diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index df8120e..e2d2262 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -6,6 +6,7 @@ contract Proofs { uint256 private immutable timeout; constructor(uint256 __period, uint256 __timeout) { + require(block.number > 256, "Insufficient block height"); period = __period; timeout = __timeout; } diff --git a/test/Proofs.test.js b/test/Proofs.test.js index ebfb695..469103c 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -1,9 +1,9 @@ const { expect } = require("chai") const { ethers } = require("hardhat") -const { mineBlock, minedBlockNumber } = require("./evm") const { snapshot, revert, + ensureMinimumBlockHeight, currentTime, advanceTime, advanceTimeTo, @@ -19,15 +19,9 @@ describe("Proofs", function () { let proofs - async function ensureEnoughBlockHistory() { - while ((await minedBlockNumber()) < 256) { - await mineBlock() - } - } - beforeEach(async function () { await snapshot() - await ensureEnoughBlockHistory() + await ensureMinimumBlockHeight(256) const Proofs = await ethers.getContractFactory("TestProofs") proofs = await Proofs.deploy(period, timeout) }) diff --git a/test/Storage.test.js b/test/Storage.test.js index 9162a57..0d9b2e8 100644 --- a/test/Storage.test.js +++ b/test/Storage.test.js @@ -2,8 +2,7 @@ const { expect } = require("chai") const { ethers, deployments } = require("hardhat") const { exampleRequest, exampleOffer } = require("./examples") const { - mineBlock, - minedBlockNumber, + ensureMinimumBlockHeight, advanceTime, advanceTimeTo, currentTime, @@ -24,15 +23,10 @@ describe("Storage", function () { storage = storage.connect(account) } - async function ensureEnoughBlockHistory() { - while ((await minedBlockNumber()) < 256) { - await mineBlock() - } - } - beforeEach(async function () { ;[client, host] = await ethers.getSigners() + await ensureMinimumBlockHeight(256) await deployments.fixture(["TestToken", "Storage"]) token = await ethers.getContract("TestToken") storage = await ethers.getContract("Storage") @@ -61,8 +55,6 @@ describe("Storage", function () { switchAccount(client) await storage.selectOffer(offerId(offer)) id = offerId(offer) - - await ensureEnoughBlockHistory() }) describe("starting the contract", function () { diff --git a/test/evm.js b/test/evm.js index e92090a..5de5deb 100644 --- a/test/evm.js +++ b/test/evm.js @@ -22,6 +22,12 @@ async function minedBlockNumber() { return await ethers.provider.getBlockNumber() } +async function ensureMinimumBlockHeight(height) { + while ((await minedBlockNumber()) < height) { + await mineBlock() + } +} + async function currentTime() { let block = await ethers.provider.getBlock("latest") return block.timestamp @@ -44,6 +50,7 @@ module.exports = { revert, mineBlock, minedBlockNumber, + ensureMinimumBlockHeight, currentTime, advanceTime, advanceTimeTo,