mirror of
https://github.com/status-im/codex-contracts-eth.git
synced 2025-02-07 06:04:26 +00:00
vault: allow automine to be disabled in time sensitive tests
This commit is contained in:
parent
cf875eb0d7
commit
ae160498ca
@ -1,7 +1,13 @@
|
||||
const { expect } = require("chai")
|
||||
const { ethers } = require("hardhat")
|
||||
const { randomBytes } = ethers.utils
|
||||
const { currentTime, advanceTimeToForNextBlock, mine } = require("./evm")
|
||||
const {
|
||||
currentTime,
|
||||
advanceTimeToForNextBlock,
|
||||
mine,
|
||||
snapshot,
|
||||
revert,
|
||||
} = require("./evm")
|
||||
|
||||
describe("Vault", function () {
|
||||
let token
|
||||
@ -10,6 +16,7 @@ describe("Vault", function () {
|
||||
let account, account2, account3
|
||||
|
||||
beforeEach(async function () {
|
||||
await snapshot()
|
||||
const TestToken = await ethers.getContractFactory("TestToken")
|
||||
token = await TestToken.deploy()
|
||||
const Vault = await ethers.getContractFactory("Vault")
|
||||
@ -20,6 +27,10 @@ describe("Vault", function () {
|
||||
await token.mint(account3.address, 1_000_000)
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
await revert()
|
||||
})
|
||||
|
||||
describe("depositing", function () {
|
||||
const context = randomBytes(32)
|
||||
const amount = 42
|
||||
|
11
test/evm.js
11
test/evm.js
@ -5,13 +5,19 @@ let snapshots = []
|
||||
async function snapshot() {
|
||||
const id = await ethers.provider.send("evm_snapshot")
|
||||
const time = await currentTime()
|
||||
snapshots.push({ id, time })
|
||||
const automine = await ethers.provider.send("hardhat_getAutomine")
|
||||
snapshots.push({ id, time, automine })
|
||||
}
|
||||
|
||||
async function revert() {
|
||||
const { id, time } = snapshots.pop()
|
||||
const { id, time, automine } = snapshots.pop()
|
||||
await ethers.provider.send("evm_revert", [id])
|
||||
await ethers.provider.send("evm_setNextBlockTimestamp", [time + 1])
|
||||
await ethers.provider.send("evm_setAutomine", [automine])
|
||||
}
|
||||
|
||||
async function setAutomine(enabled) {
|
||||
await ethers.provider.send("evm_setAutomine", [enabled])
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,6 +71,7 @@ async function advanceTimeToForNextBlock(timestamp) {
|
||||
module.exports = {
|
||||
snapshot,
|
||||
revert,
|
||||
setAutomine,
|
||||
mine,
|
||||
ensureMinimumBlockHeight,
|
||||
currentTime,
|
||||
|
Loading…
x
Reference in New Issue
Block a user