mirror of
https://github.com/codex-storage/codex-contracts-eth.git
synced 2025-01-10 11:55:44 +00:00
[marketplace] Remove fulfillRequest()
This commit is contained in:
parent
80f0cc6005
commit
f32974b496
@ -9,7 +9,6 @@ contract Marketplace is Collateral, Proofs {
|
||||
uint256 public immutable collateral;
|
||||
MarketplaceFunds private funds;
|
||||
mapping(bytes32 => Request) private requests;
|
||||
mapping(bytes32 => RequestState) private requestState;
|
||||
mapping(bytes32 => Slot) private slots;
|
||||
|
||||
constructor(
|
||||
@ -86,31 +85,6 @@ contract Marketplace is Collateral, Proofs {
|
||||
require(token.transfer(slot.host, amount), "Payment failed");
|
||||
}
|
||||
|
||||
function fulfillRequest(bytes32 requestId, bytes calldata proof)
|
||||
public
|
||||
marketplaceInvariant
|
||||
{
|
||||
RequestState storage state = requestState[requestId];
|
||||
require(state.host == address(0), "Request already fulfilled");
|
||||
|
||||
Request storage request = requests[requestId];
|
||||
require(request.client != address(0), "Unknown request");
|
||||
require(request.expiry > block.timestamp, "Request expired");
|
||||
|
||||
require(balanceOf(msg.sender) >= collateral, "Insufficient collateral");
|
||||
_lock(msg.sender, requestId);
|
||||
|
||||
_expectProofs(
|
||||
requestId,
|
||||
request.ask.proofProbability,
|
||||
request.ask.duration
|
||||
);
|
||||
_submitProof(requestId, proof);
|
||||
|
||||
state.host = msg.sender;
|
||||
emit RequestFulfilled(requestId);
|
||||
}
|
||||
|
||||
function _host(bytes32 slotId) internal view returns (address) {
|
||||
return slots[slotId].host;
|
||||
}
|
||||
@ -164,10 +138,6 @@ contract Marketplace is Collateral, Proofs {
|
||||
bytes name; // random name
|
||||
}
|
||||
|
||||
struct RequestState {
|
||||
address host;
|
||||
}
|
||||
|
||||
struct Slot {
|
||||
address host;
|
||||
bool hostPaid;
|
||||
|
@ -231,74 +231,4 @@ describe("Marketplace", function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe("fulfilling request", function () {
|
||||
const proof = hexlify(randomBytes(42))
|
||||
|
||||
beforeEach(async function () {
|
||||
switchAccount(client)
|
||||
await token.approve(marketplace.address, request.ask.reward)
|
||||
await marketplace.requestStorage(request)
|
||||
switchAccount(host)
|
||||
await token.approve(marketplace.address, collateral)
|
||||
await marketplace.deposit(collateral)
|
||||
})
|
||||
|
||||
it("emits event when request is fulfilled", async function () {
|
||||
await expect(marketplace.fulfillRequest(requestId(request), proof))
|
||||
.to.emit(marketplace, "RequestFulfilled")
|
||||
.withArgs(requestId(request))
|
||||
})
|
||||
|
||||
it("locks collateral of host", async function () {
|
||||
await marketplace.fulfillRequest(requestId(request), proof)
|
||||
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(
|
||||
marketplace.fulfillRequest(requestId(request), invalid)
|
||||
).to.be.revertedWith("Invalid proof")
|
||||
})
|
||||
|
||||
it("is rejected when collateral is insufficient", async function () {
|
||||
let insufficient = collateral - 1
|
||||
await marketplace.withdraw()
|
||||
await token.approve(marketplace.address, insufficient)
|
||||
await marketplace.deposit(insufficient)
|
||||
await expect(
|
||||
marketplace.fulfillRequest(requestId(request), proof)
|
||||
).to.be.revertedWith("Insufficient collateral")
|
||||
})
|
||||
|
||||
it("is rejected when request already fulfilled", async function () {
|
||||
await marketplace.fulfillRequest(requestId(request), proof)
|
||||
await expect(
|
||||
marketplace.fulfillRequest(requestId(request), proof)
|
||||
).to.be.revertedWith("Request already fulfilled")
|
||||
})
|
||||
|
||||
it("is rejected when request is unknown", async function () {
|
||||
let unknown = exampleRequest()
|
||||
await expect(
|
||||
marketplace.fulfillRequest(requestId(unknown), proof)
|
||||
).to.be.revertedWith("Unknown request")
|
||||
})
|
||||
|
||||
it("is rejected when request is expired", async function () {
|
||||
switchAccount(client)
|
||||
let expired = { ...request, expiry: now() - hours(1) }
|
||||
await token.approve(marketplace.address, request.ask.reward)
|
||||
await marketplace.requestStorage(expired)
|
||||
switchAccount(host)
|
||||
await expect(
|
||||
marketplace.fulfillRequest(requestId(expired), proof)
|
||||
).to.be.revertedWith("Request expired")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user