From 2e7d85fc082ec04dea7ff4371df5a1cf31c833ab Mon Sep 17 00:00:00 2001 From: Jon Ator Date: Fri, 31 May 2024 11:49:57 -0400 Subject: [PATCH] update tests --- packages/tx/src/__tests__/gas.spec.ts | 41 +++++++++++++++++++++++++++ packages/tx/src/gas.ts | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/tx/src/__tests__/gas.spec.ts b/packages/tx/src/__tests__/gas.spec.ts index b357fe7754..49b1e622cb 100644 --- a/packages/tx/src/__tests__/gas.spec.ts +++ b/packages/tx/src/__tests__/gas.spec.ts @@ -847,6 +847,47 @@ describe("getGasPriceByFeeDenom", () => { expect(queryFeeTokenSpotPrice).not.toHaveBeenCalled(); }); + it("should return an alternative token gas price in registry if fee market module is not available", async () => { + const chainId = "juno-1"; + const chainListWithoutFeeMarket = chainList.map((chain) => ({ + ...chain, + features: [], + })); + const feeDenom = + "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9"; + + const result = await getGasPriceByFeeDenom({ + chainId, + chainList: chainListWithoutFeeMarket, + feeDenom, + gasMultiplier, + }); + + expect(result.gasPrice.toString()).toBe(new Dec(0.0035).toString()); + + expect(queryFeesBaseGasPrice).not.toHaveBeenCalled(); + expect(queryFeeTokenSpotPrice).not.toHaveBeenCalled(); + }); + + it("should throw an error if fee token is not in config", async () => { + const chainListWithoutFeeMarket = chainList.map((chain) => ({ + ...chain, + features: [], + })); + + await expect( + getGasPriceByFeeDenom({ + chainId, + chainList: chainListWithoutFeeMarket, + feeDenom, + gasMultiplier, + }) + ).rejects.toThrow("Fee token not found: uion"); + + expect(queryFeesBaseGasPrice).not.toHaveBeenCalled(); + expect(queryFeeTokenSpotPrice).not.toHaveBeenCalled(); + }); + it("should throw an error if chain is not found", async () => { await expect( getGasPriceByFeeDenom({ diff --git a/packages/tx/src/gas.ts b/packages/tx/src/gas.ts index 4daa768562..e2feec948f 100644 --- a/packages/tx/src/gas.ts +++ b/packages/tx/src/gas.ts @@ -418,7 +418,7 @@ export async function getGasPriceByFeeDenom({ } const feeToken = chain.fees.fee_tokens.find((ft) => ft.denom === feeDenom); - if (!feeToken) throw new Error("Fee token not found"); + if (!feeToken) throw new Error("Fee token not found: " + feeDenom); return { gasPrice: new Dec(feeToken.average_gas_price ?? defaultGasPrice) }; }