Skip to content

Commit

Permalink
Merge pull request #280 from oasisprotocol/jberci/fix/signtests
Browse files Browse the repository at this point in the history
contracts: fix flaky signing tests
  • Loading branch information
CedarMist authored Mar 13, 2024
2 parents 06fe637 + ba6f902 commit e084c36
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions contracts/test/signing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import { ethers } from 'hardhat';
import { SigningTests__factory } from '../typechain-types/factories/contracts/tests';
import { SigningTests } from '../typechain-types/contracts/tests/SigningTests';

function randomBytesUnlike(len: number, orig: Buffer): Buffer {
do {
var bytes = randomBytes(len);
} while (len > 0 && bytes.equals(orig));
return bytes;
}

async function testSignThenVerify(
se: SigningTests,
alg: number,
Expand All @@ -29,7 +36,7 @@ async function testSignThenVerify(
alg,
keypair.publicKey,
ctx,
randomBytes(msg.length),
randomBytesUnlike(msg.length, msg),
sig,
),
).equal(false);
Expand All @@ -41,7 +48,7 @@ async function testSignThenVerify(
await se.testVerify(
alg,
keypair.publicKey,
randomBytes(ctx.length),
randomBytesUnlike(ctx.length, ctx),
msg,
sig,
),
Expand Down

0 comments on commit e084c36

Please sign in to comment.