Add supplyOf query

This commit is contained in:
Simon Warta 2020-08-13 11:56:42 +02:00
parent 894084a433
commit 0c5f72a55f
3 changed files with 31 additions and 0 deletions

View File

@ -137,5 +137,29 @@ describe("BankExtension", () => {
]);
});
});
describe("supplyOf", () => {
it("works for existing denom", async () => {
pendingWithoutSimapp();
const client = await makeBankClient(simapp.tendermintUrl);
const response = await client.bank.unverified.supplyOf(simapp.denomFee);
expect(response).toEqual({
amount: "18000000000",
denom: simapp.denomFee,
});
});
it("returns zero for non-existent denom", async () => {
pendingWithoutSimapp();
const client = await makeBankClient(simapp.tendermintUrl);
const response = await client.bank.unverified.supplyOf("gintonic");
expect(response).toEqual({
amount: "0",
denom: "gintonic",
});
});
});
});
});

View File

@ -12,6 +12,7 @@ export interface BankExtension {
readonly balance: (address: string, denom: string) => Promise<cosmos.ICoin>;
readonly allBalances: (address: string) => Promise<cosmos.ICoin[]>;
readonly totalSupply: () => Promise<cosmos.ICoin[]>;
readonly supplyOf: (denom: string) => Promise<cosmos.ICoin>;
};
};
}
@ -55,6 +56,11 @@ export function setupBankExtension(base: QueryClient): BankExtension {
const { supply } = await queryService.totalSupply({});
return supply.map(toObject);
},
supplyOf: async (denom: string) => {
const { amount } = await queryService.supplyOf({ denom: denom });
assert(amount);
return toObject(amount);
},
},
},
};

View File

@ -7,6 +7,7 @@ export interface BankExtension {
readonly balance: (address: string, denom: string) => Promise<cosmos.ICoin>;
readonly allBalances: (address: string) => Promise<cosmos.ICoin[]>;
readonly totalSupply: () => Promise<cosmos.ICoin[]>;
readonly supplyOf: (denom: string) => Promise<cosmos.ICoin>;
};
};
}