Skip to content

Commit

Permalink
Add the task to attempt to increase blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Oct 11, 2023
1 parent f32bca9 commit fbd5a70
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tasks/evm-increase-blocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {task} from "hardhat/config"
import {ethers} from "ethers"

const BLOCK_PERIOD = 12 // seconds

task(
"evm-increase-blocks",
"Helper task to increase the block number in the current EVM"
)
.addOptionalPositionalParam(
"blocks",
"How many blocks to increase by (defaults to 1)"
)
.setAction(async (taskArgs, hre) => {
const {network} = hre

const provider = network.provider
const blocks = parseInt(taskArgs.blocks ?? "1")

const currBlock = ethers.BigNumber.from(
await provider.send("eth_blockNumber")
)
console.log(`Previous block pre-update: ${currBlock}`)

await provider.send("evm_increaseBlocks", [
ethers.utils.hexValue(blocks) // hex encoded number of blocks to increase
])
// helpfully increase the time by 12s per block as well
await provider.send("evm_increaseTime", [
ethers.utils.hexValue(BLOCK_PERIOD * blocks) // hex encoded number of seconds
])

const newBlock = ethers.BigNumber.from(
await provider.send("eth_blockNumber")
)
console.log(`New block post-update: ${newBlock}`)
})

0 comments on commit fbd5a70

Please sign in to comment.