Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contracts/tests: Fix flaky SIWE and gas cost #444

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions contracts/test/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((resolve, reject) => {
CedarMist marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down
5 changes: 4 additions & 1 deletion contracts/test/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Loading