From 2a745d7abefcae8dd9ab52c2e08d40ae0ff83e6a Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 15 Mar 2022 16:53:35 +0100 Subject: [PATCH] Fix flaky test Ensure that when we check whether a proof is required, the pointer isn't about to wrap. --- test/Storage.test.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/Storage.test.js b/test/Storage.test.js index 59caebe..a9dd1eb 100644 --- a/test/Storage.test.js +++ b/test/Storage.test.js @@ -121,21 +121,25 @@ describe("Storage", function () { ;({ periodOf, periodEnd } = periodic(period)) }) - async function ensureProofIsMissing() { - let currentPeriod = periodOf(await currentTime()) - await advanceTimeTo(periodEnd(currentPeriod)) - while (!(await storage.isProofRequired(id))) { + async function waitUntilProofIsRequired() { + await advanceTimeTo(periodEnd(periodOf(await currentTime()))) + while ( + !( + (await storage.isProofRequired(id)) && + (await storage.getPointer(id)) < 250 + ) + ) { 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 () { await storage.connect(host).startContract(id) 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 expect(await storage.balanceOf(host.address)).to.equal(expectedBalance)