Skip to content

Commit

Permalink
PublicKeys test
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jul 8, 2024
1 parent b3e1ef8 commit 7607ae2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions noir-projects/aztec-nr/aztec/src/keys/public_keys.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 31 additions & 0 deletions yarn-project/circuits.js/src/types/public_keys.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 7607ae2

Please sign in to comment.