From f3b969fd7cf6de400741e42c18ffee1ad4cd3ace Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Mon, 13 Jun 2022 11:49:25 +0200 Subject: [PATCH] [marketplace] require storage proofs when fulfilling request --- contracts/Marketplace.sol | 17 +++++++++++++++++ contracts/Storage.sol | 12 ------------ test/Marketplace.test.js | 5 +++++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 54143a9..5497944 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -60,6 +60,11 @@ contract Marketplace is Collateral, Proofs { require(balanceOf(msg.sender) >= collateral, "Insufficient collateral"); _lock(msg.sender, requestId); + _expectProofs( + requestId, + request.ask.proofProbability, + request.ask.duration + ); _submitProof(requestId, proof); state.fulfilled = true; @@ -123,6 +128,18 @@ contract Marketplace is Collateral, Proofs { return requestState[requestId].selectedOffer; } + function proofPeriod() public view returns (uint256) { + return _period(); + } + + function proofTimeout() public view returns (uint256) { + return _timeout(); + } + + function proofEnd(bytes32 contractId) public view returns (uint256) { + return _end(contractId); + } + struct Request { address client; Ask ask; diff --git a/contracts/Storage.sol b/contracts/Storage.sol index 36cf35a..c96b39b 100644 --- a/contracts/Storage.sol +++ b/contracts/Storage.sol @@ -59,18 +59,6 @@ contract Storage is Collateral, Marketplace { require(token.transfer(offer.host, offer.price), "Payment failed"); } - function proofPeriod() public view returns (uint256) { - return _period(); - } - - function proofTimeout() public view returns (uint256) { - return _timeout(); - } - - function proofEnd(bytes32 contractId) public view returns (uint256) { - return _end(contractId); - } - function missingProofs(bytes32 contractId) public view returns (uint256) { return _missed(contractId); } diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index a39e251..f18cded 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -115,6 +115,11 @@ describe("Marketplace", function () { await expect(marketplace.withdraw()).to.be.revertedWith("Account locked") }) + it("starts requiring storage proofs", async function () { + await marketplace.fulfillRequest(requestId(request), proof) + expect(await marketplace.proofEnd(requestId(request))).to.be.gt(0) + }) + it("is rejected when proof is incorrect", async function () { let invalid = hexlify([]) await expect(