diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index 538e1b2..5ca7350 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -89,6 +89,10 @@ contract Proofs { return _getChallenge(_getPointer(id, proofPeriod)); } + function _getChallenge(bytes32 id) internal view returns (bytes32) { + return _getChallenge(id, currentPeriod()); + } + function _isProofRequired(bytes32 id, uint256 proofPeriod) internal view diff --git a/contracts/Storage.sol b/contracts/Storage.sol index b6806d8..1353284 100644 --- a/contracts/Storage.sol +++ b/contracts/Storage.sol @@ -64,6 +64,10 @@ contract Storage is Collateral, Marketplace, Proofs { return _isProofRequired(contractId); } + function getChallenge(bytes32 contractId) public view returns (bytes32) { + return _getChallenge(contractId); + } + function submitProof(bytes32 contractId, bool proof) public { _submitProof(contractId, proof); } diff --git a/contracts/TestProofs.sol b/contracts/TestProofs.sol index efc51d1..6b79500 100644 --- a/contracts/TestProofs.sol +++ b/contracts/TestProofs.sol @@ -44,6 +44,10 @@ contract TestProofs is Proofs { return _isProofRequired(id); } + function getChallenge(bytes32 id) public view returns (bytes32) { + return _getChallenge(id); + } + function submitProof(bytes32 id, bool proof) public { _submitProof(id, proof); } diff --git a/test/Proofs.test.js b/test/Proofs.test.js index d466fa2..4e657aa 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -112,6 +112,23 @@ describe("Proofs", function () { } } + it("provides different challenges per period", async function () { + await waitUntilProofIsRequired(id) + const challenge1 = await proofs.getChallenge(id) + await waitUntilProofIsRequired(id) + const challenge2 = await proofs.getChallenge(id) + expect(challenge2).not.to.equal(challenge1) + }) + + it("provides different challenges per id", async function () { + const id2 = ethers.utils.randomBytes(32) + const id3 = ethers.utils.randomBytes(32) + const challenge1 = await proofs.getChallenge(id) + const challenge2 = await proofs.getChallenge(id2) + const challenge3 = await proofs.getChallenge(id3) + expect(challenge1 === challenge2 && challenge2 === challenge3).to.be.false + }) + it("submits a correct proof", async function () { await proofs.submitProof(id, true) })