Skip to content

Commit

Permalink
test(crypto): add a test to ensure key pair generation does not fail
Browse files Browse the repository at this point in the history
Add a test case which attemps to generate a new MACI keypair 500 times in a row to check whether
issue #239 still applies to the current codebase.

fix #239
  • Loading branch information
ctrlc03 committed Dec 15, 2023
1 parent bf0d552 commit b62ef0b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crypto/ts/__tests__/Crypto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,15 @@ describe("Cryptographic operations", function test() {
expect(commitment).to.eq(commitment2);
});
});

describe("genKeypair", () => {
it("should consistently generate a valid keypair (500 runs)", () => {
for (let i = 0; i < 500; i += 1) {
const key = genKeypair();
expect(key.privKey < SNARK_FIELD_SIZE).to.eq(true);
expect(key.pubKey[0] < SNARK_FIELD_SIZE).to.eq(true);
expect(key.pubKey[1] < SNARK_FIELD_SIZE).to.eq(true);
}
});
});
});

0 comments on commit b62ef0b

Please sign in to comment.