diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index a4fdde2..1315c05 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -6,6 +6,7 @@ contract Proofs { mapping(bytes32=>bool) private ids; mapping(bytes32=>uint) private periods; mapping(bytes32=>uint) private timeouts; + mapping(bytes32=>uint) private starts; mapping(bytes32=>uint) private ends; mapping(bytes32=>uint) private markers; mapping(bytes32=>uint) private missed; @@ -46,6 +47,7 @@ contract Proofs { ids[id] = true; periods[id] = period; timeouts[id] = timeout; + starts[id] = block.number; ends[id] = block.number + duration + 2 * timeout; markers[id] = uint(blockhash(block.number - 1)) % period; } @@ -61,7 +63,7 @@ contract Proofs { internal view returns (bool) { - if (block.number >= ends[id]) { + if (blocknumber < starts[id] || blocknumber >= ends[id]) { return false; } bytes32 hash = blockhash(blocknumber - 1); diff --git a/test/Proofs.test.js b/test/Proofs.test.js index 984d0a2..ca7a5e1 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -64,6 +64,17 @@ describe("Proofs", function () { expect(average).to.be.closeTo(period, period / 2) }) + it("requires no proof before start time", async function () { + for (let i=0; i<4*period; i++) { + mineBlock() + } + await proofs.expectProofs(id, period, timeout, duration) + let start = await minedBlockNumber() + for (let i=1; i<4*period; i++) { + expect(await proofs.isProofRequired(id, start-i)).to.be.false + } + }) + describe("when proofs are required", async function () { beforeEach(async function () {