hardhat本地调试,如何快速过区块? 类似这样的:
const { time } = require('@openzeppelin/test-helpers');
...
// 快速跳到第170区块
await time.advanceBlockTo('170');
可以通过 evm_mine
rpc 来控制出块:
advanceBlock = (web3) => {
return new Promise((resolve, reject) => {
web3.currentProvider.send({
jsonrpc: '2.0',
method: 'evm_mine',
id: new Date().getTime()
}, (err, result) => {
if (err) { return reject(err) }
const newBlockHash = web3.eth.getBlock('latest').hash
return resolve(newBlockHash)
})
})
}
出 N 个块就是:
for (i = 0 ; i < n; i++) {
await advanceBlock(web3);
}