From 3326c4fe7451133cc8ced2de7f1d254b3a4022c6 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 3 Nov 2021 13:18:08 +0100 Subject: [PATCH] Make isProofRequired() work for the current block The block hash of the current block is not known yet, so we use the block hash of the previous block to determine whether a proof is required for a block. --- contracts/Proofs.sol | 2 +- test/Proofs.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index 399f83a..e856c50 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -50,7 +50,7 @@ contract Proofs { internal view returns (bool) { - bytes32 hash = blockhash(blocknumber); + 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 c6a011f..1dcd350 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -45,7 +45,7 @@ describe("Proofs", function () { } async function minedBlockNumber() { - return await ethers.provider.getBlockNumber() - 1 + return await ethers.provider.getBlockNumber() } async function mineUntilProofIsRequired(id) {