Add getChallenge() to Storage contract
This commit is contained in:
parent
fd55afcc5a
commit
f8ddc4a2f6
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue