From 019c1c34c0f399410d660c1bca866c3a91315935 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 18 Jan 2023 15:35:01 +0100 Subject: [PATCH] [marketplace] rewrite slot freeing test To make it independent of values chosen in exampleRequest(). Uses the recently introduced slotState(). --- test/Marketplace.test.js | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 4f2c560..3d56673 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -763,30 +763,18 @@ describe("Marketplace", function () { }) }) - describe("freeing a slot", function () { - it("frees slot when collateral slashed below minimum threshold", async function () { - const id = slotId(slot) - - await waitUntilStarted(marketplace, request, proof) - - const maxSlashes = 10 // slashes before going below collateral minimum - const slashMisses = config.collateral.slashCriterion - for (let i = 0; i < maxSlashes; i++) { - for (let j = 0; j < slashMisses; j++) { - await waitUntilProofIsRequired(id) - let missedPeriod = periodOf(await currentTime()) - await advanceTime(period) - if (i === maxSlashes - 1 && j === slashMisses - 1) { - await expect( - await marketplace.markProofAsMissing(id, missedPeriod) - ).to.emit(marketplace, "SlotFreed") - expect(await marketplace.getHost(id)).to.equal(AddressZero) - } else { - await marketplace.markProofAsMissing(id, missedPeriod) - } - } - } - }) + it("frees slot when collateral slashed below minimum threshold", async function () { + const minimum = config.collateral.minimumAmount + await waitUntilStarted(marketplace, request, proof) + while ((await marketplace.slotState(slotId(slot))) === SlotState.Filled) { + expect(await marketplace.balanceOf(host.address)).to.be.gt(minimum) + await waitUntilProofIsRequired(slotId(slot)) + const missedPeriod = periodOf(await currentTime()) + await advanceTime(period) + await marketplace.markProofAsMissing(slotId(slot), missedPeriod) + } + expect(await marketplace.slotState(slotId(slot))).to.equal(SlotState.Free) + expect(await marketplace.balanceOf(host.address)).to.be.lte(minimum) }) })