From f16b9b07ae4aa5b277fe5f48c0abfa06d4a8ea34 Mon Sep 17 00:00:00 2001 From: Eric Mastro Date: Tue, 16 Aug 2022 13:19:51 +1000 Subject: [PATCH] [marketplace] add more tests Add missing tests for `isSlotCancelled`. Add test ensuring that proofs cannot be marked as missed when a contract is cancelled. --- test/Marketplace.test.js | 14 ++++++++++++++ test/Storage.test.js | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 38b89de..8b9955e 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -357,6 +357,20 @@ describe("Marketplace", function () { await expect(await marketplace.isCancelled(slot.request)).to.equal(true) }) + it("isSlotCancelled fails when slot is empty", async function () { + await expect( + marketplace.isSlotCancelled(slotId(slot)) + ).to.be.revertedWith("Slot empty") + }) + + it("isSlotCancelled is true once request is cancelled", async function () { + await marketplace.fillSlot(slot.request, slot.index, proof) + await waitUntilExpired(request.expiry) + await expect(await marketplace.isSlotCancelled(slotId(slot))).to.equal( + true + ) + }) + it("state is Cancelled when client withdraws funds", async function () { await expect(await marketplace.state(slot.request)).to.equal( RequestState.New diff --git a/test/Storage.test.js b/test/Storage.test.js index a3a76ba..d4de434 100644 --- a/test/Storage.test.js +++ b/test/Storage.test.js @@ -111,6 +111,15 @@ describe("Storage", function () { const expectedBalance = (collateralAmount * (100 - slashPercentage)) / 100 expect(await storage.balanceOf(host.address)).to.equal(expectedBalance) }) + + it("fails to mark proof as missing when cancelled", async function () { + await storage.fillSlot(slot.request, slot.index, proof) + await advanceTimeTo(request.expiry + 1) + let missedPeriod = periodOf(await currentTime()) + await expect( + storage.markProofAsMissing(slotId(slot), missedPeriod) + ).to.be.revertedWith("Request was cancelled") + }) }) })