Skip to content

Commit ea0dedc

Browse files
authored
test: Update chain definition in isEIP155Enforced test (#2773)
1 parent 50bbc7c commit ea0dedc

File tree

9 files changed

+78
-72
lines changed

9 files changed

+78
-72
lines changed

.github/workflows/CI.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ env:
3030

3131
jobs:
3232
build:
33-
runs-on: ubuntu-latest-16
33+
runs-on: ubuntu-latest
3434
name: Build Packages
3535
steps:
3636
- name: Check out the code
@@ -63,7 +63,7 @@ jobs:
6363
test:
6464
timeout-minutes: 15
6565
name: Unit Tests
66-
runs-on: ubuntu-latest-16
66+
runs-on: ubuntu-latest
6767
steps:
6868
- name: Check out the code
6969
uses: actions/checkout@v4
@@ -73,6 +73,9 @@ jobs:
7373

7474
- name: Set up foundry
7575
uses: foundry-rs/foundry-toolchain@v1
76+
with:
77+
version: nightly-440ec525deb00b4dca138794865c27d1e8ea4d01
78+
cache: false
7679

7780
- run: pnpm test
7881

@@ -101,14 +104,20 @@ jobs:
101104
if: github.event_name != 'merge_group'
102105
timeout-minutes: 15
103106
name: "Benchmarks"
104-
runs-on: ubuntu-latest-16
107+
runs-on: ubuntu-latest
105108
steps:
106109
- name: Check out the code
107110
uses: actions/checkout@v4
108111

109112
- name: Setup & Install
110113
uses: ./.github/composite-actions/install
111114

115+
- name: Set up foundry
116+
uses: foundry-rs/foundry-toolchain@v1
117+
with:
118+
version: nightly-440ec525deb00b4dca138794865c27d1e8ea4d01
119+
cache: false
120+
112121
- name: Run benchmarks
113122
uses: CodSpeedHQ/action@v2
114123
with:
@@ -120,7 +129,7 @@ jobs:
120129
if: github.event_name == 'pull_request'
121130
timeout-minutes: 15
122131
name: "Size"
123-
runs-on: ubuntu-latest-16
132+
runs-on: ubuntu-latest
124133
steps:
125134
- name: Check out the code
126135
uses: actions/checkout@v4

packages/thirdweb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
"push": "yalc push",
195195
"size": "size-limit",
196196
"test:watch": "vitest -c ./test/vitest.config.ts dev",
197-
"test": "vitest run -c ./test/vitest.config.ts --coverage --bail=1",
197+
"test": "vitest run -c ./test/vitest.config.ts",
198198
"test:cov": "vitest dev -c ./test/vitest.config.ts --coverage",
199199
"test:dev": "vitest run -c ./test/vitest.config.ts",
200200
"typedoc": "node scripts/typedoc.mjs",

packages/thirdweb/src/adapters/viem.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { zeroAddress } from "viem";
22
import { beforeAll, describe, expect, test } from "vitest";
3+
import { ANVIL_PKEY_A } from "~test/test-wallets.js";
4+
import { typedData } from "~test/typed-data.js";
5+
import { ANVIL_CHAIN, FORKED_ETHEREUM_CHAIN } from "../../test/src/chains.js";
36
import { TEST_CLIENT } from "../../test/src/test-clients.js";
47
import { privateKeyAccount } from "../wallets/private-key.js";
58
import { viemAdapter } from "./viem.js";
69

7-
import { ANVIL_PKEY_A } from "~test/test-wallets.js";
8-
import { typedData } from "~test/typed-data.js";
9-
import { ANVIL_CHAIN } from "../../test/src/chains.js";
10-
import { mainnet } from "../chains/chain-definitions/ethereum.js";
11-
1210
const account = privateKeyAccount({
1311
privateKey: ANVIL_PKEY_A,
1412
client: TEST_CLIENT,
@@ -68,7 +66,7 @@ describe("walletClient.toViem", () => {
6866
walletClient = viemAdapter.walletClient.toViem({
6967
client: TEST_CLIENT,
7068
account,
71-
chain: mainnet,
69+
chain: FORKED_ETHEREUM_CHAIN,
7270
});
7371

7472
const address = await walletClient.getAddresses();

packages/thirdweb/src/extensions/erc1155/drop1155.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
206206
).rejects.toThrowErrorMatchingInlineSnapshot(`
207207
[TransactionError: Error - !Qty
208208
209-
contract: 0xd91A47278829a0128D7212225FE74BC153A7FAF8
209+
contract: ${contract.address}
210210
chainId: 31337]
211211
`);
212212

packages/thirdweb/src/transaction/prepare-transaction.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import { describe, expect, test as it } from "vitest";
2-
32
import { TEST_WALLET_A, TEST_WALLET_B } from "../../test/src/addresses.js";
3+
import { FORKED_ETHEREUM_CHAIN } from "../../test/src/chains.js";
44
import { TEST_CLIENT } from "../../test/src/test-clients.js";
5-
6-
import { ethereum } from "../chains/chain-definitions/ethereum.js";
75
import { toWei } from "../utils/units.js";
86
import { estimateGas } from "./actions/estimate-gas.js";
97
import { prepareTransaction } from "./prepare-transaction.js";
108

11-
describe("prepareTransaction", () => {
9+
describe.runIf(process.env.TW_SECRET_KEY)("prepareTransaction", () => {
1210
it("should prepare a transaction", () => {
1311
const preparedTx = prepareTransaction({
14-
chain: ethereum,
12+
chain: FORKED_ETHEREUM_CHAIN,
1513
client: TEST_CLIENT,
1614
to: TEST_WALLET_B,
1715
value: toWei("0.1"),
@@ -26,7 +24,7 @@ describe("prepareTransaction", () => {
2624
"should estimate the gas correctly",
2725
async () => {
2826
const preparedTx = prepareTransaction({
29-
chain: ethereum,
27+
chain: FORKED_ETHEREUM_CHAIN,
3028
client: TEST_CLIENT,
3129
to: TEST_WALLET_B,
3230
value: toWei("0.1"),

packages/thirdweb/src/utils/any-evm/is-eip155-enforced.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from "vitest";
2+
import { ANVIL_CHAIN } from "../../../test/src/chains.js";
23
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
3-
import { ethereum } from "../../chains/chain-definitions/ethereum.js";
44
import { optimism } from "../../chains/chain-definitions/optimism.js";
55
import { isEIP155Enforced } from "./is-eip155-enforced.js";
66

@@ -22,8 +22,8 @@ describe.runIf(process.env.TW_SECRET_KEY)("isEIP155Enforced", () => {
2222
it("should return false if EIP-155 is not enforced", async () => {
2323
// Call the isEIP155Enforced function with a chain that does not enforce EIP-155
2424
const result = await isEIP155Enforced({
25-
// ethereum does not enforce eip155
26-
chain: ethereum,
25+
// localhost does not enforce eip155
26+
chain: ANVIL_CHAIN,
2727
client: TEST_CLIENT,
2828
});
2929

packages/thirdweb/test/globalSetup.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1+
import { sha256 } from "@noble/hashes/sha256";
12
import { startProxy } from "@viem/anvil";
23
import { FORK_BLOCK_NUMBER, OPTIMISM_FORK_BLOCK_NUMBER } from "./src/chains.js";
3-
import { sha256 } from "@noble/hashes/sha256";
44

55
require("dotenv-mono").load();
66

77
const SECRET_KEY = process.env.TW_SECRET_KEY as string;
88

99
const clientId = SECRET_KEY
10-
? Buffer.from(sha256(SECRET_KEY)).toString("hex").slice(0, 32)
11-
: "";
10+
? Buffer.from(sha256(SECRET_KEY)).toString("hex").slice(0, 32)
11+
: "";
1212

1313
export default async function globalSetup() {
14-
const shutdownMainnet = await startProxy({
15-
port: 8645,
16-
options: {
17-
chainId: 1,
18-
forkUrl: SECRET_KEY
19-
? `https://1.rpc.thirdweb.com/${clientId}`
20-
: "https://mainnet.gateway.tenderly.co",
21-
forkHeader: SECRET_KEY ? { "x-secret-key": SECRET_KEY } : {},
22-
forkChainId: 1,
23-
forkBlockNumber: FORK_BLOCK_NUMBER,
24-
noMining: true,
25-
startTimeout: 20000,
26-
},
27-
});
14+
const shutdownMainnet = await startProxy({
15+
port: 8645,
16+
options: {
17+
chainId: 1,
18+
forkUrl: SECRET_KEY
19+
? `https://1.rpc.thirdweb.com/${clientId}`
20+
: "https://mainnet.gateway.tenderly.co",
21+
forkHeader: SECRET_KEY ? { "x-secret-key": SECRET_KEY } : {},
22+
forkChainId: 1,
23+
forkBlockNumber: FORK_BLOCK_NUMBER,
24+
noMining: true,
25+
startTimeout: 20000,
26+
},
27+
});
2828

29-
const shutdownOptimism = await startProxy({
30-
port: 8646,
31-
options: {
32-
chainId: 10,
33-
forkUrl: SECRET_KEY
34-
? `https://10.rpc.thirdweb.com/${clientId}`
35-
: "https://mainnet.optimism.io/",
36-
forkHeader: SECRET_KEY ? { "x-secret-key": SECRET_KEY } : {},
37-
forkChainId: 10,
38-
forkBlockNumber: OPTIMISM_FORK_BLOCK_NUMBER,
39-
noMining: true,
40-
startTimeout: 20000,
41-
},
42-
});
29+
const shutdownOptimism = await startProxy({
30+
port: 8646,
31+
options: {
32+
chainId: 10,
33+
forkUrl: SECRET_KEY
34+
? `https://10.rpc.thirdweb.com/${clientId}`
35+
: "https://mainnet.optimism.io/",
36+
forkHeader: SECRET_KEY ? { "x-secret-key": SECRET_KEY } : {},
37+
forkChainId: 10,
38+
forkBlockNumber: OPTIMISM_FORK_BLOCK_NUMBER,
39+
noMining: true,
40+
startTimeout: 20000,
41+
},
42+
});
4343

44-
const shutdownAnvil = await startProxy({
45-
port: 8647,
46-
});
44+
const shutdownAnvil = await startProxy({
45+
port: 8647,
46+
});
4747

48-
return () => {
49-
shutdownMainnet();
50-
shutdownOptimism();
51-
shutdownAnvil();
52-
};
48+
return async () => {
49+
await shutdownMainnet();
50+
await shutdownOptimism();
51+
await shutdownAnvil();
52+
};
5353
}

packages/thirdweb/test/src/chains.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ export const FORKED_OPTIMISM_RPC = `http://127.0.0.1:8646/${poolId}`;
1010
export const ANVIL_RPC = `http://127.0.0.1:8647/${poolId}`;
1111

1212
export const FORKED_ETHEREUM_CHAIN = defineChain({
13-
...ethereum,
14-
// override the rpc url
15-
rpc: FORKED_ETHEREUM_RPC,
13+
...ethereum,
14+
// override the rpc url
15+
rpc: FORKED_ETHEREUM_RPC,
1616
});
1717

1818
export const FORKED_OPTIMISM_CHAIN = defineChain({
19-
...optimism,
20-
// override the rpc url
21-
rpc: FORKED_OPTIMISM_RPC,
19+
...optimism,
20+
// override the rpc url
21+
rpc: FORKED_OPTIMISM_RPC,
2222
});
2323

2424
export const ANVIL_CHAIN = defineChain({
25-
...anvil,
26-
// override the rpc url
27-
rpc: ANVIL_RPC,
25+
...anvil,
26+
// override the rpc url
27+
rpc: ANVIL_RPC,
2828
});
2929

3030
export const FORK_BLOCK_NUMBER = 19139495n;

packages/thirdweb/test/vitest.config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { join } from "node:path";
2-
import { defineConfig } from "vitest/config";
32
// @ts-expect-error - no types
43
import codspeedPlugin from "@codspeed/vitest-plugin";
4+
import { defineConfig } from "vitest/config";
55

66
const plugins = process.env.CI ? [codspeedPlugin()] : [];
77

@@ -34,8 +34,9 @@ export default defineConfig({
3434
include: ["src/**/*.test.ts"],
3535
// setupFiles: [join(__dirname, "./setup.ts")],
3636
globalSetup: [join(__dirname, "./globalSetup.ts")],
37-
testTimeout: 30_000,
38-
retry: process.env.CI ? 0 : 3,
37+
testTimeout: 60_000,
38+
retry: 0,
39+
bail: 1,
3940
// clear any mocks between any tests
4041
clearMocks: true,
4142
pool: "forks",

0 commit comments

Comments
 (0)