diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 37d4043..b0b309a 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -103,68 +103,6 @@ describe("Marketplace", function () { }) }) - describe("freeing a slot", function () { - var id - beforeEach(async function () { - slot.index = 0 - id = slotId(slot) - - switchAccount(client) - await token.approve(marketplace.address, price(request)) - await marketplace.requestStorage(request) - switchAccount(host) - await token.approve(marketplace.address, collateral) - await marketplace.deposit(collateral) - - // await marketplace.fillSlot(slot.request, slot.index, proof) - }) - - it("fails to free slot when slot not filled", async function () { - slot.index = 5 - let nonExistentId = slotId(slot) - await expect(marketplace.freeSlot(nonExistentId)).to.be.revertedWith( - "Slot empty" - ) - }) - - it("fails to free slot when not started", async function () { - await marketplace.fillSlot(slot.request, slot.index, proof) - await expect(marketplace.freeSlot(id)).to.be.revertedWith("Invalid state") - }) - - it("successfully frees slot", async function () { - await waitUntilAllSlotsFilled( - marketplace, - request.ask.slots, - slot.request, - proof - ) - await expect(marketplace.freeSlot(id)).not.to.be.reverted - }) - - it("emits event once slot is freed", async function () { - await waitUntilAllSlotsFilled( - marketplace, - request.ask.slots, - slot.request, - proof - ) - await expect(await marketplace.freeSlot(id)) - .to.emit(marketplace, "SlotFreed") - .withArgs(slot.request, id) - }) - - it("cannot get slot once freed", async function () { - await waitUntilAllSlotsFilled( - marketplace, - request.ask.slots, - slot.request, - proof - ) - await marketplace.freeSlot(id) - await expect(marketplace.slot(id)).to.be.revertedWith("Slot empty") - }) - }) describe("filling a slot", function () { beforeEach(async function () { @@ -252,6 +190,67 @@ describe("Marketplace", function () { }) }) + describe("freeing a slot", function () { + var id + beforeEach(async function () { + slot.index = 0 + id = slotId(slot) + + switchAccount(client) + await token.approve(marketplace.address, price(request)) + await marketplace.requestStorage(request) + switchAccount(host) + await token.approve(marketplace.address, collateral) + await marketplace.deposit(collateral) + }) + + it("fails to free slot when slot not filled", async function () { + slot.index = 5 + let nonExistentId = slotId(slot) + await expect(marketplace.freeSlot(nonExistentId)).to.be.revertedWith( + "Slot empty" + ) + }) + + it("fails to free slot when not started", async function () { + await marketplace.fillSlot(slot.request, slot.index, proof) + await expect(marketplace.freeSlot(id)).to.be.revertedWith("Invalid state") + }) + + it("successfully frees slot", async function () { + await waitUntilAllSlotsFilled( + marketplace, + request.ask.slots, + slot.request, + proof + ) + await expect(marketplace.freeSlot(id)).not.to.be.reverted + }) + + it("emits event once slot is freed", async function () { + await waitUntilAllSlotsFilled( + marketplace, + request.ask.slots, + slot.request, + proof + ) + await expect(await marketplace.freeSlot(id)) + .to.emit(marketplace, "SlotFreed") + .withArgs(slot.request, id) + }) + + it("cannot get slot once freed", async function () { + await waitUntilAllSlotsFilled( + marketplace, + request.ask.slots, + slot.request, + proof + ) + await marketplace.freeSlot(id) + await expect(marketplace.slot(id)).to.be.revertedWith("Slot empty") + }) + }) + describe("paying out a slot", function () { beforeEach(async function () { switchAccount(client) @@ -429,7 +428,7 @@ describe("Marketplace", function () { ) }) - it("state is Failed once too many slots are freed", async function () { + it("changes state to Failed once too many slots are freed", async function () { await waitUntilAllSlotsFilled( marketplace, request.ask.slots, diff --git a/test/Proofs.test.js b/test/Proofs.test.js index 2f26347..55adf12 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -139,9 +139,7 @@ describe("Proofs", function () { expect(await proofs.isProofRequired(id)).to.be.true }) - it("proofs won't be required when no longer expected", async function () { - expect(await proofs.getPointer(id)).to.be.lt(downtime) - expect(await proofs.willProofBeRequired(id)).to.be.true + it("will not require proofs when no longer expected", async function () { await proofs.unexpectProofs(id) expect(await proofs.willProofBeRequired(id)).to.be.false }) diff --git a/test/marketplace.js b/test/marketplace.js index 8863f9e..a67715f 100644 --- a/test/marketplace.js +++ b/test/marketplace.js @@ -17,4 +17,4 @@ async function waitUntilAllSlotsFilled(contract, numSlots, requestId, proof) { } } -module.exports = { waitUntilExpired, waitUntilAllSlotsFilled } +module.exports = { waitUntilExpired, waitUntilAllSlotsFilled, RequestState }