Fix flaky test

Ensure that when we check whether a proof is required,
the pointer isn't about to wrap.
This commit is contained in:
Mark Spanbroek 2022-03-15 16:53:35 +01:00 committed by markspanbroek
parent 438fb605c0
commit 2a745d7abe

View File

@ -121,21 +121,25 @@ describe("Storage", function () {
;({ periodOf, periodEnd } = periodic(period)) ;({ periodOf, periodEnd } = periodic(period))
}) })
async function ensureProofIsMissing() { async function waitUntilProofIsRequired() {
let currentPeriod = periodOf(await currentTime()) await advanceTimeTo(periodEnd(periodOf(await currentTime())))
await advanceTimeTo(periodEnd(currentPeriod)) while (
while (!(await storage.isProofRequired(id))) { !(
(await storage.isProofRequired(id)) &&
(await storage.getPointer(id)) < 250
)
) {
await advanceTime(period) await advanceTime(period)
} }
let missedPeriod = periodOf(await currentTime())
await advanceTime(period)
await storage.markProofAsMissing(id, missedPeriod)
} }
it("reduces collateral when too many proofs are missing", async function () { it("reduces collateral when too many proofs are missing", async function () {
await storage.connect(host).startContract(id) await storage.connect(host).startContract(id)
for (let i = 0; i < slashMisses; i++) { for (let i = 0; i < slashMisses; i++) {
await ensureProofIsMissing() await waitUntilProofIsRequired()
let missedPeriod = periodOf(await currentTime())
await advanceTime(period)
await storage.markProofAsMissing(id, missedPeriod)
} }
const expectedBalance = (collateralAmount * (100 - slashPercentage)) / 100 const expectedBalance = (collateralAmount * (100 - slashPercentage)) / 100
expect(await storage.balanceOf(host.address)).to.equal(expectedBalance) expect(await storage.balanceOf(host.address)).to.equal(expectedBalance)