Add totalSupply query

This commit is contained in:
Simon Warta 2020-08-13 11:51:56 +02:00
parent 71b0728042
commit 894084a433
4 changed files with 33 additions and 1 deletions

View File

@ -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,
},
]);
});
});
});
});

View File

@ -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);
},
},
},
};

View File

@ -64,4 +64,5 @@ export const validator = {
export const nonExistentAddress = "cosmos1p79apjaufyphcmsn4g07cynqf0wyjuezqu84hd";
export const nonNegativeIntegerMatcher = /^[0-9]+$/;
export const tendermintIdMatcher = /^[0-9A-F]{64}$/;

View File

@ -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[]>;
};
};
}