Skip to content

Commit

Permalink
chore: add tests for checking undefined executeData
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Feb 20, 2024
1 parent 27069bd commit 1287539
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/libs/AxelarQueryAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssetConfig } from "../assets/types";
import { parseUnits } from "ethers/lib/utils";
import { formatEther, parseUnits } from "ethers/lib/utils";

Check warning on line 2 in src/libs/AxelarQueryAPI.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/libs/AxelarQueryAPI.ts#L2

'formatEther' is defined but never used (@typescript-eslint/no-unused-vars)
import { loadAssets } from "../assets";
import { EnvironmentConfigs, getConfigs } from "../constants";
import { RestService } from "../services";
Expand Down Expand Up @@ -380,7 +380,6 @@ export class AxelarQueryAPI {
const ethToSrcTokenPriceRatio = ethTokenPrice / srcTokenPrice;

const actualL1ExecutionFee = Math.ceil(l1ExecutionFee.toNumber() * ethToSrcTokenPriceRatio);
console.log(actualL1ExecutionFee);

l1ExecutionFee = BigNumber.from(actualL1ExecutionFee.toString());

Expand Down
37 changes: 27 additions & 10 deletions src/libs/test/AxelarQueryAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
TransferFeeResponse,
} from "@axelar-network/axelarjs-types/axelar/nexus/v1beta1/query";
import { BigNumber, BigNumberish, ethers } from "ethers";
import { parseUnits } from "ethers/lib/utils";
import { formatEther, parseUnits } from "ethers/lib/utils";

Check warning on line 6 in src/libs/test/AxelarQueryAPI.spec.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/libs/test/AxelarQueryAPI.spec.ts#L6

'formatEther' is defined but never used (@typescript-eslint/no-unused-vars)
import { CHAINS } from "../../chains";
import { AxelarQueryAPI } from "../AxelarQueryAPI";
import { Environment } from "../types";
Expand Down Expand Up @@ -84,33 +84,50 @@ describe("AxelarQueryAPI", () => {
});

describe("estimateGasFee", () => {
test.skip("It should return estimated gas amount that makes sense for USDC", async () => {
test("It should return estimated gas amount that makes sense for USDC", async () => {
const gasAmount = await api.estimateGasFee(
EvmChain.AVALANCHE,
EvmChain.ETHEREUM,
"ethereum-2",
700000,
1.1,
"500000"
"500000",
undefined,
GasToken.USDC
);

// gasAmount should be less than 10k usd, otherwise we handle decimal conversion incorrectly.
expect(ethers.utils.parseUnits("10000", 6).gt(gasAmount as BigNumberish)).toBeTruthy();
expect(ethers.utils.parseEther("10000").gt(gasAmount as BigNumberish)).toBeTruthy();
});

test("It should include L1 fee for L2 destination chain", async () => {
const gasAmount = await api.estimateGasFee(
EvmChain.AVALANCHE,
const mainnetApi = new AxelarQueryAPI({ environment: Environment.MAINNET });
const gasAmount = await mainnetApi.estimateGasFee(
EvmChain.ETHEREUM,
EvmChain.OPTIMISM,
700000,
1.1,
"500000",
529994,
1,
undefined,
"0x1a98b2e0e68ba0eb84262d4bcf91955ec2680b37bcedd59a1f48e18d183dac9961bf9d1400000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000d40000000000000000000000000000000000000000000000000000000000deac2c6000000000000000000000000000000000000000000000000000000000000000762696e616e636500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a307863653136463639333735353230616230313337376365374238386635424138433438463844363636000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000bc000000000000000000000000000000000000000000000000000000000000000400000000000000000000000004607cad6135d7a119185ebe062d3b369b1b536ef000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000003600000000000000000000000000000000000000000000000000000000000000580000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000009200000000000000000000000000000000000000000000000000000000000000a8000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000eb466342c4d449bc9f53a865d5cb90586f4052150000000000000000000000000000000000000000000000000000000000000001000000000000000000000000eb466342c4d449bc9f53a865d5cb90586f405215000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc450000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000eb466342c4d449bc9f53a865d5cb90586f4052150000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000eb466342c4d449bc9f53a865d5cb90586f405215000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000000000000000000000000000000000000000000640000000000000000000000004fd39c9e151e50580779bd04b1f7ecc310079fd3000000000000000000000000000000000000000000000000000000000deac2c6000000000000000000000000000000000000000000000000000000000dc647500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000eb466342c4d449bc9f53a865d5cb90586f40521500000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc450000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000000000000000000000000000000000000640000000000000000000000004fd39c9e151e50580779bd04b1f7ecc310079fd3000000000000000000000000000000000000000000000000000000000de83dbf000000000000000000000000000000000000000000000000015d8c7908dbe7130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000100000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000242e1a7d4d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000004607cad6135d7a119185ebe062d3b369b1b536ef000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000761786c5553444300000000000000000000000000000000000000000000000000",
undefined
);

expect(gasAmount).toBeDefined();
});

it("should return error when the source chain is L2, but the executeData is undefuned ", async () => {
expect(
api.estimateGasFee(
"ethereum-2",
EvmChain.OPTIMISM,
700000,
1.1,
"500000",
undefined,
GasToken.USDC
)
).rejects.toThrow("executeData is required to calculate the L1 execution fee for optimism");
});

test("It should return estimated gas amount that makes sense for native token", async () => {
const gasAmount = await api.estimateGasFee(
CHAINS.TESTNET.AVALANCHE as EvmChain,
Expand Down

0 comments on commit 1287539

Please sign in to comment.