From 3fd7c756d9887adc2d71298327ab0f13348f1518 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 10 Mar 2022 13:35:41 +0100 Subject: [PATCH] Fix flaky tests By ensuring that there's enough blocks left for submitting a proof. --- contracts/Proofs.sol | 4 ++++ contracts/Storage.sol | 4 ++++ contracts/TestProofs.sol | 4 ++++ test/Proofs.test.js | 7 ++++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index 5ca7350..b1fb270 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -75,6 +75,10 @@ contract Proofs { return uint8(pointer); } + function _getPointer(bytes32 id) internal view returns (uint8) { + return _getPointer(id, currentPeriod()); + } + function _getChallenge(uint8 pointer) internal view returns (bytes32) { bytes32 hash = blockhash(block.number - 1 - pointer); assert(uint256(hash) != 0); diff --git a/contracts/Storage.sol b/contracts/Storage.sol index 1353284..38aeb00 100644 --- a/contracts/Storage.sol +++ b/contracts/Storage.sol @@ -68,6 +68,10 @@ contract Storage is Collateral, Marketplace, Proofs { return _getChallenge(contractId); } + function getPointer(bytes32 id) public view returns (uint8) { + return _getPointer(id); + } + function submitProof(bytes32 contractId, bool proof) public { _submitProof(contractId, proof); } diff --git a/contracts/TestProofs.sol b/contracts/TestProofs.sol index 6b79500..3fac3aa 100644 --- a/contracts/TestProofs.sol +++ b/contracts/TestProofs.sol @@ -48,6 +48,10 @@ contract TestProofs is Proofs { return _getChallenge(id); } + function getPointer(bytes32 id) public view returns (uint8) { + return _getPointer(id); + } + function submitProof(bytes32 id, bool proof) public { _submitProof(id, proof); } diff --git a/test/Proofs.test.js b/test/Proofs.test.js index 4e657aa..75247e9 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -107,7 +107,12 @@ describe("Proofs", function () { async function waitUntilProofIsRequired(id) { await advanceTimeTo(periodEnd(periodOf(await currentTime()))) - while (!(await proofs.isProofRequired(id))) { + while ( + !( + (await proofs.isProofRequired(id)) && + (await proofs.getPointer(id)) < 250 + ) + ) { await advanceTime(period) } }