diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index f3902e1..153f9a1 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -74,11 +74,11 @@ describe("Marketplace constructor", function () { testPercentageOverflow( "repairRewardPercentage", - "Marketplace_RepairRewardPercentageTooHigh" + "Marketplace_RepairRewardPercentageTooHigh", ) testPercentageOverflow( "slashPercentage", - "Marketplace_SlashPercentageTooHigh" + "Marketplace_SlashPercentageTooHigh", ) it("should reject when total slash percentage exceeds 100%", async () => { @@ -98,7 +98,7 @@ describe("Marketplace constructor", function () { assertDeploymentRejectedWithCustomError( "Marketplace_MaximumSlashingTooHigh", - promise + promise, ) }) }) @@ -147,7 +147,7 @@ describe("Marketplace", function () { configuration: config, }, }, - } + }, ) marketplace = testMarketplace @@ -213,10 +213,10 @@ describe("Marketplace", function () { let invalid = { ...request, client: host.address } await token.approve(await marketplace.getAddress(), maxPrice(invalid)) await expect( - marketplace.requestStorage(invalid) + marketplace.requestStorage(invalid), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_InvalidClientAddress" + "Marketplace_InvalidClientAddress", ) }) @@ -224,13 +224,13 @@ describe("Marketplace", function () { request.ask.duration = config.requestDurationLimit + 1 await token.approve( await marketplace.getAddress(), - collateralPerSlot(request) + collateralPerSlot(request), ) await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_DurationExceedsLimit" + "Marketplace_DurationExceedsLimit", ) }) @@ -238,7 +238,7 @@ describe("Marketplace", function () { let insufficient = maxPrice(request) - 1 await token.approve(await marketplace.getAddress(), insufficient) await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError(token, "ERC20InsufficientAllowance") }) @@ -247,32 +247,32 @@ describe("Marketplace", function () { request.expiry = request.ask.duration + 1 await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError(marketplace, "Marketplace_InvalidExpiry") request.expiry = 0 await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError(marketplace, "Marketplace_InvalidExpiry") }) it("is rejected with insufficient slots ", async function () { request.ask.slots = 0 await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_InsufficientSlots" + "Marketplace_InsufficientSlots", ) }) it("is rejected when maxSlotLoss exceeds slots", async function () { request.ask.maxSlotLoss = request.ask.slots + 1 await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_InvalidMaxSlotLoss" + "Marketplace_InvalidMaxSlotLoss", ) }) @@ -280,60 +280,60 @@ describe("Marketplace", function () { await token.approve(await marketplace.getAddress(), maxPrice(request) * 2) await marketplace.requestStorage(request) await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_RequestAlreadyExists" + "Marketplace_RequestAlreadyExists", ) }) it("is rejected when insufficient duration", async function () { request.ask.duration = 0 await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError( marketplace, // request.expiry has to be > 0 and // request.expiry < request.ask.duration // so request.ask.duration will trigger "Marketplace_InvalidExpiry" - "Marketplace_InvalidExpiry" + "Marketplace_InvalidExpiry", ) }) it("is rejected when insufficient proofProbability", async function () { request.ask.proofProbability = 0 await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_InsufficientProofProbability" + "Marketplace_InsufficientProofProbability", ) }) it("is rejected when insufficient collateral", async function () { request.ask.collateralPerByte = 0 await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_InsufficientCollateral" + "Marketplace_InsufficientCollateral", ) }) it("is rejected when insufficient reward", async function () { request.ask.pricePerBytePerSecond = 0 await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_InsufficientReward" + "Marketplace_InsufficientReward", ) }) it("is rejected when cid is missing", async function () { request.content.cid = Buffer.from("") await expect( - marketplace.requestStorage(request) + marketplace.requestStorage(request), ).to.be.revertedWithCustomError(marketplace, "Marketplace_InvalidCid") }) }) @@ -346,7 +346,7 @@ describe("Marketplace", function () { switchAccount(host) await token.approve( await marketplace.getAddress(), - collateralPerSlot(request) + collateralPerSlot(request), ) }) @@ -362,7 +362,7 @@ describe("Marketplace", function () { await marketplace.reserveSlot(slot.request, slot.index) await marketplace.fillSlot(slot.request, slot.index, proof) expect(await marketplace.getHost(slotId(slot))).to.equal( - await host.getAddress() + await host.getAddress(), ) }) @@ -371,7 +371,7 @@ describe("Marketplace", function () { await marketplace.fillSlot(slot.request, slot.index, proof) await marketplace.freeSlot(slotId(slot)) expect(await marketplace.slotState(slotId(slot))).to.equal( - SlotState.Repair + SlotState.Repair, ) // We need to advance the time to next period, because filling slot @@ -384,7 +384,7 @@ describe("Marketplace", function () { const discountedCollateral = collateral - Math.round( - (collateral * config.collateral.repairRewardPercentage) / 100 + (collateral * config.collateral.repairRewardPercentage) / 100, ) await token.approve(await marketplace.getAddress(), discountedCollateral) await marketplace.reserveSlot(slot.request, slot.index) @@ -392,13 +392,13 @@ describe("Marketplace", function () { const endBalance = await token.balanceOf(host.address) expect(startBalance - endBalance).to.equal(discountedCollateral) expect(await marketplace.slotState(slotId(slot))).to.equal( - SlotState.Filled + SlotState.Filled, ) }) it("fails to retrieve a request of an empty slot", async function () { expect( - marketplace.getActiveSlot(slotId(slot)) + marketplace.getActiveSlot(slotId(slot)), ).to.be.revertedWithCustomError(marketplace, "Marketplace_SlotIsFree") }) @@ -413,7 +413,7 @@ describe("Marketplace", function () { it("is rejected when proof is incorrect", async function () { await marketplace.reserveSlot(slot.request, slot.index) await expect( - marketplace.fillSlot(slot.request, slot.index, invalidProof()) + marketplace.fillSlot(slot.request, slot.index, invalidProof()), ).to.be.revertedWithCustomError(marketplace, "Proofs_InvalidProof") }) @@ -421,14 +421,14 @@ describe("Marketplace", function () { await marketplace.reserveSlot(slot.request, slot.index) await marketplace.fillSlot(slot.request, slot.index, proof) await expect( - marketplace.fillSlot(slot.request, slot.index, proof) + marketplace.fillSlot(slot.request, slot.index, proof), ).to.be.revertedWithCustomError(marketplace, "Marketplace_SlotNotFree") }) it("is rejected when request is unknown", async function () { let unknown = await exampleRequest() await expect( - marketplace.fillSlot(requestId(unknown), 0, proof) + marketplace.fillSlot(requestId(unknown), 0, proof), ).to.be.revertedWithCustomError(marketplace, "Marketplace_UnknownRequest") }) @@ -441,7 +441,7 @@ describe("Marketplace", function () { switchAccount(host) await marketplace.reserveSlot(requestId(expired), slot.index) await expect( - marketplace.fillSlot(requestId(expired), slot.index, proof) + marketplace.fillSlot(requestId(expired), slot.index, proof), ).to.be.revertedWithCustomError(marketplace, "Marketplace_SlotNotFree") }) @@ -449,7 +449,7 @@ describe("Marketplace", function () { await waitUntilStarted(marketplace, request, proof, token) await waitUntilFinished(marketplace, slot.request) await expect( - marketplace.fillSlot(slot.request, slot.index, proof) + marketplace.fillSlot(slot.request, slot.index, proof), ).to.be.revertedWithCustomError(marketplace, "Marketplace_SlotNotFree") }) @@ -457,17 +457,17 @@ describe("Marketplace", function () { await waitUntilStarted(marketplace, request, proof, token) await waitUntilFailed(marketplace, request) await expect( - marketplace.fillSlot(slot.request, slot.index, proof) + marketplace.fillSlot(slot.request, slot.index, proof), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_ReservationRequired" + "Marketplace_ReservationRequired", ) }) it("is rejected when slot index not in range", async function () { const invalid = request.ask.slots await expect( - marketplace.fillSlot(slot.request, invalid, proof) + marketplace.fillSlot(slot.request, invalid, proof), ).to.be.revertedWithCustomError(marketplace, "Marketplace_InvalidSlot") }) @@ -475,27 +475,27 @@ describe("Marketplace", function () { const lastSlot = request.ask.slots - 1 await token.approve( await marketplace.getAddress(), - collateralPerSlot(request) * lastSlot + collateralPerSlot(request) * lastSlot, ) await token.approve( await marketplace.getAddress(), - maxPrice(request) * lastSlot + maxPrice(request) * lastSlot, ) for (let i = 0; i <= lastSlot; i++) { await marketplace.reserveSlot(slot.request, i) await marketplace.fillSlot(slot.request, i, proof) } await expect( - marketplace.fillSlot(slot.request, lastSlot, proof) + marketplace.fillSlot(slot.request, lastSlot, proof), ).to.be.revertedWithCustomError(marketplace, "Marketplace_SlotNotFree") }) it("fails if slot is not reserved first", async function () { await expect( - marketplace.fillSlot(slot.request, slot.index, proof) + marketplace.fillSlot(slot.request, slot.index, proof), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_ReservationRequired" + "Marketplace_ReservationRequired", ) }) }) @@ -513,14 +513,14 @@ describe("Marketplace", function () { await token.approve(await marketplace.getAddress(), insufficient) await marketplace.reserveSlot(slot.request, slot.index) await expect( - marketplace.fillSlot(slot.request, slot.index, proof) + marketplace.fillSlot(slot.request, slot.index, proof), ).to.be.revertedWithCustomError(token, "ERC20InsufficientAllowance") }) it("collects only requested collateral and not more", async function () { await token.approve( await marketplace.getAddress(), - collateralPerSlot(request) * 2 + collateralPerSlot(request) * 2, ) const startBalance = await token.balanceOf(host.address) await marketplace.reserveSlot(slot.request, slot.index) @@ -550,10 +550,10 @@ describe("Marketplace", function () { it("reverts when somebody other then host submit the proof", async function () { switchAccount(host2) await expect( - marketplace.submitProof(slotId(slot), proof) + marketplace.submitProof(slotId(slot), proof), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_ProofNotSubmittedByHost" + "Marketplace_ProofNotSubmittedByHost", ) }) @@ -563,7 +563,7 @@ describe("Marketplace", function () { let littleEndian = new Uint8Array(truncated).reverse() let expected = littleEndianToBigInt(littleEndian) expect(await marketplace.challengeToFieldElement(challenge)).to.equal( - expected + expected, ) }) @@ -572,7 +572,7 @@ describe("Marketplace", function () { let littleEndian = new Uint8Array(merkleRoot).reverse() let expected = littleEndianToBigInt(littleEndian) expect(await marketplace.merkleRootToFieldElement(merkleRoot)).to.equal( - expected + expected, ) }) }) @@ -593,7 +593,7 @@ describe("Marketplace", function () { await marketplace.reserveSlot(slot.request, slot.index) await marketplace.fillSlot(slot.request, slot.index, proof) expect(await marketplace.requestEnd(requestId(request))).to.equal( - requestTime + request.ask.duration + requestTime + request.ask.duration, ) }) @@ -642,7 +642,7 @@ describe("Marketplace", function () { slot.index = 5 let nonExistentId = slotId(slot) await expect( - marketplace.freeSlot(nonExistentId) + marketplace.freeSlot(nonExistentId), ).to.be.revertedWithCustomError(marketplace, "Marketplace_SlotIsFree") }) @@ -651,7 +651,7 @@ describe("Marketplace", function () { switchAccount(client) await expect(marketplace.freeSlot(id)).to.be.revertedWithCustomError( marketplace, - "Marketplace_InvalidSlotHost" + "Marketplace_InvalidSlotHost", ) }) @@ -711,7 +711,7 @@ describe("Marketplace", function () { marketplace, request, proof, - token + token, ) await waitUntilFinished(marketplace, requestId(request)) @@ -723,7 +723,7 @@ describe("Marketplace", function () { expect(expectedPayouts[slot.index]).to.be.lt(maxPrice(request)) const collateral = collateralPerSlot(request) expect(endBalanceHost - startBalanceHost).to.equal( - expectedPayouts[slot.index] + collateral + expectedPayouts[slot.index] + collateral, ) }) @@ -733,27 +733,27 @@ describe("Marketplace", function () { const startBalanceHost = await token.balanceOf(host.address) const startBalanceCollateral = await token.balanceOf( - hostCollateralRecipient.address + hostCollateralRecipient.address, ) const collateralToBeReturned = await marketplace.currentCollateral( - slotId(slot) + slotId(slot), ) await marketplace.freeSlot( slotId(slot), hostRewardRecipient.address, - hostCollateralRecipient.address + hostCollateralRecipient.address, ) const endBalanceCollateral = await token.balanceOf( - hostCollateralRecipient.address + hostCollateralRecipient.address, ) const endBalanceHost = await token.balanceOf(host.address) expect(endBalanceHost).to.equal(startBalanceHost) expect(endBalanceCollateral - startBalanceCollateral).to.equal( - collateralPerSlot(request) + collateralPerSlot(request), ) expect(collateralToBeReturned).to.equal(collateralPerSlot(request)) }) @@ -764,18 +764,18 @@ describe("Marketplace", function () { const startBalanceHost = await token.balanceOf(host.address) const startBalanceReward = await token.balanceOf( - hostRewardRecipient.address + hostRewardRecipient.address, ) await marketplace.freeSlot( slotId(slot), hostRewardRecipient.address, - hostCollateralRecipient.address + hostCollateralRecipient.address, ) const endBalanceHost = await token.balanceOf(host.address) const endBalanceReward = await token.balanceOf( - hostRewardRecipient.address + hostRewardRecipient.address, ) expect(endBalanceHost).to.equal(startBalanceHost) @@ -798,7 +798,7 @@ describe("Marketplace", function () { const expectedPartialPayout = calculatePartialPayout( request, expiresAt, - filledAt + filledAt, ) const endBalance = await token.balanceOf(host.address) @@ -817,43 +817,43 @@ describe("Marketplace", function () { await waitUntilCancelled(marketplace, request) const startBalanceHost = await token.balanceOf(host.address) const startBalanceReward = await token.balanceOf( - hostRewardRecipient.address + hostRewardRecipient.address, ) const startBalanceCollateral = await token.balanceOf( - hostCollateralRecipient.address + hostCollateralRecipient.address, ) const collateralToBeReturned = await marketplace.currentCollateral( - slotId(slot) + slotId(slot), ) await marketplace.freeSlot( slotId(slot), hostRewardRecipient.address, - hostCollateralRecipient.address + hostCollateralRecipient.address, ) const expectedPartialPayout = calculatePartialPayout( request, expiresAt, - filledAt + filledAt, ) const endBalanceReward = await token.balanceOf( - hostRewardRecipient.address + hostRewardRecipient.address, ) expect(endBalanceReward - startBalanceReward).to.be.equal( - expectedPartialPayout + expectedPartialPayout, ) const endBalanceHost = await token.balanceOf(host.address) expect(endBalanceHost).to.be.equal(startBalanceHost) const endBalanceCollateral = await token.balanceOf( - hostCollateralRecipient.address + hostCollateralRecipient.address, ) expect(endBalanceCollateral - startBalanceCollateral).to.be.equal( - collateralPerSlot(request) + collateralPerSlot(request), ) expect(collateralToBeReturned).to.be.equal(collateralPerSlot(request)) @@ -864,18 +864,18 @@ describe("Marketplace", function () { await marketplace.fillSlot(slot.request, slot.index, proof) const startBalanceHost = await token.balanceOf(host.address) const startBalanceReward = await token.balanceOf( - hostRewardRecipient.address + hostRewardRecipient.address, ) const startBalanceCollateral = await token.balanceOf( - hostCollateralRecipient.address + hostCollateralRecipient.address, ) await marketplace.freeSlot(slotId(slot)) const endBalanceHost = await token.balanceOf(host.address) const endBalanceReward = await token.balanceOf( - hostRewardRecipient.address + hostRewardRecipient.address, ) const endBalanceCollateral = await token.balanceOf( - hostCollateralRecipient.address + hostCollateralRecipient.address, ) expect(endBalanceHost).to.equal(startBalanceHost) expect(endBalanceReward).to.equal(startBalanceReward) @@ -887,7 +887,7 @@ describe("Marketplace", function () { await waitUntilFinished(marketplace, requestId(request)) await marketplace.freeSlot(slotId(slot)) await expect( - marketplace.freeSlot(slotId(slot)) + marketplace.freeSlot(slotId(slot)), ).to.be.revertedWithCustomError(marketplace, "Marketplace_AlreadyPaid") }) @@ -914,7 +914,7 @@ describe("Marketplace", function () { const lastSlot = request.ask.slots - 1 await token.approve( await marketplace.getAddress(), - collateralPerSlot(request) * lastSlot + collateralPerSlot(request) * lastSlot, ) for (let i = 0; i < lastSlot; i++) { await marketplace.reserveSlot(slot.request, i) @@ -937,21 +937,21 @@ describe("Marketplace", function () { await marketplace.fillSlot(slot.request, i, proof) } expect(await marketplace.requestState(slot.request)).to.equal( - RequestState.Started + RequestState.Started, ) }) it("fails when all slots are already filled", async function () { const lastSlot = request.ask.slots - 1 await token.approve( await marketplace.getAddress(), - collateralPerSlot(request) * (lastSlot + 1) + collateralPerSlot(request) * (lastSlot + 1), ) for (let i = 0; i <= lastSlot; i++) { await marketplace.reserveSlot(slot.request, i) await marketplace.fillSlot(slot.request, i, proof) } await expect( - marketplace.fillSlot(slot.request, lastSlot, proof) + marketplace.fillSlot(slot.request, lastSlot, proof), ).to.be.revertedWithCustomError(marketplace, "Marketplace_SlotNotFree") }) }) @@ -973,17 +973,23 @@ describe("Marketplace", function () { it("rejects withdraw when request not yet timed out", async function () { switchAccount(client) await expect( - marketplace.withdrawFunds(slot.request, clientWithdrawRecipient.address) + marketplace.withdrawFunds( + slot.request, + clientWithdrawRecipient.address, + ), ).to.be.revertedWithCustomError(marketplace, "Marketplace_InvalidState") }) it("rejects withdraw when wrong account used", async function () { await waitUntilCancelled(marketplace, request) await expect( - marketplace.withdrawFunds(slot.request, clientWithdrawRecipient.address) + marketplace.withdrawFunds( + slot.request, + clientWithdrawRecipient.address, + ), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_InvalidClientAddress" + "Marketplace_InvalidClientAddress", ) }) @@ -992,7 +998,7 @@ describe("Marketplace", function () { const lastSlot = request.ask.slots - 1 await token.approve( await marketplace.getAddress(), - collateralPerSlot(request) * (lastSlot + 1) + collateralPerSlot(request) * (lastSlot + 1), ) for (let i = 0; i <= lastSlot; i++) { await marketplace.reserveSlot(slot.request, i) @@ -1001,7 +1007,10 @@ describe("Marketplace", function () { await waitUntilCancelled(marketplace, request) switchAccount(client) await expect( - marketplace.withdrawFunds(slot.request, clientWithdrawRecipient.address) + marketplace.withdrawFunds( + slot.request, + clientWithdrawRecipient.address, + ), ).to.be.revertedWithCustomError(marketplace, "Marketplace_InvalidState") }) @@ -1012,13 +1021,16 @@ describe("Marketplace", function () { switchAccount(client) await marketplace.withdrawFunds( slot.request, - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) await expect( - marketplace.withdrawFunds(slot.request, clientWithdrawRecipient.address) + marketplace.withdrawFunds( + slot.request, + clientWithdrawRecipient.address, + ), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_NothingToWithdraw" + "Marketplace_NothingToWithdraw", ) }) @@ -1026,7 +1038,10 @@ describe("Marketplace", function () { await waitUntilCancelled(marketplace, request) switchAccount(client) await expect( - marketplace.withdrawFunds(slot.request, clientWithdrawRecipient.address) + marketplace.withdrawFunds( + slot.request, + clientWithdrawRecipient.address, + ), ) .to.emit(marketplace, "RequestCancelled") .withArgs(requestId(request)) @@ -1039,16 +1054,16 @@ describe("Marketplace", function () { switchAccount(client) const startBalanceClient = await token.balanceOf(client.address) const startBalancePayout = await token.balanceOf( - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) await marketplace.withdrawFunds( slot.request, - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) const endBalanceClient = await token.balanceOf(client.address) const endBalancePayout = await token.balanceOf( - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) expect(endBalanceClient).to.equal(startBalanceClient) @@ -1058,7 +1073,7 @@ describe("Marketplace", function () { // at the time of expiry and hence the user would get the full "expiry window" reward back. expect(endBalancePayout - startBalancePayout).to.be.gt(0) expect(endBalancePayout - startBalancePayout).to.be.lte( - request.expiry * pricePerSlotPerSecond(request) + request.expiry * pricePerSlotPerSecond(request), ) }) @@ -1067,15 +1082,15 @@ describe("Marketplace", function () { switchAccount(client) const startBalanceClient = await token.balanceOf(client.address) const startBalancePayout = await token.balanceOf( - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) await marketplace.withdrawFunds( slot.request, - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) const endBalanceClient = await token.balanceOf(client.address) const endBalancePayout = await token.balanceOf( - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) expect(endBalanceClient).to.equal(startBalanceClient) expect(endBalancePayout - startBalancePayout).to.equal(maxPrice(request)) @@ -1089,16 +1104,16 @@ describe("Marketplace", function () { const startBalanceClient = await token.balanceOf(client.address) const startBalancePayout = await token.balanceOf( - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) await marketplace.withdrawFunds( slot.request, - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) const endBalanceClient = await token.balanceOf(client.address) const endBalancePayout = await token.balanceOf( - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) expect(endBalanceClient).to.equal(startBalanceClient) @@ -1120,17 +1135,17 @@ describe("Marketplace", function () { const expectedPartialhostRewardRecipient = calculatePartialPayout( request, expiresAt, - filledAt + filledAt, ) switchAccount(client) await marketplace.withdrawFunds( slot.request, - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) const endBalance = await token.balanceOf(clientWithdrawRecipient.address) expect(endBalance - startBalance).to.equal( - maxPrice(request) - expectedPartialhostRewardRecipient + maxPrice(request) - expectedPartialhostRewardRecipient, ) }) @@ -1140,20 +1155,20 @@ describe("Marketplace", function () { await expect(marketplace.freeSlot(slotId(slot))).to.emit( marketplace, - "SlotFreed" + "SlotFreed", ) await waitUntilFinished(marketplace, requestId(request)) switchAccount(client) await marketplace.withdrawFunds( slot.request, - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) const endBalance = await token.balanceOf(clientWithdrawRecipient.address) expect(endBalance - startBalance).to.equal( maxPrice(request) - payouts.reduce((a, b) => a + b, 0) + // This is the amount that user gets refunded for filling period in expiry window - payouts[slot.index] // This is the refunded amount for the freed slot + payouts[slot.index], // This is the refunded amount for the freed slot ) }) }) @@ -1184,7 +1199,7 @@ describe("Marketplace", function () { switchAccount(client) await marketplace.withdrawFunds( slot.request, - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) expect(await marketplace.requestState(slot.request)).to.equal(Cancelled) }) @@ -1203,7 +1218,7 @@ describe("Marketplace", function () { it("does not change to 'Failed' before it is started", async function () { await token.approve( await marketplace.getAddress(), - collateralPerSlot(request) * (request.ask.maxSlotLoss + 1) + collateralPerSlot(request) * (request.ask.maxSlotLoss + 1), ) for (let i = 0; i <= request.ask.maxSlotLoss; i++) { await marketplace.reserveSlot(slot.request, i) @@ -1334,7 +1349,7 @@ describe("Marketplace", function () { // 4 * (256 - 64) / 256 const expectedProbability = 3 expect(await marketplace.slotProbability(slotId(slot))).to.equal( - expectedProbability + expectedProbability, ) }) }) @@ -1457,10 +1472,10 @@ describe("Marketplace", function () { await waitUntilCancelled(marketplace, request) let missedPeriod = periodOf(await currentTime()) await expect( - marketplace.markProofAsMissing(slotId(slot), missedPeriod) + marketplace.markProofAsMissing(slotId(slot), missedPeriod), ).to.be.revertedWithCustomError( marketplace, - "Marketplace_SlotNotAcceptingProofs" + "Marketplace_SlotNotAcceptingProofs", ) }) @@ -1478,7 +1493,7 @@ describe("Marketplace", function () { const collateral = collateralPerSlot(request) const expectedBalance = Math.round( - (collateral * (100 - slashPercentage)) / 100 + (collateral * (100 - slashPercentage)) / 100, ) expect(expectedBalance == (await marketplace.getSlotCollateral(id))) @@ -1505,11 +1520,11 @@ describe("Marketplace", function () { const slashedAmount = (collateral * slashPercentage) / 100 const expectedReward = Math.round( - (slashedAmount * validatorRewardPercentage) / 100 + (slashedAmount * validatorRewardPercentage) / 100, ) expect(endBalance).to.equal( - calculateBalance(startBalance, expectedReward) + calculateBalance(startBalance, expectedReward), ) }) }) @@ -1525,7 +1540,7 @@ describe("Marketplace", function () { await waitUntilStarted(marketplace, request, proof, token) while ((await marketplace.slotState(slotId(slot))) === SlotState.Filled) { expect(await marketplace.getSlotCollateral(slotId(slot))).to.be.gt( - minimum + minimum, ) await waitUntilProofIsRequired(slotId(slot)) const missedPeriod = periodOf(await currentTime()) @@ -1533,10 +1548,10 @@ describe("Marketplace", function () { await marketplace.markProofAsMissing(slotId(slot), missedPeriod) } expect(await marketplace.slotState(slotId(slot))).to.equal( - SlotState.Repair + SlotState.Repair, ) expect(await marketplace.getSlotCollateral(slotId(slot))).to.be.lte( - minimum + minimum, ) }) @@ -1552,23 +1567,23 @@ describe("Marketplace", function () { let missedProofs = 0 while ((await marketplace.slotState(slotId(slot))) === SlotState.Filled) { expect(await marketplace.getSlotCollateral(slotId(slot))).to.be.gt( - minimum + minimum, ) await waitUntilProofIsRequired(slotId(slot)) const missedPeriod = periodOf(await currentTime()) await advanceTime(period + 1) expect(await marketplace.missingProofs(slotId(slot))).to.equal( - missedProofs + missedProofs, ) await marketplace.markProofAsMissing(slotId(slot), missedPeriod) missedProofs += 1 } expect(await marketplace.slotState(slotId(slot))).to.equal( - SlotState.Repair + SlotState.Repair, ) expect(await marketplace.missingProofs(slotId(slot))).to.equal(0) expect(await marketplace.getSlotCollateral(slotId(slot))).to.be.lte( - minimum + minimum, ) }) }) @@ -1598,7 +1613,7 @@ describe("Marketplace", function () { await waitUntilCancelled(marketplace, request) await marketplace.withdrawFunds( requestId(request), - clientWithdrawRecipient.address + clientWithdrawRecipient.address, ) expect(await marketplace.myRequests()).to.deep.equal([]) }) diff --git a/test/Vault.tests.js b/test/Vault.tests.js index df3a0f5..12330f8 100644 --- a/test/Vault.tests.js +++ b/test/Vault.tests.js @@ -26,7 +26,7 @@ describe("Vault", function () { const { vault: _vault, token: _token } = await ignition.deploy( VaultModule, - {} + {}, ) vault = _vault token = _token @@ -62,7 +62,7 @@ describe("Vault", function () { beforeEach(async function () { account = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) }) @@ -86,7 +86,7 @@ describe("Vault", function () { const locking = vault.lock(fund, maximum + 1, maximum) await expect(locking).to.be.revertedWithCustomError( vault, - "VaultInvalidExpiry" + "VaultInvalidExpiry", ) }) @@ -106,7 +106,7 @@ describe("Vault", function () { maximum = beginning + 100 account = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) await setAutomine(false) await setNextBlockTimestamp(beginning) @@ -120,7 +120,7 @@ describe("Vault", function () { it("cannot set lock when already locked", async function () { await expect( - vault.lock(fund, expiry, maximum) + vault.lock(fund, expiry, maximum), ).to.be.revertedWithCustomError(vault, "VaultFundAlreadyLocked") }) @@ -135,7 +135,7 @@ describe("Vault", function () { const extending = vault.extendLock(fund, maximum + 1) await expect(extending).to.be.revertedWithCustomError( vault, - "VaultInvalidExpiry" + "VaultInvalidExpiry", ) }) @@ -143,7 +143,7 @@ describe("Vault", function () { const extending = vault.extendLock(fund, expiry - 1) await expect(extending).to.be.revertedWithCustomError( vault, - "VaultInvalidExpiry" + "VaultInvalidExpiry", ) }) @@ -164,7 +164,7 @@ describe("Vault", function () { beforeEach(async function () { account = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) await setAutomine(true) }) @@ -193,7 +193,7 @@ describe("Vault", function () { const depositing = vault.deposit(fund, account, amount) await expect(depositing).to.be.revertedWithCustomError( token, - "ERC20InsufficientAllowance" + "ERC20InsufficientAllowance", ) }) @@ -256,11 +256,11 @@ describe("Vault", function () { beforeEach(async function () { account = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) account2 = await vault.encodeAccountId( await holder2.getAddress(), - randomBytes(12) + randomBytes(12), ) await token .connect(controller) @@ -297,7 +297,7 @@ describe("Vault", function () { await setAutomine(true) await vault.designate(fund, account, amount) await expect( - vault.designate(fund, account, 1) + vault.designate(fund, account, 1), ).to.be.revertedWithCustomError(vault, "VaultInsufficientBalance") }) @@ -308,7 +308,7 @@ describe("Vault", function () { const designating = vault.designate(fund, account, 1) await expect(designating).to.be.revertedWithCustomError( vault, - "VaultInsufficientBalance" + "VaultInsufficientBalance", ) }) }) @@ -321,15 +321,15 @@ describe("Vault", function () { beforeEach(async function () { account1 = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) account2 = await vault.encodeAccountId( await holder2.getAddress(), - randomBytes(12) + randomBytes(12), ) account3 = await vault.encodeAccountId( await holder3.getAddress(), - randomBytes(12) + randomBytes(12), ) await token .connect(controller) @@ -368,7 +368,7 @@ describe("Vault", function () { it("does not transfer more than the balance", async function () { await setAutomine(true) await expect( - vault.transfer(fund, account1, account2, amount + 1) + vault.transfer(fund, account1, account2, amount + 1), ).to.be.revertedWithCustomError(vault, "VaultInsufficientBalance") }) @@ -376,7 +376,7 @@ describe("Vault", function () { await setAutomine(true) await vault.designate(fund, account1, 1) await expect( - vault.transfer(fund, account1, account2, amount) + vault.transfer(fund, account1, account2, amount), ).to.be.revertedWithCustomError(vault, "VaultInsufficientBalance") }) @@ -385,7 +385,7 @@ describe("Vault", function () { setAutomine(true) await vault.transfer(fund, account1, account2, 500) await expect( - vault.transfer(fund, account1, account2, 1) + vault.transfer(fund, account1, account2, 1), ).to.be.revertedWithCustomError(vault, "VaultInsufficientBalance") }) }) @@ -398,15 +398,15 @@ describe("Vault", function () { beforeEach(async function () { account1 = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) account2 = await vault.encodeAccountId( await holder2.getAddress(), - randomBytes(12) + randomBytes(12), ) account3 = await vault.encodeAccountId( await holder3.getAddress(), - randomBytes(12) + randomBytes(12), ) await token .connect(controller) @@ -545,7 +545,7 @@ describe("Vault", function () { it("rejects flow when insufficient available tokens", async function () { setAutomine(true) await expect( - vault.flow(fund, account1, account2, 11) + vault.flow(fund, account1, account2, 11), ).to.be.revertedWithCustomError(vault, "VaultInsufficientBalance") }) @@ -553,7 +553,7 @@ describe("Vault", function () { await vault.flow(fund, account1, account2, 10) setAutomine(true) await expect( - vault.flow(fund, account1, account2, 1) + vault.flow(fund, account1, account2, 1), ).to.be.revertedWithCustomError(vault, "VaultInsufficientBalance") }) @@ -562,7 +562,7 @@ describe("Vault", function () { await vault.flow(fund, account1, account2, 5) setAutomine(true) await expect( - vault.flow(fund, account1, account2, 1) + vault.flow(fund, account1, account2, 1), ).to.be.revertedWithCustomError(vault, "VaultInsufficientBalance") }) }) @@ -576,15 +576,15 @@ describe("Vault", function () { beforeEach(async function () { account1 = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) account2 = await vault.encodeAccountId( await holder2.getAddress(), - randomBytes(12) + randomBytes(12), ) account3 = await vault.encodeAccountId( await holder3.getAddress(), - randomBytes(12) + randomBytes(12), ) await setAutomine(true) await token @@ -603,7 +603,7 @@ describe("Vault", function () { it("burns a number of designated tokens", async function () { await vault.burnDesignated(fund, account1, 10) expect(await vault.getDesignatedBalance(fund, account1)).to.equal( - designated - 10 + designated - 10, ) expect(await vault.getBalance(fund, account1)).to.equal(amount - 10) }) @@ -612,7 +612,7 @@ describe("Vault", function () { await vault.burnDesignated(fund, account1, designated) expect(await vault.getDesignatedBalance(fund, account1)).to.equal(0) expect(await vault.getBalance(fund, account1)).to.equal( - amount - designated + amount - designated, ) }) @@ -631,7 +631,7 @@ describe("Vault", function () { it("cannot burn more than all designated tokens", async function () { await expect( - vault.burnDesignated(fund, account1, designated + 1) + vault.burnDesignated(fund, account1, designated + 1), ).to.be.revertedWithCustomError(vault, "VaultInsufficientBalance") }) }) @@ -659,7 +659,7 @@ describe("Vault", function () { it("does not burn tokens from other accounts with the same holder", async function () { const account1a = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) await vault.transfer(fund, account1, account1a, 10) await vault.burnAccount(fund, account1) @@ -671,12 +671,12 @@ describe("Vault", function () { const burning1 = vault.burnAccount(fund, account1) await expect(burning1).to.be.revertedWithCustomError( vault, - "VaultFlowNotZero" + "VaultFlowNotZero", ) const burning2 = vault.burnAccount(fund, account2) await expect(burning2).to.be.revertedWithCustomError( vault, - "VaultFlowNotZero" + "VaultFlowNotZero", ) }) @@ -696,15 +696,15 @@ describe("Vault", function () { beforeEach(async function () { account1 = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) account2 = await vault.encodeAccountId( await holder2.getAddress(), - randomBytes(12) + randomBytes(12), ) account3 = await vault.encodeAccountId( await holder3.getAddress(), - randomBytes(12) + randomBytes(12), ) await token.approve(await vault.getAddress(), deposit) await vault.deposit(fund, account1, deposit) @@ -741,11 +741,11 @@ describe("Vault", function () { beforeEach(async function () { account1 = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) account2 = await vault.encodeAccountId( await holder2.getAddress(), - randomBytes(12) + randomBytes(12), ) await setAutomine(true) await token @@ -759,7 +759,7 @@ describe("Vault", function () { const withdrawing = vault.withdraw(fund, account1) await expect(withdrawing).to.be.revertedWithCustomError( vault, - "VaultFundNotUnlocked" + "VaultFundNotUnlocked", ) }) @@ -769,11 +769,11 @@ describe("Vault", function () { let withdrawing2 = vault.withdraw(fund, account2) await expect(withdrawing1).to.be.revertedWithCustomError( vault, - "VaultFundNotUnlocked" + "VaultFundNotUnlocked", ) await expect(withdrawing2).to.be.revertedWithCustomError( vault, - "VaultFundNotUnlocked" + "VaultFundNotUnlocked", ) }) }) @@ -790,15 +790,15 @@ describe("Vault", function () { maximum = beginning + 100 account1 = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) account2 = await vault.encodeAccountId( await holder2.getAddress(), - randomBytes(12) + randomBytes(12), ) account3 = await vault.encodeAccountId( await holder3.getAddress(), - randomBytes(12) + randomBytes(12), ) await setAutomine(false) await setNextBlockTimestamp(beginning) @@ -827,7 +827,7 @@ describe("Vault", function () { const locking = vault.lock(fund, expiry, maximum) await expect(locking).to.be.revertedWithCustomError( vault, - "VaultFundAlreadyLocked" + "VaultFundAlreadyLocked", ) }) @@ -880,17 +880,17 @@ describe("Vault", function () { it("allows flowing tokens to be withdrawn", async function () { const balance1Before = await token.balanceOf( - await holder.getAddress() + await holder.getAddress(), ) const balance2Before = await token.balanceOf( - await holder2.getAddress() + await holder2.getAddress(), ) await vault.withdraw(fund, account1) await vault.withdraw(fund, account2) await mine() const balance1After = await token.balanceOf(await holder.getAddress()) const balance2After = await token.balanceOf( - await holder2.getAddress() + await holder2.getAddress(), ) expect(balance1After - balance1Before).to.equal(deposit - total) expect(balance2After - balance2Before).to.equal(total) @@ -973,7 +973,7 @@ describe("Vault", function () { await expect( vault .connect(holder2) - .withdrawByRecipient(await controller.getAddress(), fund, account1) + .withdrawByRecipient(await controller.getAddress(), fund, account1), ).to.be.revertedWithCustomError(vault, "VaultOnlyAccountHolder") }) @@ -986,7 +986,7 @@ describe("Vault", function () { it("does not withdraw other accounts from the same holder", async function () { const account1a = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) await vault.transfer(fund, account1, account1a, 10) await expire() @@ -1070,7 +1070,7 @@ describe("Vault", function () { expiry = (await currentTime()) + 100 account = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) await token.connect(controller).approve(await vault.getAddress(), amount) await vault.lock(fund, expiry, expiry) @@ -1082,7 +1082,7 @@ describe("Vault", function () { const locking = vault.lock(fund, expiry, expiry) await expect(locking).to.be.revertedWithCustomError( vault, - "VaultFundAlreadyLocked" + "VaultFundAlreadyLocked", ) }) @@ -1090,7 +1090,7 @@ describe("Vault", function () { const withdrawing = vault.withdraw(fund, account) await expect(withdrawing).to.be.revertedWithCustomError( vault, - "VaultFundNotUnlocked" + "VaultFundNotUnlocked", ) }) @@ -1108,17 +1108,17 @@ describe("Vault", function () { beforeEach(async function () { account = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) account2 = await vault.encodeAccountId( await holder2.getAddress(), - randomBytes(12) + randomBytes(12), ) }) it("does not allow extending of lock", async function () { await expect( - vault.extendLock(fund, (await currentTime()) + 1) + vault.extendLock(fund, (await currentTime()) + 1), ).to.be.revertedWithCustomError(vault, "VaultFundNotLocked") }) @@ -1126,44 +1126,44 @@ describe("Vault", function () { const amount = 1000 await token.connect(controller).approve(await vault.getAddress(), amount) await expect( - vault.deposit(fund, account, amount) + vault.deposit(fund, account, amount), ).to.be.revertedWithCustomError(vault, "VaultFundNotLocked") }) it("does not allow designating tokens", async function () { await expect( - vault.designate(fund, account, 0) + vault.designate(fund, account, 0), ).to.be.revertedWithCustomError(vault, "VaultFundNotLocked") }) it("does not allow transfer of tokens", async function () { await expect( - vault.transfer(fund, account, account2, 0) + vault.transfer(fund, account, account2, 0), ).to.be.revertedWithCustomError(vault, "VaultFundNotLocked") }) it("does not allow new token flows to start", async function () { await expect( - vault.flow(fund, account, account2, 0) + vault.flow(fund, account, account2, 0), ).to.be.revertedWithCustomError(vault, "VaultFundNotLocked") }) it("does not allow burning of designated tokens", async function () { await expect( - vault.burnDesignated(fund, account, 1) + vault.burnDesignated(fund, account, 1), ).to.be.revertedWithCustomError(vault, "VaultFundNotLocked") }) it("does not allow burning of accounts", async function () { await expect( - vault.burnAccount(fund, account) + vault.burnAccount(fund, account), ).to.be.revertedWithCustomError(vault, "VaultFundNotLocked") }) it("does not allow freezing of a fund", async function () { await expect(vault.freezeFund(fund)).to.be.revertedWithCustomError( vault, - "VaultFundNotLocked" + "VaultFundNotLocked", ) }) } @@ -1189,14 +1189,14 @@ describe("Vault", function () { it("does not allow pause to be called by others", async function () { await expect(vault.connect(other).pause()).to.be.revertedWithCustomError( vault, - "OwnableUnauthorizedAccount" + "OwnableUnauthorizedAccount", ) }) it("does not allow unpause to be called by others", async function () { await vault.connect(owner).pause() await expect( - vault.connect(other).unpause() + vault.connect(other).unpause(), ).to.be.revertedWithCustomError(vault, "OwnableUnauthorizedAccount") }) @@ -1210,7 +1210,7 @@ describe("Vault", function () { await vault.connect(owner).renounceOwnership() await expect(vault.connect(owner).pause()).to.be.revertedWithCustomError( vault, - "OwnableUnauthorizedAccount" + "OwnableUnauthorizedAccount", ) }) @@ -1224,11 +1224,11 @@ describe("Vault", function () { maximum = (await currentTime()) + 100 account1 = await vault.encodeAccountId( await holder.getAddress(), - randomBytes(12) + randomBytes(12), ) account2 = await vault.encodeAccountId( await holder2.getAddress(), - randomBytes(12) + randomBytes(12), ) await vault.lock(fund, expiry, maximum) await token.approve(await vault.getAddress(), 1000) @@ -1242,7 +1242,7 @@ describe("Vault", function () { await expect( vault .connect(holder) - .withdrawByRecipient(await controller.getAddress(), fund, account1) + .withdrawByRecipient(await controller.getAddress(), fund, account1), ).not.to.be.reverted }) @@ -1250,64 +1250,64 @@ describe("Vault", function () { const fund = randomBytes(32) const expiry = (await currentTime()) + 100 await expect( - vault.lock(fund, expiry, expiry) + vault.lock(fund, expiry, expiry), ).to.be.revertedWithCustomError(vault, "EnforcedPause") }) it("does not allow extending of lock", async function () { await expect( - vault.extendLock(fund, maximum) + vault.extendLock(fund, maximum), ).to.be.revertedWithCustomError(vault, "EnforcedPause") }) it("does not allow depositing of tokens", async function () { await token.approve(await vault.getAddress(), 100) await expect( - vault.deposit(fund, account1, 100) + vault.deposit(fund, account1, 100), ).to.be.revertedWithCustomError(vault, "EnforcedPause") }) it("does not allow designating tokens", async function () { await expect( - vault.designate(fund, account1, 10) + vault.designate(fund, account1, 10), ).to.be.revertedWithCustomError(vault, "EnforcedPause") }) it("does not allow transfer of tokens", async function () { await expect( - vault.transfer(fund, account1, account2, 10) + vault.transfer(fund, account1, account2, 10), ).to.be.revertedWithCustomError(vault, "EnforcedPause") }) it("does not allow new token flows to start", async function () { await expect( - vault.flow(fund, account1, account2, 1) + vault.flow(fund, account1, account2, 1), ).to.be.revertedWithCustomError(vault, "EnforcedPause") }) it("does not allow burning of designated tokens", async function () { await expect( - vault.burnDesignated(fund, account1, 10) + vault.burnDesignated(fund, account1, 10), ).to.be.revertedWithCustomError(vault, "EnforcedPause") }) it("does not allow burning of accounts", async function () { await expect( - vault.burnAccount(fund, account1) + vault.burnAccount(fund, account1), ).to.be.revertedWithCustomError(vault, "EnforcedPause") }) it("does not allow freezing of funds", async function () { await expect(vault.freezeFund(fund)).to.be.revertedWithCustomError( vault, - "EnforcedPause" + "EnforcedPause", ) }) it("does not allow a controller to withdraw for a recipient", async function () { await advanceTimeTo(expiry) await expect( - vault.withdraw(fund, account1) + vault.withdraw(fund, account1), ).to.be.revertedWithCustomError(vault, "EnforcedPause") }) })