-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the task to attempt to increase blocks
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`) | ||
}) |