mirror of
https://github.com/logos-storage/logos-storage-contracts-eth.git
synced 2026-02-05 13:43:18 +00:00
vault: allow automine to be disabled in time sensitive tests
This commit is contained in:
parent
dc4e277a20
commit
a18fbb8899
@ -1,7 +1,13 @@
|
||||
const { expect } = require("chai")
|
||||
const { ethers } = require("hardhat")
|
||||
const { randomBytes } = ethers.utils
|
||||
const { currentTime, advanceTimeTo, mine } = require("./evm")
|
||||
const {
|
||||
currentTime,
|
||||
advanceTimeTo,
|
||||
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])
|
||||
await ethers.provider.send("evm_setAutomine", [automine])
|
||||
}
|
||||
|
||||
async function setAutomine(enabled) {
|
||||
await ethers.provider.send("evm_setAutomine", [enabled])
|
||||
}
|
||||
|
||||
async function mine() {
|
||||
@ -46,6 +52,7 @@ async function setNextBlockTimestamp(timestamp) {
|
||||
module.exports = {
|
||||
snapshot,
|
||||
revert,
|
||||
setAutomine,
|
||||
mine,
|
||||
ensureMinimumBlockHeight,
|
||||
currentTime,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user