Skip to content

Commit 2de2b69

Browse files
authored
chore(tests): add test for gas cost for native token (#2783)
1 parent 9cb5153 commit 2de2b69

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ jobs:
7474
- name: Set up foundry
7575
uses: foundry-rs/foundry-toolchain@v1
7676
with:
77-
version: nightly-440ec525deb00b4dca138794865c27d1e8ea4d01
7877
cache: false
7978

8079
- run: pnpm test
@@ -115,7 +114,6 @@ jobs:
115114
- name: Set up foundry
116115
uses: foundry-rs/foundry-toolchain@v1
117116
with:
118-
version: nightly-440ec525deb00b4dca138794865c27d1e8ea4d01
119117
cache: false
120118

121119
- name: Run benchmarks
Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,70 @@
11
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";
33
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";
49
import { prepareContractCall } from "../prepare-contract-call.js";
10+
import { prepareTransaction } from "../prepare-transaction.js";
511
import { estimateGasCost } from "./estimate-gas-cost.js";
612

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 () => {
1116
const tx = prepareContractCall({
1217
contract: USDT_CONTRACT,
1318
method: "function approve(address, uint256) returns (bool)",
1419
params: [TEST_WALLET_B, 100n],
1520
});
1621
const result = await estimateGasCost({
1722
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,
1961
});
2062
expect(result).toMatchInlineSnapshot(`
2163
{
22-
"ether": "0.001196638702568277",
23-
"wei": 1196638702568277n,
64+
"ether": "0.000021198198952138",
65+
"wei": 21198198952138n,
2466
}
2567
`);
2668
});
27-
},
28-
);
69+
});
70+
});

0 commit comments

Comments
 (0)