diff --git a/.circleci/config.yml b/.circleci/config.yml index 07dd2a3ee5f..0022aa87cd3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -521,6 +521,17 @@ jobs: name: "Test" command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_2_pxes.test.ts + e2e-note-getter: + docker: + - image: aztecprotocol/alpine-build-image + resource_class: small + steps: + - *checkout + - *setup_env + - run: + name: "Test" + command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_note_getter.test.ts + e2e-multiple-accounts-1-enc-key: docker: - image: aztecprotocol/alpine-build-image @@ -1221,6 +1232,7 @@ workflows: - cli <<: *defaults - e2e-2-pxes: *e2e_test + - e2e-note-getter: *e2e_test - e2e-deploy-contract: *e2e_test - e2e-lending-contract: *e2e_test - e2e-token-contract: *e2e_test @@ -1260,6 +1272,7 @@ workflows: requires: - mainnet-fork - e2e-2-pxes + - e2e-note-getter - e2e-deploy-contract - e2e-lending-contract - e2e-token-contract diff --git a/yarn-project/end-to-end/src/e2e_note_getter.test.ts b/yarn-project/end-to-end/src/e2e_note_getter.test.ts index 3d5b309a36e..68f41d00444 100644 --- a/yarn-project/end-to-end/src/e2e_note_getter.test.ts +++ b/yarn-project/end-to-end/src/e2e_note_getter.test.ts @@ -8,6 +8,9 @@ interface NoirOption { _value: T; } +const sortFunc = (a: any, b: any) => + a.points > b.points ? 1 : a.points < b.points ? -1 : a.randomness > b.randomness ? 1 : -1; + function unwrapOptions(options: NoirOption[]): T[] { return options.filter((option: any) => option._is_some).map((option: any) => option._value); } @@ -28,9 +31,17 @@ describe('e2e_note_getter', () => { afterAll(() => teardown()); it('inserts notes from 0-9, then makes multiple queries specifying the total suite of comparators', async () => { - const numbers = [...Array(10).keys()]; - await Promise.all(numbers.map(number => contract.methods.insert_note(number).send().wait())); - await contract.methods.insert_note(5).send().wait(); + // ISSUE #4243 + // Calling this function does not work like this + // const numbers = [...Array(10).keys()]; + // await Promise.all(numbers.map(number => contract.methods.insert_note(number).send().wait())); + // It causes a race condition complaining about root mismatch + + await contract.methods + .insert_notes([...Array(10).keys()]) + .send() + .wait(); + await contract.methods.insert_note(5, Fr.ZERO).send().wait(); const [returnEq, returnNeq, returnLt, returnGt, returnLte, returnGte] = await Promise.all([ contract.methods.read_note(5, Comparator.EQ).view(), @@ -41,15 +52,21 @@ describe('e2e_note_getter', () => { contract.methods.read_note(5, Comparator.GTE).view(), ]); - expect(unwrapOptions(returnEq).map(({ points, randomness }: any) => ({ points, randomness }))).toStrictEqual([ - { points: 5n, randomness: 1n }, - { points: 5n, randomness: 1n }, - ]); + expect( + unwrapOptions(returnEq) + .map(({ points, randomness }: any) => ({ points, randomness })) + .sort(sortFunc), + ).toStrictEqual( + [ + { points: 5n, randomness: 1n }, + { points: 5n, randomness: 0n }, + ].sort(sortFunc), + ); expect( unwrapOptions(returnNeq) .map(({ points, randomness }: any) => ({ points, randomness })) - .sort((a: any, b: any) => (a.points > b.points ? 1 : -1)), + .sort(sortFunc), ).toStrictEqual( [ { points: 0n, randomness: 1n }, @@ -61,13 +78,13 @@ describe('e2e_note_getter', () => { { points: 8n, randomness: 1n }, { points: 4n, randomness: 1n }, { points: 3n, randomness: 1n }, - ].sort((a: any, b: any) => (a.points > b.points ? 1 : -1)), + ].sort(sortFunc), ); expect( unwrapOptions(returnLt) .map(({ points, randomness }: any) => ({ points, randomness })) - .sort((a: any, b: any) => (a.points > b.points ? 1 : -1)), + .sort(sortFunc), ).toStrictEqual( [ { points: 0n, randomness: 1n }, @@ -75,51 +92,51 @@ describe('e2e_note_getter', () => { { points: 2n, randomness: 1n }, { points: 4n, randomness: 1n }, { points: 3n, randomness: 1n }, - ].sort((a: any, b: any) => (a.points > b.points ? 1 : -1)), + ].sort(sortFunc), ); expect( unwrapOptions(returnGt) .map(({ points, randomness }: any) => ({ points, randomness })) - .sort((a: any, b: any) => (a.points > b.points ? 1 : -1)), + .sort(sortFunc), ).toStrictEqual( [ { points: 7n, randomness: 1n }, { points: 9n, randomness: 1n }, { points: 6n, randomness: 1n }, { points: 8n, randomness: 1n }, - ].sort((a: any, b: any) => (a.points > b.points ? 1 : -1)), + ].sort(sortFunc), ); expect( unwrapOptions(returnLte) .map(({ points, randomness }: any) => ({ points, randomness })) - .sort((a: any, b: any) => (a.points > b.points ? 1 : -1)), + .sort(sortFunc), ).toStrictEqual( [ { points: 5n, randomness: 1n }, - { points: 5n, randomness: 1n }, + { points: 5n, randomness: 0n }, { points: 0n, randomness: 1n }, { points: 1n, randomness: 1n }, { points: 2n, randomness: 1n }, { points: 4n, randomness: 1n }, { points: 3n, randomness: 1n }, - ].sort((a: any, b: any) => (a.points > b.points ? 1 : -1)), + ].sort(sortFunc), ); expect( unwrapOptions(returnGte) .map(({ points, randomness }: any) => ({ points, randomness })) - .sort((a: any, b: any) => (a.points > b.points ? 1 : -1)), + .sort(sortFunc), ).toStrictEqual( [ - { points: 5n, randomness: 1n }, + { points: 5n, randomness: 0n }, { points: 5n, randomness: 1n }, { points: 7n, randomness: 1n }, { points: 9n, randomness: 1n }, { points: 6n, randomness: 1n }, { points: 8n, randomness: 1n }, - ].sort((a: any, b: any) => (a.points > b.points ? 1 : -1)), + ].sort(sortFunc), ); }, 300_000); }); diff --git a/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr b/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr index bc5874ecc66..7d5c8ae1257 100644 --- a/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr @@ -96,8 +96,16 @@ contract DocsExample { } #[aztec(private)] - fn insert_note(amount: u8) { - let mut note = CardNote::new(amount, 1, context.msg_sender()); + fn insert_notes(amounts: [u8; 10]) { + for i in 0..amounts.len() { + let mut note = CardNote::new(amounts[i], 1, context.msg_sender()); + storage.test.insert(&mut note, true); + } + } + + #[aztec(private)] + fn insert_note(amount: u8, randomness: Field) { + let mut note = CardNote::new(amount, randomness, context.msg_sender()); storage.test.insert(&mut note, true); } @@ -105,15 +113,6 @@ contract DocsExample { let options = NoteViewerOptions::new().select(0, amount, Option::some(comparator)); let notes = storage.test.view_notes(options); - for i in 0..notes.len() { - if notes[i].is_some() { - debug_log_format( - "NOTES THAT MATCH: {0}", - [notes[i].unwrap_unchecked().points as Field] - ); - } - } - notes }