|
1 | 1 | import { describe, expect, it } from "vitest";
|
2 |
| -import { TEST_WALLET_A, TEST_WALLET_B } from "~test/addresses.js"; |
| 2 | +import { TEST_WALLET_B } from "~test/addresses.js"; |
3 | 3 | import { USDT_CONTRACT } from "~test/test-contracts.js";
|
| 4 | +import { |
| 5 | + FORKED_ETHEREUM_CHAIN, |
| 6 | + FORKED_OPTIMISM_CHAIN, |
| 7 | +} from "../../../test/src/chains.js"; |
| 8 | +import { TEST_CLIENT } from "../../../test/src/test-clients.js"; |
4 | 9 | import { prepareContractCall } from "../prepare-contract-call.js";
|
| 10 | +import { prepareTransaction } from "../prepare-transaction.js"; |
5 | 11 | import { estimateGasCost } from "./estimate-gas-cost.js";
|
6 | 12 |
|
7 |
| -describe.runIf(process.env.TW_SECRET_KEY)( |
8 |
| - "transaction: estimateGasCost", |
9 |
| - () => { |
10 |
| - it("should estimateGasCost correctly", async () => { |
| 13 | +describe.runIf(process.env.TW_SECRET_KEY)("estimateGasCost", () => { |
| 14 | + describe("normal", () => { |
| 15 | + it("should estimateGasCost tx correctly", async () => { |
11 | 16 | const tx = prepareContractCall({
|
12 | 17 | contract: USDT_CONTRACT,
|
13 | 18 | method: "function approve(address, uint256) returns (bool)",
|
14 | 19 | params: [TEST_WALLET_B, 100n],
|
15 | 20 | });
|
16 | 21 | const result = await estimateGasCost({
|
17 | 22 | transaction: tx,
|
18 |
| - from: TEST_WALLET_A, |
| 23 | + }); |
| 24 | + expect(result).toMatchInlineSnapshot(` |
| 25 | + { |
| 26 | + "ether": "0.001196638702568277", |
| 27 | + "wei": 1196638702568277n, |
| 28 | + } |
| 29 | + `); |
| 30 | + }); |
| 31 | + |
| 32 | + it("should estimateGasCost native token", async () => { |
| 33 | + const tx = prepareTransaction({ |
| 34 | + chain: FORKED_ETHEREUM_CHAIN, |
| 35 | + client: TEST_CLIENT, |
| 36 | + value: 0n, |
| 37 | + to: TEST_WALLET_B, |
| 38 | + }); |
| 39 | + const result = await estimateGasCost({ |
| 40 | + transaction: tx, |
| 41 | + }); |
| 42 | + expect(result).toMatchInlineSnapshot(` |
| 43 | + { |
| 44 | + "ether": "0.00052179661420146", |
| 45 | + "wei": 521796614201460n, |
| 46 | + } |
| 47 | + `); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + describe("op stack", () => { |
| 52 | + it("should estimateGasCost native token", async () => { |
| 53 | + const tx = prepareTransaction({ |
| 54 | + chain: FORKED_OPTIMISM_CHAIN, |
| 55 | + client: TEST_CLIENT, |
| 56 | + value: 0n, |
| 57 | + to: TEST_WALLET_B, |
| 58 | + }); |
| 59 | + const result = await estimateGasCost({ |
| 60 | + transaction: tx, |
19 | 61 | });
|
20 | 62 | expect(result).toMatchInlineSnapshot(`
|
21 | 63 | {
|
22 |
| - "ether": "0.001196638702568277", |
23 |
| - "wei": 1196638702568277n, |
| 64 | + "ether": "0.000021198198952138", |
| 65 | + "wei": 21198198952138n, |
24 | 66 | }
|
25 | 67 | `);
|
26 | 68 | });
|
27 |
| - }, |
28 |
| -); |
| 69 | + }); |
| 70 | +}); |
0 commit comments