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