From 8efa9fe1621919692bbeb8973e106e495e773d57 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 3 Nov 2021 17:02:12 +0100 Subject: [PATCH] Stop requiring proofs when contract has ended --- contracts/Proofs.sol | 3 +++ test/Proofs.test.js | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index 6562418..a4fdde2 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -61,6 +61,9 @@ contract Proofs { internal view returns (bool) { + if (block.number >= ends[id]) { + return false; + } bytes32 hash = blockhash(blocknumber - 1); return hash != 0 && uint(hash) % periods[id] == markers[id]; } diff --git a/test/Proofs.test.js b/test/Proofs.test.js index d507e7f..984d0a2 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -6,7 +6,7 @@ describe("Proofs", function () { const id = ethers.utils.randomBytes(32) const period = 10 const timeout = 5 - const duration = 100 + const duration = 50 let proofs @@ -50,6 +50,20 @@ describe("Proofs", function () { ).to.be.revertedWith("Invalid proof timeout") }) + it("requires on average a proof every period", async function () { + let blocks = 500 + let amount = 0 + await proofs.expectProofs(id, period, timeout, blocks) + for (let i=0; i