Merge pull request #270 from CosmWasm/fix-needsRefill
Test and fix needsRefill
This commit is contained in:
commit
8e10dba528
@ -1,5 +1,5 @@
|
||||
import { TokenManager } from "./tokenmanager";
|
||||
import { TokenConfiguration } from "./types";
|
||||
import { MinimalAccount, TokenConfiguration } from "./types";
|
||||
|
||||
const dummyConfig: TokenConfiguration = {
|
||||
bankTokens: [
|
||||
@ -138,4 +138,39 @@ describe("TokenManager", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("needsRefill", () => {
|
||||
const tm = new TokenManager(dummyConfig);
|
||||
|
||||
it("works for sufficient/insufficient balance", () => {
|
||||
const brokeAccount: MinimalAccount = {
|
||||
address: "cosmos1rtfrpqt3yd7c8g73m9rsaen7fft0h52m3v9v5a",
|
||||
balance: [
|
||||
{
|
||||
denom: "utokenz",
|
||||
amount: "3",
|
||||
},
|
||||
],
|
||||
};
|
||||
const richAccount: MinimalAccount = {
|
||||
address: "cosmos1rtfrpqt3yd7c8g73m9rsaen7fft0h52m3v9v5a",
|
||||
balance: [
|
||||
{
|
||||
denom: "utokenz",
|
||||
amount: "3456789000000", // 3456789 TOKENZ
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(tm.needsRefill(brokeAccount, "TOKENZ")).toEqual(true);
|
||||
expect(tm.needsRefill(richAccount, "TOKENZ")).toEqual(false);
|
||||
});
|
||||
|
||||
it("works for missing balance", () => {
|
||||
const emptyAccount: MinimalAccount = {
|
||||
address: "cosmos1rtfrpqt3yd7c8g73m9rsaen7fft0h52m3v9v5a",
|
||||
balance: [],
|
||||
};
|
||||
expect(tm.needsRefill(emptyAccount, "TOKENZ")).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -47,10 +47,7 @@ export class TokenManager {
|
||||
|
||||
const balanceAmount = account.balance.find((b) => b.denom === meta.denom);
|
||||
|
||||
const balance = balanceAmount
|
||||
? Decimal.fromAtomics(balanceAmount.amount, meta.fractionalDigits)
|
||||
: Decimal.fromAtomics("0", 0);
|
||||
|
||||
const balance = Decimal.fromAtomics(balanceAmount ? balanceAmount.amount : "0", meta.fractionalDigits);
|
||||
const thresholdAmount = this.refillThreshold(tickerSymbol);
|
||||
const threshold = Decimal.fromAtomics(thresholdAmount.amount, meta.fractionalDigits);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user