const { expect } = require("chai") const { ethers } = require("hardhat") const { mineBlock, minedBlockNumber } = require ("./mining") describe("Proofs", function () { const id = ethers.utils.randomBytes(32) const period = 10 const timeout = 5 const duration = 50 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, duration) expect(await proofs.period(id)).to.equal(period) expect(await proofs.timeout(id)).to.equal(timeout) }) it("calculates an endtime based on duration and timeout", async function() { await proofs.expectProofs(id, period, timeout, duration) let start = await minedBlockNumber() let end = start + duration + 2 * timeout expect(await proofs.end(id)).to.equal(end) }) it("does not allow ids to be reused", async function() { await proofs.expectProofs(id, period, timeout, duration) await expect( proofs.expectProofs(id, period, timeout, duration) ).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, duration) ).to.be.revertedWith("Invalid proof timeout") }) it("requires on average a proof every period", async function () { let blocks = 600 let amount = 0 await proofs.expectProofs(id, period, timeout, blocks) for (let i=0; i