[marketplace] Emit RequestFulfilled when all slots are filled

This commit is contained in:
Mark Spanbroek 2022-07-20 10:29:24 +02:00 committed by markspanbroek
parent f32974b496
commit 9a76c04d45
2 changed files with 30 additions and 0 deletions

View File

@ -9,6 +9,7 @@ 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(
@ -65,8 +66,13 @@ contract Marketplace is Collateral, Proofs {
_expectProofs(slotId, request.ask.proofProbability, request.ask.duration);
_submitProof(slotId, proof);
RequestState storage state = requestState[requestId];
slot.host = msg.sender;
state.slotsFilled += 1;
emit SlotFilled(requestId, slotIndex, slotId);
if (state.slotsFilled == request.content.erasure.totalNodes) {
emit RequestFulfilled(requestId);
}
}
function payoutSlot(bytes32 requestId, uint256 slotIndex)
@ -138,6 +144,10 @@ contract Marketplace is Collateral, Proofs {
bytes name; // random name
}
struct RequestState {
uint256 slotsFilled;
}
struct Slot {
address host;
bool hostPaid;

View File

@ -231,4 +231,24 @@ describe("Marketplace", function () {
})
})
describe("fulfilling a request", function () {
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 all slots are filled", async function () {
const lastSlot = request.content.erasure.totalNodes - 1
for (let i = 0; i < lastSlot; i++) {
await marketplace.fillSlot(slot.request, i, proof)
}
await expect(marketplace.fillSlot(slot.request, lastSlot, proof))
.to.emit(marketplace, "RequestFulfilled")
.withArgs(requestId(request))
})
})
})