Add EVM snapshots including time for tests
This commit is contained in:
parent
ee4683e50c
commit
22e8ea50e2
|
@ -1,6 +1,6 @@
|
|||
const { expect } = require("chai")
|
||||
const { ethers } = require("hardhat")
|
||||
const { mineBlock, minedBlockNumber } = require("./mining")
|
||||
const { mineBlock, minedBlockNumber } = require("./evm")
|
||||
|
||||
describe("Proofs", function () {
|
||||
const id = ethers.utils.randomBytes(32)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { expect } = require("chai")
|
||||
const { ethers, deployments } = require("hardhat")
|
||||
const { exampleRequest, exampleOffer } = require("./examples")
|
||||
const { mineBlock, minedBlockNumber } = require("./mining")
|
||||
const { mineBlock, minedBlockNumber } = require("./evm")
|
||||
const { requestId, offerId } = require("./ids")
|
||||
|
||||
describe("Storage", function () {
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
const { ethers } = require("hardhat")
|
||||
|
||||
let snapshots = []
|
||||
|
||||
async function snapshot() {
|
||||
const id = await ethers.provider.send("evm_snapshot")
|
||||
const time = await currentTime()
|
||||
snapshots.push({ id, time })
|
||||
}
|
||||
|
||||
async function revert() {
|
||||
const { id, time } = snapshots.pop()
|
||||
await ethers.provider.send("evm_revert", [id])
|
||||
await ethers.provider.send("evm_setNextBlockTimestamp", [time + 1])
|
||||
}
|
||||
|
||||
async function mineBlock() {
|
||||
await ethers.provider.send("evm_mine")
|
||||
}
|
||||
|
||||
async function minedBlockNumber() {
|
||||
return await ethers.provider.getBlockNumber()
|
||||
}
|
||||
|
||||
async function currentTime() {
|
||||
let block = await ethers.provider.getBlock("latest")
|
||||
return block.timestamp
|
||||
}
|
||||
|
||||
async function advanceTime(seconds) {
|
||||
ethers.provider.send("evm_increaseTime", [seconds])
|
||||
await mineBlock()
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
snapshot,
|
||||
revert,
|
||||
mineBlock,
|
||||
minedBlockNumber,
|
||||
currentTime,
|
||||
advanceTime,
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
const { ethers } = require("hardhat")
|
||||
|
||||
async function mineBlock() {
|
||||
await ethers.provider.send("evm_mine")
|
||||
}
|
||||
|
||||
async function minedBlockNumber() {
|
||||
return await ethers.provider.getBlockNumber()
|
||||
}
|
||||
|
||||
module.exports = { mineBlock, minedBlockNumber }
|
Loading…
Reference in New Issue