From 7607ae231ca5cbb346add8d6b10ae67ac83475f4 Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 8 Jul 2024 16:03:42 +0000 Subject: [PATCH] PublicKeys test --- .../aztec-nr/aztec/src/keys/public_keys.nr | 10 ++++++ .../circuits.js/src/types/public_keys.test.ts | 31 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 yarn-project/circuits.js/src/types/public_keys.test.ts diff --git a/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr b/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr index a78bb4739a1..204e9acc10a 100644 --- a/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr +++ b/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr @@ -115,6 +115,16 @@ fn compute_public_keys_hash() { assert(actual.to_field() == expected_public_keys_hash); } +#[test] +fn compute_empty_hash() { + let keys = PublicKeys::empty(); + + let actual = keys.hash(); + let test_data_empty_hash = 0x0000000000000000000000000000000000000000000000000000000000000000; + + assert(actual.to_field() == test_data_empty_hash); +} + #[test] fn test_public_keys_serialization() { let keys = PublicKeys { diff --git a/yarn-project/circuits.js/src/types/public_keys.test.ts b/yarn-project/circuits.js/src/types/public_keys.test.ts new file mode 100644 index 00000000000..b07c840a584 --- /dev/null +++ b/yarn-project/circuits.js/src/types/public_keys.test.ts @@ -0,0 +1,31 @@ +import { Fr, Point } from '@aztec/foundation/fields'; +import { updateInlineTestData } from '@aztec/foundation/testing'; + +import { PublicKeys } from './public_keys.js'; + +describe('PublicKeys', () => { + it('computes public keys hash', () => { + const keys = new PublicKeys( + new Point(new Fr(1n), new Fr(2n), false), + new Point(new Fr(3n), new Fr(4n), false), + new Point(new Fr(5n), new Fr(6n), false), + new Point(new Fr(7n), new Fr(8n), false), + ); + + const hash = keys.hash().toString(); + expect(hash).toMatchInlineSnapshot(`"0x146f68c0e0ba4067d61a3304bbfdec0797d5df1357db6c01247c48bfb345c7d7"`); + + // Run with AZTEC_GENERATE_TEST_DATA=1 to update noir test data + updateInlineTestData('noir-projects/aztec-nr/aztec/src/keys/public_keys.nr', 'expected_public_keys_hash', hash); + }); + + it('computes empty keys hash', () => { + const keys = PublicKeys.empty(); + + const hash = keys.hash().toString(); + expect(hash).toMatchInlineSnapshot(`"0x0000000000000000000000000000000000000000000000000000000000000000"`); + + // Run with AZTEC_GENERATE_TEST_DATA=1 to update noir test data + updateInlineTestData('noir-projects/aztec-nr/aztec/src/keys/public_keys.nr', 'test_data_empty_hash', hash); + }); +});