diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 1f84b30..d00cf7c 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -261,10 +261,11 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { if (slot.host != msg.sender) revert Marketplace_InvalidSlotHost(); SlotState state = slotState(slotId); - if (state == SlotState.Finished) { + if ( + state == SlotState.Finished || + state == SlotState.Cancelled + ) { _payoutSlot(slot.requestId, slotId); - } else if (state == SlotState.Cancelled) { - _payoutCancelledSlot(slot.requestId, slotId); } else if (state == SlotState.Failed) { _removeFromMySlots(msg.sender, slotId); } else if (state == SlotState.Filled) { @@ -386,24 +387,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { } } - function _payoutSlot( - RequestId requestId, - SlotId slotId - ) private requestIsKnown(requestId) { - RequestContext storage context = _requestContexts[requestId]; - Request storage request = _requests[requestId]; - context.state = RequestState.Finished; - Slot storage slot = _slots[slotId]; - slot.currentCollateral = 0; - - _removeFromMyRequests(request.client, requestId); - _removeFromMySlots(slot.host, slotId); - - FundId fund = requestId.asFundId(); - AccountId account = _vault.hostAccount(slot.host, slot.slotIndex); - _vault.withdraw(fund, account); - } - /** * @notice Pays out a host for duration of time that the slot was filled, and returns the collateral. @@ -411,7 +394,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { out. * @param slotId SlotId of the slot to be paid out. */ - function _payoutCancelledSlot( + function _payoutSlot( RequestId requestId, SlotId slotId ) private requestIsKnown(requestId) { diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 77595a9..597a4da 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -1314,16 +1314,6 @@ describe("Marketplace", function () { switchAccount(client) expect(await marketplace.myRequests()).to.deep.equal([requestId(request)]) }) - - it("removes request from list when request finishes", async function () { - await marketplace.requestStorage(request) - switchAccount(host) - await waitUntilStarted(marketplace, request, proof, token) - await waitUntilFinished(marketplace, requestId(request)) - await marketplace.freeSlot(slotId(slot)) - switchAccount(client) - expect(await marketplace.myRequests()).to.deep.equal([]) - }) }) describe("list of active slots", function () {