diff --git a/test/Collateral.test.js b/test/Collateral.test.js index 2e6669c..8000a7e 100644 --- a/test/Collateral.test.js +++ b/test/Collateral.test.js @@ -1,5 +1,4 @@ const { expect } = require("chai") -const { exampleLock } = require("./examples") describe("Collateral", function () { let collateral, token @@ -90,25 +89,4 @@ describe("Collateral", function () { expect(await collateral.balanceOf(account1.address)).to.equal(950) }) }) - - describe("locking", function () { - let lock - - beforeEach(async function () { - await token.approve(collateral.address, 42) - await collateral.deposit(42) - lock = await exampleLock() - await collateral.createLock(lock.id, lock.expiry) - await collateral.lock(account0.address, lock.id) - }) - - it("withdrawal fails when account is locked", async function () { - await expect(collateral.withdraw()).to.be.revertedWith("Account locked") - }) - - it("withdrawal succeeds when account is unlocked", async function () { - await collateral.unlock(lock.id) - await expect(collateral.withdraw()).not.to.be.reverted - }) - }) }) diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 9a27715..1302013 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -126,11 +126,6 @@ describe("Marketplace", function () { .withArgs(slot.request, slot.index, slotId(slot)) }) - it("locks collateral of host", async function () { - await marketplace.fillSlot(slot.request, slot.index, proof) - await expect(marketplace.withdraw()).to.be.revertedWith("Account locked") - }) - it("starts requiring storage proofs", async function () { await marketplace.fillSlot(slot.request, slot.index, proof) expect(await marketplace.proofEnd(slotId(slot))).to.be.gt(0) @@ -535,6 +530,34 @@ describe("Marketplace", function () { }) }) + describe("collateral locking", function () { + beforeEach(async function () { + 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("locks collateral of host when it fills a slot", async function () { + await marketplace.fillSlot(slot.request, slot.index, proof) + await expect(marketplace.withdraw()).to.be.revertedWith("Account locked") + }) + + it("allows withdrawal when all slots are free", async function () { + let slot1 = { ...slot, index: 0 } + let slot2 = { ...slot, index: 1 } + await marketplace.fillSlot(slot1.request, slot1.index, proof) + await marketplace.fillSlot(slot2.request, slot2.index, proof) + await waitUntilFinished(marketplace, requestId(request)) + await marketplace.freeSlot(slotId(slot1)) + await expect(marketplace.withdraw()).to.be.revertedWith("Account locked") + await marketplace.freeSlot(slotId(slot2)) + await expect(marketplace.withdraw()).not.to.be.reverted + }) + }) + describe("contract state", function () { beforeEach(async function () { switchAccount(client)