Do not require proofs before start of contract
This commit is contained in:
parent
8efa9fe162
commit
c0fb0c725c
|
@ -6,6 +6,7 @@ contract Proofs {
|
||||||
mapping(bytes32=>bool) private ids;
|
mapping(bytes32=>bool) private ids;
|
||||||
mapping(bytes32=>uint) private periods;
|
mapping(bytes32=>uint) private periods;
|
||||||
mapping(bytes32=>uint) private timeouts;
|
mapping(bytes32=>uint) private timeouts;
|
||||||
|
mapping(bytes32=>uint) private starts;
|
||||||
mapping(bytes32=>uint) private ends;
|
mapping(bytes32=>uint) private ends;
|
||||||
mapping(bytes32=>uint) private markers;
|
mapping(bytes32=>uint) private markers;
|
||||||
mapping(bytes32=>uint) private missed;
|
mapping(bytes32=>uint) private missed;
|
||||||
|
@ -46,6 +47,7 @@ contract Proofs {
|
||||||
ids[id] = true;
|
ids[id] = true;
|
||||||
periods[id] = period;
|
periods[id] = period;
|
||||||
timeouts[id] = timeout;
|
timeouts[id] = timeout;
|
||||||
|
starts[id] = block.number;
|
||||||
ends[id] = block.number + duration + 2 * timeout;
|
ends[id] = block.number + duration + 2 * timeout;
|
||||||
markers[id] = uint(blockhash(block.number - 1)) % period;
|
markers[id] = uint(blockhash(block.number - 1)) % period;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +63,7 @@ contract Proofs {
|
||||||
internal view
|
internal view
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
if (block.number >= ends[id]) {
|
if (blocknumber < starts[id] || blocknumber >= ends[id]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bytes32 hash = blockhash(blocknumber - 1);
|
bytes32 hash = blockhash(blocknumber - 1);
|
||||||
|
|
|
@ -64,6 +64,17 @@ describe("Proofs", function () {
|
||||||
expect(average).to.be.closeTo(period, period / 2)
|
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 () {
|
describe("when proofs are required", async function () {
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
|
|
Loading…
Reference in New Issue