diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 883ec12..54d68d5 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -268,7 +268,7 @@ contract Marketplace is Collateral, Proofs { function proofEnd(SlotId slotId) public view returns (uint256) { Slot memory slot = _slot(slotId); - uint256 end = _end(_toEndId(slot.requestId)); + uint256 end = requestEnd(slot.requestId); if (_slotAcceptsProofs(slotId)) { return end; } else { @@ -276,6 +276,10 @@ contract Marketplace is Collateral, Proofs { } } + function requestEnd(RequestId requestId) public view returns (uint256) { + return _end(_toEndId(requestId)); + } + function _price( uint64 numSlots, uint256 duration, diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index e265942..ce352bf 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -179,7 +179,7 @@ describe("Marketplace", function () { it("is rejected when request is finished", async function () { const lastSlot = await waitUntilStarted(marketplace, request, slot, proof) - await waitUntilFinished(marketplace, lastSlot) + await waitUntilFinished(marketplace, requestId(request)) await expect( marketplace.fillSlot(slot.request, slot.index, proof) ).to.be.revertedWith("Request not accepting proofs") @@ -262,7 +262,7 @@ describe("Marketplace", function () { it("checks that proof end time is in the past once finished", async function () { const lastSlot = await waitUntilStarted(marketplace, request, slot, proof) - await waitUntilFinished(marketplace, lastSlot) + await waitUntilFinished(marketplace, requestId(request)) const now = await currentTime() // in the process of calling currentTime and proofEnd, // block.timestamp has advanced by 1, so the expected proof end time will @@ -303,7 +303,7 @@ describe("Marketplace", function () { it("fails to free slot when finished", async function () { const lastSlot = await waitUntilStarted(marketplace, request, slot, proof) - await waitUntilFinished(marketplace, lastSlot) + await waitUntilFinished(marketplace, requestId(request)) await expect(marketplace.freeSlot(slotId(slot))).to.be.revertedWith( "Slot not accepting proofs" ) @@ -340,7 +340,7 @@ describe("Marketplace", function () { it("pays the host", async function () { const lastSlot = await waitUntilStarted(marketplace, request, slot, proof) - await waitUntilFinished(marketplace, lastSlot) + await waitUntilFinished(marketplace, requestId(request)) const startBalance = await token.balanceOf(host.address) await marketplace.payoutSlot(slot.request, slot.index) const endBalance = await token.balanceOf(host.address) @@ -356,7 +356,7 @@ describe("Marketplace", function () { it("can only be done once", async function () { const lastSlot = await waitUntilStarted(marketplace, request, slot, proof) - await waitUntilFinished(marketplace, lastSlot) + await waitUntilFinished(marketplace, requestId(request)) await marketplace.payoutSlot(slot.request, slot.index) await expect( marketplace.payoutSlot(slot.request, slot.index) @@ -365,7 +365,7 @@ describe("Marketplace", function () { it("cannot be filled again", async function () { const lastSlot = await waitUntilStarted(marketplace, request, slot, proof) - await waitUntilFinished(marketplace, lastSlot) + await waitUntilFinished(marketplace, requestId(request)) await marketplace.payoutSlot(slot.request, slot.index) await expect(marketplace.fillSlot(slot.request, slot.index, proof)).to.be .reverted @@ -508,7 +508,7 @@ describe("Marketplace", function () { it("state is Finished once slot is paid out", async function () { const lastSlot = await waitUntilStarted(marketplace, request, slot, proof) - await waitUntilFinished(marketplace, lastSlot) + await waitUntilFinished(marketplace, requestId(request)) await marketplace.payoutSlot(slot.request, slot.index) await expect(await marketplace.state(slot.request)).to.equal( RequestState.Finished @@ -601,7 +601,7 @@ describe("Marketplace", function () { slot, proof ) - await waitUntilFinished(marketplace, lastSlot) + await waitUntilFinished(marketplace, requestId(request)) await expect( marketplace.testAcceptsProofs(slotId(slot)) ).to.be.revertedWith("Slot not accepting proofs") @@ -614,7 +614,7 @@ describe("Marketplace", function () { slot, proof ) - await waitUntilFinished(marketplace, lastSlot) + await waitUntilFinished(marketplace, requestId(request)) await marketplace.payoutSlot(slot.request, slot.index) await expect( marketplace.testAcceptsProofs(slotId(slot)) @@ -669,7 +669,7 @@ describe("Marketplace", function () { await marketplace.requestStorage(request) switchAccount(host) const lastSlot = await waitUntilStarted(marketplace, request, slot, proof) - await waitUntilFinished(marketplace, lastSlot) + await waitUntilFinished(marketplace, requestId(request)) await marketplace.payoutSlot(slot.request, slot.index) switchAccount(client) expect(await marketplace.myRequests()).to.deep.equal([]) diff --git a/test/Storage.test.js b/test/Storage.test.js index 4d2c39e..01746cb 100644 --- a/test/Storage.test.js +++ b/test/Storage.test.js @@ -76,7 +76,7 @@ describe("Storage", function () { describe("ending the contract", function () { it("unlocks the host collateral", async function () { await storage.fillSlot(slot.request, slot.index, proof) - await waitUntilFinished(storage, slot) + await waitUntilFinished(storage, slot.request) await expect(storage.withdraw()).not.to.be.reverted }) }) diff --git a/test/marketplace.js b/test/marketplace.js index 94317bb..bbcaa72 100644 --- a/test/marketplace.js +++ b/test/marketplace.js @@ -13,9 +13,8 @@ async function waitUntilStarted(contract, request, slot, proof) { return { ...slot, index: lastSlotIdx } } -async function waitUntilFinished(contract, lastSlot) { - const lastSlotId = slotId(lastSlot) - const end = (await contract.proofEnd(lastSlotId)).toNumber() +async function waitUntilFinished(contract, requestId) { + const end = (await contract.requestEnd(requestId)).toNumber() await advanceTimeTo(end + 1) }