const { expect } = require("chai") const { ethers } = require("hardhat") describe("Proofs", function () { const id = ethers.utils.randomBytes(32) const period = 10 const timeout = 5 let proofs beforeEach(async function () { const Proofs = await ethers.getContractFactory("TestProofs") proofs = await Proofs.deploy() }) it("indicates that proofs are required", async function() { await proofs.expectProofs(id, period, timeout) expect(await proofs.period(id)).to.equal(period) expect(await proofs.timeout(id)).to.equal(timeout) }) it("does not allow ids to be reused", async function() { await proofs.expectProofs(id, period, timeout) await expect( proofs.expectProofs(id, period, timeout) ).to.be.revertedWith("Proof id already in use") }) it("does not allow a proof timeout that is too large", async function () { let invalidTimeout = 129 // max proof timeout is 128 blocks await expect( proofs.expectProofs(id, period, invalidTimeout) ).to.be.revertedWith("Invalid proof timeout") }) describe("when proofs are required", async function () { beforeEach(async function () { await proofs.expectProofs(id, period, timeout) }) async function mineBlock() { await ethers.provider.send("evm_mine") } async function minedBlockNumber() { return await ethers.provider.getBlockNumber() - 1 } async function mineUntilProofIsRequired(id) { while (!await proofs.isProofRequired(id, await minedBlockNumber())) { mineBlock() } } async function mineUntilProofTimeout() { for (let i=0; i