mirror of
https://github.com/logos-storage/logos-storage-contracts-eth.git
synced 2026-01-09 08:43:08 +00:00
marketplace: cleanup tests
This commit is contained in:
parent
6bd4144714
commit
6971766b62
@ -273,7 +273,7 @@ describe("Marketplace", function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe("filling a slot with collateral", function () {
|
||||
describe("filling a slot", function () {
|
||||
beforeEach(async function () {
|
||||
switchAccount(client)
|
||||
await token.approve(marketplace.address, maxPrice(request))
|
||||
@ -296,6 +296,15 @@ describe("Marketplace", function () {
|
||||
expect(await marketplace.getHost(slotId(slot))).to.equal(host.address)
|
||||
})
|
||||
|
||||
it("collects only requested collateral and not more", async function () {
|
||||
await token.approve(marketplace.address, collateralPerSlot(request) * 2)
|
||||
const startBalance = await token.balanceOf(host.address)
|
||||
await marketplace.reserveSlot(slot.request, slot.index)
|
||||
await marketplace.fillSlot(slot.request, slot.index, proof)
|
||||
const endBalance = await token.balanceOf(host.address)
|
||||
expect(startBalance - endBalance).to.eq(collateralPerSlot(request))
|
||||
})
|
||||
|
||||
describe("when repairing a slot", function () {
|
||||
beforeEach(async function () {
|
||||
await marketplace.reserveSlot(slot.request, slot.index)
|
||||
@ -411,17 +420,8 @@ describe("Marketplace", function () {
|
||||
marketplace.fillSlot(slot.request, slot.index, proof)
|
||||
).to.be.revertedWith("Marketplace_ReservationRequired")
|
||||
})
|
||||
})
|
||||
|
||||
describe("filling slot without collateral", function () {
|
||||
beforeEach(async function () {
|
||||
switchAccount(client)
|
||||
await token.approve(marketplace.address, maxPrice(request))
|
||||
await marketplace.requestStorage(request)
|
||||
switchAccount(host)
|
||||
})
|
||||
|
||||
it("is rejected when approved collateral is insufficient", async function () {
|
||||
it("fails when approved collateral is insufficient", async function () {
|
||||
let insufficient = collateralPerSlot(request) - 1
|
||||
await token.approve(marketplace.address, insufficient)
|
||||
await marketplace.reserveSlot(slot.request, slot.index)
|
||||
@ -429,15 +429,6 @@ describe("Marketplace", function () {
|
||||
marketplace.fillSlot(slot.request, slot.index, proof)
|
||||
).to.be.revertedWith("ERC20InsufficientAllowance")
|
||||
})
|
||||
|
||||
it("collects only requested collateral and not more", async function () {
|
||||
await token.approve(marketplace.address, collateralPerSlot(request) * 2)
|
||||
const startBalance = await token.balanceOf(host.address)
|
||||
await marketplace.reserveSlot(slot.request, slot.index)
|
||||
await marketplace.fillSlot(slot.request, slot.index, proof)
|
||||
const endBalance = await token.balanceOf(host.address)
|
||||
expect(startBalance - endBalance).to.eq(collateralPerSlot(request))
|
||||
})
|
||||
})
|
||||
|
||||
describe("submitting proofs when slot is filled", function () {
|
||||
@ -1177,38 +1168,34 @@ describe("Marketplace", function () {
|
||||
})
|
||||
|
||||
describe("slashing when missing proofs", function () {
|
||||
it("reduces collateral when a proof is missing", async function () {
|
||||
const id = slotId(slot)
|
||||
const { slashPercentage } = config.collateral
|
||||
const { slashPercentage, validatorRewardPercentage } = config.collateral
|
||||
let id
|
||||
let missedPeriod
|
||||
let collateral
|
||||
let slashAmount
|
||||
|
||||
beforeEach(async function () {
|
||||
collateral = collateralPerSlot(request)
|
||||
slashAmount = Math.round((collateral * slashPercentage) / 100)
|
||||
id = slotId(slot)
|
||||
await marketplace.reserveSlot(slot.request, slot.index)
|
||||
await marketplace.fillSlot(slot.request, slot.index, proof)
|
||||
|
||||
await waitUntilProofIsRequired(id)
|
||||
let missedPeriod = periodOf(await currentTime())
|
||||
missedPeriod = periodOf(await currentTime())
|
||||
await advanceTime(period + 1)
|
||||
})
|
||||
|
||||
it("reduces balance when a proof is missing", async function () {
|
||||
const startBalance = await marketplace.getSlotBalance(id)
|
||||
await setNextBlockTimestamp(await currentTime())
|
||||
await marketplace.markProofAsMissing(id, missedPeriod)
|
||||
const endBalance = await marketplace.getSlotBalance(id)
|
||||
expect(endBalance).to.equal(startBalance - slashAmount)
|
||||
|
||||
const collateral = collateralPerSlot(request)
|
||||
const expectedSlash = Math.round((collateral * slashPercentage) / 100)
|
||||
|
||||
expect(endBalance).to.equal(startBalance - expectedSlash)
|
||||
})
|
||||
|
||||
it("rewards validator when marking proof as missing", async function () {
|
||||
const id = slotId(slot)
|
||||
const { slashPercentage, validatorRewardPercentage } = config.collateral
|
||||
await marketplace.reserveSlot(slot.request, slot.index)
|
||||
await marketplace.fillSlot(slot.request, slot.index, proof)
|
||||
|
||||
switchAccount(validator)
|
||||
|
||||
await waitUntilProofIsRequired(id)
|
||||
let missedPeriod = periodOf(await currentTime())
|
||||
await advanceTime(period + 1)
|
||||
await marketplace.markProofAsMissing(id, missedPeriod)
|
||||
|
||||
const startBalance = await token.balanceOf(validator.address)
|
||||
@ -1216,11 +1203,8 @@ describe("Marketplace", function () {
|
||||
await marketplace.withdrawByValidator(slot.request)
|
||||
const endBalance = await token.balanceOf(validator.address)
|
||||
|
||||
const collateral = collateralPerSlot(request)
|
||||
const slashedAmount = (collateral * slashPercentage) / 100
|
||||
|
||||
const expectedReward = Math.round(
|
||||
(slashedAmount * validatorRewardPercentage) / 100
|
||||
(slashAmount * validatorRewardPercentage) / 100
|
||||
)
|
||||
|
||||
expect(endBalance.toNumber()).to.equal(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user