From 4f75159e02c13be0c7d5ed433f6828e4127ffd30 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Mon, 28 Nov 2022 11:51:19 +0100 Subject: [PATCH] [marketplace] Slots of failed request remain in mySlots() Until hosts calls freeSlot() --- contracts/Marketplace.sol | 8 +----- test/Marketplace.test.js | 55 +++++---------------------------------- 2 files changed, 7 insertions(+), 56 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 5df30ab..dc511a9 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -22,7 +22,6 @@ contract Marketplace is Collateral, Proofs { mapping(SlotId => Slot) private slots; mapping(address => EnumerableSet.Bytes32Set) private requestsPerClient; // purchasing mapping(address => EnumerableSet.Bytes32Set) private slotsPerHost; // sales - mapping(SlotId => RequestId) private requestForSlot; constructor( IERC20 _token, @@ -42,12 +41,8 @@ contract Marketplace is Collateral, Proofs { return _toRequestIds(requestsPerClient[msg.sender].values()); } - function isActive(bytes32 slot) private view returns (bool) { - return state(requestForSlot[SlotId.wrap(slot)]) != RequestState.Failed; - } - function mySlots() public view returns (SlotId[] memory) { - return _toSlotIds(slotsPerHost[msg.sender].filter(isActive)); + return _toSlotIds(slotsPerHost[msg.sender].values()); } function isWithdrawAllowed() internal view override returns (bool) { @@ -111,7 +106,6 @@ contract Marketplace is Collateral, Proofs { context.slotsFilled += 1; slotsPerHost[slot.host].add(SlotId.unwrap(slotId)); - requestForSlot[slotId] = requestId; emit SlotFilled(requestId, slotIndex, slotId); if (context.slotsFilled == request.ask.slots) { diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index d456411..9025c3a 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -758,60 +758,17 @@ describe("Marketplace", function () { ]) }) - it("removes active slots for all hosts in a request when it fails", async function () { - let halfOfSlots = request.ask.slots / 2 - - // fill half the slots with host1 - for (let i = 0; i < Math.floor(halfOfSlots); i++) { - await marketplace.fillSlot(requestId(request), i, proof) - } - - // fill other half of slots with host2 - switchAccount(host2) - await token.approve(marketplace.address, collateral) - await marketplace.deposit(collateral) - for (let i = Math.floor(halfOfSlots); i < request.ask.slots; i++) { - await marketplace.fillSlot(requestId(request), i, proof) - } - - await waitUntilFailed(marketplace, request, slot) - expect(await marketplace.mySlots()).to.have.members([]) - switchAccount(host) - expect(await marketplace.mySlots()).to.have.members([]) - }) - - it("doesn't remove active slots for hosts in request that didn't fail", async function () { - // start first request - await waitUntilStarted(marketplace, request, proof) - - // start a second request - let request2 = await exampleRequest() - request2.client = client.address - switchAccount(client) - await token.approve(marketplace.address, price(request2)) - await marketplace.requestStorage(request2) - switchAccount(host) - await waitUntilStarted(marketplace, request2, proof) - - // wait until first request fails - await waitUntilFailed(marketplace, request, slot) - - // check that our active slots only contains slotIds from second request - let expected = [] - let expectedSlot = { ...slot, index: 0, request: requestId(request2) } - for (let i = 0; i < request2.ask.slots; i++) { - expectedSlot.index = i - let id = slotId(expectedSlot) - expected.push(id) - } - expect(await marketplace.mySlots()).to.have.members(expected) - }) - it("removes slot from list when slot is paid out", async function () { await waitUntilStarted(marketplace, request, proof) await waitUntilFinished(marketplace, requestId(request)) await marketplace.freeSlot(slotId(slot)) expect(await marketplace.mySlots()).to.not.contain(slotId(slot)) }) + + it("removes slot from list when failed slot is freed", async function () { + await waitUntilStarted(marketplace, request, proof) + await waitUntilFailed(marketplace, request, slot) + expect(await marketplace.mySlots()).to.not.contain(slotId(slot)) + }) }) })