Fix some tests... others hardcode atoms :(

This commit is contained in:
Ethan Frey 2020-01-22 15:56:06 +01:00
parent 1ca8435df0
commit 65465b895c
3 changed files with 22 additions and 8 deletions

View File

@ -73,11 +73,11 @@ describe("CosmosConnection", () => {
it("displays a given token", async () => {
pendingWithoutCosmos();
const connection = await CosmosConnection.establish(httpUrl);
const token = await connection.getToken("ATOM" as TokenTicker);
const token = await connection.getToken("cosm" as TokenTicker);
expect(token).toEqual({
fractionalDigits: 6,
tokenName: "Atom",
tokenTicker: "ATOM" as TokenTicker,
tokenName: "Cosm",
tokenTicker: "cosm" as TokenTicker,
});
connection.disconnect();
});
@ -96,12 +96,18 @@ describe("CosmosConnection", () => {
pendingWithoutCosmos();
const connection = await CosmosConnection.establish(httpUrl);
const tokens = await connection.getAllTokens();
// TODO: make this more flexible
expect(tokens).toEqual([
{
fractionalDigits: 6,
tokenName: "Atom",
tokenTicker: "ATOM" as TokenTicker,
tokenName: "Cosm",
tokenTicker: "cosm" as TokenTicker,
},
{
fractionalDigits: 6,
tokenName: "Stake",
tokenTicker: "stake" as TokenTicker,
}
]);
connection.disconnect();
});

View File

@ -93,12 +93,17 @@ export class CosmosConnection implements BlockchainConnection {
private constructor(restClient: RestClient, chainData: ChainData) {
this.restClient = restClient;
this.chainData = chainData;
// TODO: this is an argument
this.primaryToken = {
fractionalDigits: 6,
tokenName: "Atom",
tokenTicker: "ATOM" as TokenTicker,
tokenName: "Cosm",
tokenTicker: "cosm" as TokenTicker,
};
this.supportedTokens = [this.primaryToken];
this.supportedTokens = [this.primaryToken, {
fractionalDigits: 6,
tokenName: "Stake",
tokenTicker: "stake" as TokenTicker,
}];
}
public disconnect(): void {
@ -128,6 +133,7 @@ export class CosmosConnection implements BlockchainConnection {
const account = result.value;
const supportedCoins = account.coins.filter(({ denom }) =>
this.supportedTokens.find(
// TODO: ugly special case - fix this
({ tokenTicker }) => (tokenTicker === "ATOM" && denom === "uatom") || tokenTicker === denom,
),
);

View File

@ -46,6 +46,7 @@ export function decodeFullSignature(signature: amino.StdSignature, nonce: number
}
export function decodeAmount(amount: amino.Coin): Amount {
// TODO: more uglyness here (breaks unit tests)
if (amount.denom !== "uatom") {
throw new Error("Only ATOM amounts are supported");
}
@ -53,6 +54,7 @@ export function decodeAmount(amount: amino.Coin): Amount {
fractionalDigits: 6,
quantity: amount.amount,
tokenTicker: atom,
// tokenTicker: amount.denom as TokenTicker,
};
}