Add totalSupply query
This commit is contained in:
parent
71b0728042
commit
894084a433
@ -1,7 +1,13 @@
|
||||
import { Client as TendermintClient } from "@cosmjs/tendermint-rpc";
|
||||
|
||||
import { QueryClient } from "../queryclient";
|
||||
import { nonExistentAddress, pendingWithoutSimapp, simapp, unused } from "../testutils.spec";
|
||||
import {
|
||||
nonExistentAddress,
|
||||
nonNegativeIntegerMatcher,
|
||||
pendingWithoutSimapp,
|
||||
simapp,
|
||||
unused,
|
||||
} from "../testutils.spec";
|
||||
import { BankExtension, setupBankExtension } from "./bank";
|
||||
|
||||
async function makeBankClient(rpcUrl: string): Promise<QueryClient & BankExtension> {
|
||||
@ -112,5 +118,24 @@ describe("BankExtension", () => {
|
||||
expect(balances).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("totalSupply", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const client = await makeBankClient(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.bank.unverified.totalSupply();
|
||||
expect(response).toEqual([
|
||||
{
|
||||
amount: "18000000000",
|
||||
denom: simapp.denomFee,
|
||||
},
|
||||
{
|
||||
amount: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
denom: simapp.denomStaking,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -11,6 +11,7 @@ export interface BankExtension {
|
||||
readonly unverified: {
|
||||
readonly balance: (address: string, denom: string) => Promise<cosmos.ICoin>;
|
||||
readonly allBalances: (address: string) => Promise<cosmos.ICoin[]>;
|
||||
readonly totalSupply: () => Promise<cosmos.ICoin[]>;
|
||||
};
|
||||
};
|
||||
}
|
||||
@ -50,6 +51,10 @@ export function setupBankExtension(base: QueryClient): BankExtension {
|
||||
const { balances } = await queryService.allBalances({ address: toAccAddress(address) });
|
||||
return balances.map(toObject);
|
||||
},
|
||||
totalSupply: async () => {
|
||||
const { supply } = await queryService.totalSupply({});
|
||||
return supply.map(toObject);
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -64,4 +64,5 @@ export const validator = {
|
||||
|
||||
export const nonExistentAddress = "cosmos1p79apjaufyphcmsn4g07cynqf0wyjuezqu84hd";
|
||||
|
||||
export const nonNegativeIntegerMatcher = /^[0-9]+$/;
|
||||
export const tendermintIdMatcher = /^[0-9A-F]{64}$/;
|
||||
|
||||
1
packages/stargate/types/queries/bank.d.ts
vendored
1
packages/stargate/types/queries/bank.d.ts
vendored
@ -6,6 +6,7 @@ export interface BankExtension {
|
||||
readonly unverified: {
|
||||
readonly balance: (address: string, denom: string) => Promise<cosmos.ICoin>;
|
||||
readonly allBalances: (address: string) => Promise<cosmos.ICoin[]>;
|
||||
readonly totalSupply: () => Promise<cosmos.ICoin[]>;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user