Commit 72a325f6 authored by Mark Tyneway's avatar Mark Tyneway

hardhat-node: add forking configuration

Adds forking config to the `ethereumoptimism/hardhat` docker image.
This can be configured with the following env vars:

- `FORK_URL` - http provider of the remote node to fetch data from
- `FORK_STARTING_BLOCK` - block to start forking from, if left
  undefined it will use the tip

Without `FORK_URL` set, it will not run in forking mode

Also adds the ability to configure the gas price with:

- `GAS_PRICE` - defaults to 0, which was the previous behavior
parent dd3e79a3
---
'@eth-optimism/hardhat-node': patch
---
Add fork mode config to ethereumoptimism/hardhat docker image
...@@ -7,6 +7,8 @@ services: ...@@ -7,6 +7,8 @@ services:
build: build:
context: ./docker/hardhat context: ./docker/hardhat
dockerfile: Dockerfile dockerfile: Dockerfile
env_file:
- ./envs/l1_chain.env
ports: ports:
# expose the service to the host for integration testing # expose the service to the host for integration testing
- ${L1CHAIN_HTTP_PORT:-9545}:8545 - ${L1CHAIN_HTTP_PORT:-9545}:8545
......
module.exports = { const isForkModeEnabled = !!process.env.FORK_URL
const forkUrl = process.env.FORK_URL
const forkStartingBlock = parseInt(process.env.FORK_STARTING_BLOCK) || undefined
const gasPrice = parseInt(process.env.GAS_PRICE) || 0
const config = {
networks: { networks: {
hardhat: { hardhat: {
gasPrice: 0, gasPrice,
initialBaseFeePerGas: 0 initialBaseFeePerGas: 0
}, },
}, },
analytics: { enabled: false }, analytics: { enabled: false },
} }
if (isForkModeEnabled) {
console.log(`Running hardhat in a fork mode! URL: ${forkUrl}`)
if (forkStartingBlock) {
console.log(`Starting block: ${forkStartingBlock}`)
}
config.networks.hardhat.forking = {
url: forkUrl,
blockNumber: forkStartingBlock,
}
} else {
console.log('Running with a fresh state...')
}
module.exports = config
FORK_URL=
FORK_STARTING_BLOCK=
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment