-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fork feature #405
base: main
Are you sure you want to change the base?
Add fork feature #405
Changes from 6 commits
7415562
36df86b
1503e2f
027f63d
907501e
beb0013
425bb4f
504ba3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
INFURA_KEY=<fillme> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,5 @@ jobs: | |
|
||
- name: Test 🧪 | ||
run: npm test | ||
env: | ||
INFURA_KEY: ${{ secrets.INFURA_KEY }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,24 +68,35 @@ class LocalTableland { | |
} | ||
|
||
// make sure we are starting fresh | ||
// TODO: I don't think this is doing anything anymore... | ||
this.#_cleanup(); | ||
|
||
// Run a local hardhat node | ||
this.registry = spawn( | ||
isWindows() ? "npx.cmd" : "npx", | ||
["hardhat", "node"], | ||
{ | ||
// we can't run in windows if we use detached mode | ||
detached: !isWindows(), | ||
cwd: this.registryDir, | ||
env: { | ||
...process.env, | ||
HARDHAT_NETWORK: "hardhat", | ||
HARDHAT_UNLIMITED_CONTRACT_SIZE: "true", | ||
}, | ||
// There's two ways of signaling a mainnet fork should be used. The `FORK` | ||
// env var, or the config has a fork property. Either way this means we | ||
// don't need to deploy the registry, and the validator should listen to | ||
// a different contract address, specifically the mainnet address. | ||
const shouldFork = !!(process.env.FORK || config.fork); | ||
const hardhatCommandArr = ["hardhat", "node"]; | ||
|
||
if (config.fork) { | ||
hardhatCommandArr.push("--fork"); | ||
hardhatCommandArr.push(config.fork); | ||
if (config.forkBlockNumber) { | ||
hardhatCommandArr.push("--fork-block-number"); | ||
hardhatCommandArr.push(config.forkBlockNumber); | ||
} | ||
); | ||
} | ||
|
||
// Run a local hardhat node | ||
this.registry = spawn(isWindows() ? "npx.cmd" : "npx", hardhatCommandArr, { | ||
// we can't run in windows if we use detached mode | ||
detached: !isWindows(), | ||
cwd: this.registryDir, | ||
env: { | ||
...process.env, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
HARDHAT_NETWORK: "hardhat", | ||
HARDHAT_UNLIMITED_CONTRACT_SIZE: "true", | ||
}, | ||
}); | ||
|
||
this.registry.on("error", (err) => { | ||
throw new Error(`registry errored with: ${err}`); | ||
|
@@ -106,18 +117,19 @@ class LocalTableland { | |
// wait until initialization is done | ||
await waitForReady(registryReadyEvent, this.initEmitter); | ||
|
||
// Deploy the Registry to the Hardhat node | ||
logSync( | ||
spawnSync( | ||
isWindows() ? "npx.cmd" : "npx", | ||
["hardhat", "run", "--network", "localhost", "scripts/deploy.ts"], | ||
{ | ||
cwd: this.registryDir, | ||
} | ||
), | ||
!inDebugMode() | ||
); | ||
|
||
if (!shouldFork) { | ||
// Deploy the Registry to the Hardhat node | ||
logSync( | ||
spawnSync( | ||
isWindows() ? "npx.cmd" : "npx", | ||
["hardhat", "run", "--network", "localhost", "scripts/deploy.ts"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only deploy the registry if NOT using a fork, since the fork already has the registry deployed. |
||
{ | ||
cwd: this.registryDir, | ||
} | ||
), | ||
!inDebugMode() | ||
); | ||
} | ||
// need to determine if we are starting the validator via docker | ||
// and a local repo, or if are running a binary etc... | ||
const ValidatorClass = this.validatorDir ? ValidatorDev : ValidatorPkg; | ||
|
@@ -127,7 +139,7 @@ class LocalTableland { | |
// run this before starting in case the last instance of the validator didn't get cleanup after | ||
// this might be needed if a test runner force quits the parent local-tableland process | ||
this.validator.cleanup(); | ||
this.validator.start(); | ||
this.validator.start(shouldFork); | ||
|
||
// TODO: It seems like this check isn't sufficient to see if the process is gonna get to a point | ||
// where the on error listener can be attached. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the JS class config is set, but the dev can also use the command flags or env vars to specify.