Skip to content

Commit ce044fa

Browse files
committed
anvil test
1 parent 85999c3 commit ce044fa

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
PROVIDER_URLS="https://eth-mainnet.alchemyapi.io/v2/YOUR_ALCHEMY_ID" # your provider URLS seperated by comma
2-
PRIVATE_KEY="" ## Optional: Only needed if you wish to create a task from the CLI instead of the UI
2+
PRIVATE_KEY="" ## Optional: Only needed if you wish to create a task from the CLI instead of the UI
3+
RPC="" ## PRC FOR ANVIL FORK

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Web3Function.onRun(async (context: Web3FunctionContext) => {
129129
130130
- Example:<br/> `npx w3f test web3-functions/oracle/index.ts --show-logs`
131131
- Output:
132-
```
132+
```
133133
Web3Function Build result:
134134
Schema: web3-functions/oracle/schema.json
135135
Built file: /Users/chuahsonglin/Documents/GitHub/Gelato/backend/js-resolver-template/.tmp/index.js

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"create-task:event": "ts-node scripts/create-task-event-listener.ts",
1313
"create-task:oracle": "ts-node scripts/create-task-oracle.ts",
1414
"create-task:secrets": "ts-node scripts/create-task-with-secrets.ts",
15-
"create-task:ad-board": "ts-node scripts/create-task-ad-board.ts"
15+
"create-task:ad-board": "ts-node scripts/create-task-ad-board.ts",
16+
"forkAnvil": "ts-node scripts/forkAnvil.ts"
1617
},
1718
"keywords": [],
1819
"author": "",

scripts/forkAnvil.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
import * as dotenv from 'dotenv';
3+
dotenv.config();
4+
5+
const forkChain = async () => {
6+
7+
const { spawn } = await import("child_process");
8+
9+
const RPC = process.env['RPC']!
10+
let params = ["-f",RPC]
11+
12+
let blockNumber;
13+
14+
if (blockNumber) {
15+
params.push(`--fork-block-number=${blockNumber}`)
16+
}
17+
18+
/// You can add as much customs params as wanted
19+
const childProcess = spawn('anvil',params, {
20+
stdio: "inherit",
21+
});
22+
23+
childProcess.once("close", (status) => {
24+
childProcess.removeAllListeners("error");
25+
26+
if (status === 0) {
27+
console.log('ok')
28+
} else {
29+
console.log('error')
30+
}
31+
32+
});
33+
34+
childProcess.once("error", (_status) => {
35+
childProcess.removeAllListeners("close");
36+
console.log('error')
37+
});
38+
}
39+
40+
forkChain()

0 commit comments

Comments
 (0)