diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 4057aeb..d1d0366 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -448,38 +448,13 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { _vault.withdraw(fund, account); } - /** - * @notice Withdraws remaining storage request funds back to the client that - deposited them. - * @dev Request must be cancelled, failed or finished, and the - transaction must originate from the depositor address. - * @param requestId the id of the request - */ + /// Withdraws remaining storage request funds back to the client that function withdrawFunds(RequestId requestId) public requestIsKnown(requestId) { - Request storage request = _requests[requestId]; - RequestContext storage context = _requestContexts[requestId]; - - if (request.client != msg.sender) revert Marketplace_InvalidClientAddress(); - - RequestState state = requestState(requestId); - if ( - state != RequestState.Cancelled && - state != RequestState.Failed && - state != RequestState.Finished - ) { - revert Marketplace_InvalidState(); - } - - context.state = state; - if (state == RequestState.Cancelled) { - emit RequestCancelled(requestId); - } - - _removeFromMyRequests(request.client, requestId); - FundId fund = requestId.asFundId(); - AccountId account = _vault.clientAccount(request.client); + AccountId account = _vault.clientAccount(msg.sender); _vault.withdraw(fund, account); + + _removeFromMyRequests(msg.sender, requestId); } function withdrawByValidator(RequestId requestId) public { @@ -627,5 +602,4 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { event RequestFailed(RequestId indexed requestId); event SlotFilled(RequestId indexed requestId, uint64 slotIndex); event SlotFreed(RequestId indexed requestId, uint64 slotIndex); - event RequestCancelled(RequestId indexed requestId); } diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 0be0c9e..e49be17 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -720,15 +720,18 @@ describe("Marketplace", function () { it("rejects withdraw when request not yet timed out", async function () { switchAccount(client) await expect(marketplace.withdrawFunds(slot.request)).to.be.revertedWith( - "Marketplace_InvalidState" + "VaultFundNotUnlocked" ) }) - it("rejects withdraw when wrong account used", async function () { + it("withdraws nothing when wrong account used", async function () { await waitUntilCancelled(marketplace, request) - await expect(marketplace.withdrawFunds(slot.request)).to.be.revertedWith( - "Marketplace_InvalidClientAddress" - ) + + const startBalance = await token.balanceOf(host.address) + await marketplace.withdrawFunds(slot.request) + const endBalance = await token.balanceOf(host.address) + + expect(endBalance - startBalance).to.equal(0) }) it("rejects withdraw when in wrong state", async function () { @@ -745,7 +748,7 @@ describe("Marketplace", function () { await waitUntilCancelled(marketplace, request) switchAccount(client) await expect(marketplace.withdrawFunds(slot.request)).to.be.revertedWith( - "Marketplace_InvalidState" + "VaultFundNotUnlocked" ) }) @@ -762,14 +765,6 @@ describe("Marketplace", function () { expect(endBalance - startBalance).to.equal(0) }) - it("emits event once request is cancelled", async function () { - await waitUntilCancelled(marketplace, request) - switchAccount(client) - await expect(marketplace.withdrawFunds(slot.request)) - .to.emit(marketplace, "RequestCancelled") - .withArgs(requestId(request)) - }) - it("withdraw rest of funds to the client for finished requests", async function () { await waitUntilStarted(marketplace, request, proof, token) await waitUntilFinished(marketplace, requestId(request))