From 128753989b22148b12f7cda107653ec8aea81094 Mon Sep 17 00:00:00 2001 From: npty Date: Tue, 20 Feb 2024 16:47:06 +0700 Subject: [PATCH] chore: add tests for checking undefined executeData --- src/libs/AxelarQueryAPI.ts | 3 +-- src/libs/test/AxelarQueryAPI.spec.ts | 37 ++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/libs/AxelarQueryAPI.ts b/src/libs/AxelarQueryAPI.ts index 4e786623..2476cc1a 100644 --- a/src/libs/AxelarQueryAPI.ts +++ b/src/libs/AxelarQueryAPI.ts @@ -1,5 +1,5 @@ import { AssetConfig } from "../assets/types"; -import { parseUnits } from "ethers/lib/utils"; +import { formatEther, parseUnits } from "ethers/lib/utils"; import { loadAssets } from "../assets"; import { EnvironmentConfigs, getConfigs } from "../constants"; import { RestService } from "../services"; @@ -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()); diff --git a/src/libs/test/AxelarQueryAPI.spec.ts b/src/libs/test/AxelarQueryAPI.spec.ts index 6f453a35..59f65147 100644 --- a/src/libs/test/AxelarQueryAPI.spec.ts +++ b/src/libs/test/AxelarQueryAPI.spec.ts @@ -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"; import { CHAINS } from "../../chains"; import { AxelarQueryAPI } from "../AxelarQueryAPI"; import { Environment } from "../types"; @@ -84,26 +84,29 @@ 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 ); @@ -111,6 +114,20 @@ describe("AxelarQueryAPI", () => { 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,