From d91a784681df656e3ff2c0defe601b9abeb6c782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matev=C5=BE=20Jekovec?= Date: Wed, 23 Oct 2024 13:23:23 +0200 Subject: [PATCH 1/2] contracts/test/auth: Wait for correct block --- contracts/test/auth.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/contracts/test/auth.ts b/contracts/test/auth.ts index a27a8787..9d8f0e91 100644 --- a/contracts/test/auth.ts +++ b/contracts/test/auth.ts @@ -160,10 +160,15 @@ describe('Auth', function () { siweStr4, await erc191sign(siweStr4, account), ); - // Wait until the next second after expiration - await delay(expiration.getTime() - Date.now() + 1000); - const tx = await siweAuthTests.doNothing(); - await tx.wait(); + // Wait until the block time is greater than the expiration date + await new Promise((resolve, reject) => { + ethers.provider.on('block', async (blockNumber) => { + const ts = (await ethers.provider.getBlock(blockNumber))!.timestamp; + if (ts * 1000 > expiration.getTime()) { + resolve(); + } + }); + }); await expect(siweAuthTests.testVerySecretMessage(bearer4)).to.be.reverted; // Revoke bearer. From 6e142c643cee71fdc50b9c54ff86ec284369dfb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matev=C5=BE=20Jekovec?= Date: Wed, 23 Oct 2024 13:25:48 +0200 Subject: [PATCH 2/2] contracts/test/gas: Workaround for flaky gas cost --- contracts/test/gas.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/test/gas.ts b/contracts/test/gas.ts index 02a14abe..329cb233 100644 --- a/contracts/test/gas.ts +++ b/contracts/test/gas.ts @@ -30,8 +30,11 @@ describe('Gas Padding', function () { // Note: calldata isn't included in gas padding // Thus when the value is 0 it will use 4 gas instead of 16 gas + // TODO: Workaround for flaky gas used https://github.com/oasisprotocol/sapphire-paratime/issues/337. tx = await contract.testConstantTime(0, 100000); receipt = await tx.wait(); - expect(receipt?.cumulativeGasUsed).eq(initialGasUsed - 12n); + expect(receipt?.cumulativeGasUsed) + .gte(initialGasUsed - 13n) + .lte(initialGasUsed - 12n); }); });