[marketplace] require storage proofs when fulfilling request

This commit is contained in:
Mark Spanbroek 2022-06-13 11:49:25 +02:00 committed by markspanbroek
parent 83291ef06b
commit f3b969fd7c
3 changed files with 22 additions and 12 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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(