Skip to content

Commit

Permalink
anvil test
Browse files Browse the repository at this point in the history
  • Loading branch information
donoso-eth committed Jun 30, 2023
1 parent 85999c3 commit ce044fa
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PROVIDER_URLS="https://eth-mainnet.alchemyapi.io/v2/YOUR_ALCHEMY_ID" # your provider URLS seperated by comma
PRIVATE_KEY="" ## Optional: Only needed if you wish to create a task from the CLI instead of the UI
PRIVATE_KEY="" ## Optional: Only needed if you wish to create a task from the CLI instead of the UI
RPC="" ## PRC FOR ANVIL FORK
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Web3Function.onRun(async (context: Web3FunctionContext) => {
- Example:<br/> `npx w3f test web3-functions/oracle/index.ts --show-logs`
- Output:
```
```
Web3Function Build result:
Schema: web3-functions/oracle/schema.json
Built file: /Users/chuahsonglin/Documents/GitHub/Gelato/backend/js-resolver-template/.tmp/index.js
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"create-task:event": "ts-node scripts/create-task-event-listener.ts",
"create-task:oracle": "ts-node scripts/create-task-oracle.ts",
"create-task:secrets": "ts-node scripts/create-task-with-secrets.ts",
"create-task:ad-board": "ts-node scripts/create-task-ad-board.ts"
"create-task:ad-board": "ts-node scripts/create-task-ad-board.ts",
"forkAnvil": "ts-node scripts/forkAnvil.ts"
},
"keywords": [],
"author": "",
Expand Down
40 changes: 40 additions & 0 deletions scripts/forkAnvil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

import * as dotenv from 'dotenv';
dotenv.config();

const forkChain = async () => {

const { spawn } = await import("child_process");

const RPC = process.env['RPC']!
let params = ["-f",RPC]

let blockNumber;

if (blockNumber) {
params.push(`--fork-block-number=${blockNumber}`)
}

/// You can add as much customs params as wanted
const childProcess = spawn('anvil',params, {
stdio: "inherit",
});

childProcess.once("close", (status) => {
childProcess.removeAllListeners("error");

if (status === 0) {
console.log('ok')
} else {
console.log('error')
}

});

childProcess.once("error", (_status) => {
childProcess.removeAllListeners("close");
console.log('error')
});
}

forkChain()

0 comments on commit ce044fa

Please sign in to comment.