Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonator committed May 31, 2024
1 parent 056ada8 commit 2e7d85f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions packages/tx/src/__tests__/gas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/src/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
}
Expand Down

0 comments on commit 2e7d85f

Please sign in to comment.