Ensure getAccount does not list zero balances of ERC20s
This commit is contained in:
@@ -44,6 +44,8 @@
|
||||
"@iov/encoding": "^2.0.0-alpha.7",
|
||||
"@iov/stream": "^2.0.0-alpha.7",
|
||||
"@iov/utils": "^2.0.0-alpha.7",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^5.1.1",
|
||||
"fast-deep-equal": "^3.1.1",
|
||||
"readonly-date": "^1.0.0",
|
||||
"xstream": "^11.11.0"
|
||||
|
||||
@@ -84,6 +84,12 @@ describe("CosmWasmConnection", () => {
|
||||
ticker: "BASH",
|
||||
name: "Bash Token",
|
||||
},
|
||||
{
|
||||
contractAddress: "cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c",
|
||||
fractionalDigits: 18,
|
||||
ticker: "CASH",
|
||||
name: "Cash Token",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -154,6 +160,11 @@ describe("CosmWasmConnection", () => {
|
||||
tokenName: "Bash Token",
|
||||
tokenTicker: "BASH" as TokenTicker,
|
||||
},
|
||||
{
|
||||
fractionalDigits: 18,
|
||||
tokenName: "Cash Token",
|
||||
tokenTicker: "CASH" as TokenTicker,
|
||||
},
|
||||
{
|
||||
fractionalDigits: 6,
|
||||
tokenName: "Fee Token",
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
import { Sha256 } from "@iov/crypto";
|
||||
import { Encoding, Uint53 } from "@iov/encoding";
|
||||
import { DefaultValueProducer, ValueAndUpdates } from "@iov/stream";
|
||||
import BN from "bn.js";
|
||||
import equal from "fast-deep-equal";
|
||||
import { ReadonlyDate } from "readonly-date";
|
||||
import { Stream } from "xstream";
|
||||
@@ -172,18 +173,20 @@ export class CosmWasmConnection implements BlockchainConnection {
|
||||
const response = JSON.parse(
|
||||
await this.restClient.queryContractSmart(erc20.contractAddress, queryMsg),
|
||||
);
|
||||
const normalizedBalance = new BN(response.balance).toString();
|
||||
return {
|
||||
fractionalDigits: erc20.fractionalDigits,
|
||||
quantity: response.balance,
|
||||
quantity: normalizedBalance,
|
||||
tokenTicker: erc20.ticker as TokenTicker,
|
||||
};
|
||||
},
|
||||
),
|
||||
);
|
||||
const nonZeroErc20Amounts = erc20Amounts.filter(amount => amount.quantity !== "0");
|
||||
|
||||
const balance = [
|
||||
...supportedBankCoins.map(coin => decodeAmount(this.bankTokens, coin)),
|
||||
...erc20Amounts,
|
||||
...nonZeroErc20Amounts,
|
||||
].sort((a, b) => a.tokenTicker.localeCompare(b.tokenTicker));
|
||||
|
||||
const pubkey = !account.public_key ? undefined : decodeCosmosPubkey(account.public_key);
|
||||
|
||||
@@ -118,7 +118,18 @@ async function main() {
|
||||
},
|
||||
],
|
||||
};
|
||||
for (const initMsg of [initMsgAsh, initMsgBash]) {
|
||||
const initMsgCash = {
|
||||
decimals: 18,
|
||||
name: "Cash Token",
|
||||
symbol: "CASH",
|
||||
initial_balances: [
|
||||
{
|
||||
address: faucetAddress,
|
||||
amount: "189189189000000000000000000", // 189189189 CASH
|
||||
},
|
||||
],
|
||||
};
|
||||
for (const initMsg of [initMsgAsh, initMsgBash, initMsgCash]) {
|
||||
const initResult = await instantiateContract(client, pen, codeId, initMsg);
|
||||
if (initResult.code) {
|
||||
throw new Error(`Instantiation failed with code: ${initResult.code}; log: '${initResult.raw_log}'`);
|
||||
|
||||
@@ -966,6 +966,13 @@
|
||||
dependencies:
|
||||
"@types/babel-types" "*"
|
||||
|
||||
"@types/bn.js@^4.11.6":
|
||||
version "4.11.6"
|
||||
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.6.tgz#c306c70d9358aaea33cd4eda092a742b9505967c"
|
||||
integrity sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/body-parser@*":
|
||||
version "1.17.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.17.1.tgz#18fcf61768fb5c30ccc508c21d6fd2e8b3bf7897"
|
||||
@@ -1826,6 +1833,11 @@ bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.8, bn.js@^4.4.0:
|
||||
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
|
||||
integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==
|
||||
|
||||
bn.js@^5.1.1:
|
||||
version "5.1.1"
|
||||
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.1.tgz#48efc4031a9c4041b9c99c6941d903463ab62eb5"
|
||||
integrity sha512-IUTD/REb78Z2eodka1QZyyEk66pciRcP6Sroka0aI3tG/iwIdYLrBD62RsubR7vqdt3WyX8p4jxeatzmRSphtA==
|
||||
|
||||
body-parser@^1.16.1:
|
||||
version "1.19.0"
|
||||
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a"
|
||||
|
||||
Reference in New Issue
Block a user