Skip to content

Commit 385bf4b

Browse files
authored
chore: add note getter test to cci (AztecProtocol#4236)
1 parent 21727dc commit 385bf4b

File tree

3 files changed

+59
-30
lines changed

3 files changed

+59
-30
lines changed

.circleci/config.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,17 @@ jobs:
521521
name: "Test"
522522
command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_2_pxes.test.ts
523523

524+
e2e-note-getter:
525+
docker:
526+
- image: aztecprotocol/alpine-build-image
527+
resource_class: small
528+
steps:
529+
- *checkout
530+
- *setup_env
531+
- run:
532+
name: "Test"
533+
command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_note_getter.test.ts
534+
524535
e2e-multiple-accounts-1-enc-key:
525536
docker:
526537
- image: aztecprotocol/alpine-build-image
@@ -1221,6 +1232,7 @@ workflows:
12211232
- cli
12221233
<<: *defaults
12231234
- e2e-2-pxes: *e2e_test
1235+
- e2e-note-getter: *e2e_test
12241236
- e2e-deploy-contract: *e2e_test
12251237
- e2e-lending-contract: *e2e_test
12261238
- e2e-token-contract: *e2e_test
@@ -1260,6 +1272,7 @@ workflows:
12601272
requires:
12611273
- mainnet-fork
12621274
- e2e-2-pxes
1275+
- e2e-note-getter
12631276
- e2e-deploy-contract
12641277
- e2e-lending-contract
12651278
- e2e-token-contract

yarn-project/end-to-end/src/e2e_note_getter.test.ts

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ interface NoirOption<T> {
88
_value: T;
99
}
1010

11+
const sortFunc = (a: any, b: any) =>
12+
a.points > b.points ? 1 : a.points < b.points ? -1 : a.randomness > b.randomness ? 1 : -1;
13+
1114
function unwrapOptions<T>(options: NoirOption<T>[]): T[] {
1215
return options.filter((option: any) => option._is_some).map((option: any) => option._value);
1316
}
@@ -28,9 +31,17 @@ describe('e2e_note_getter', () => {
2831
afterAll(() => teardown());
2932

3033
it('inserts notes from 0-9, then makes multiple queries specifying the total suite of comparators', async () => {
31-
const numbers = [...Array(10).keys()];
32-
await Promise.all(numbers.map(number => contract.methods.insert_note(number).send().wait()));
33-
await contract.methods.insert_note(5).send().wait();
34+
// ISSUE #4243
35+
// Calling this function does not work like this
36+
// const numbers = [...Array(10).keys()];
37+
// await Promise.all(numbers.map(number => contract.methods.insert_note(number).send().wait()));
38+
// It causes a race condition complaining about root mismatch
39+
40+
await contract.methods
41+
.insert_notes([...Array(10).keys()])
42+
.send()
43+
.wait();
44+
await contract.methods.insert_note(5, Fr.ZERO).send().wait();
3445

3546
const [returnEq, returnNeq, returnLt, returnGt, returnLte, returnGte] = await Promise.all([
3647
contract.methods.read_note(5, Comparator.EQ).view(),
@@ -41,15 +52,21 @@ describe('e2e_note_getter', () => {
4152
contract.methods.read_note(5, Comparator.GTE).view(),
4253
]);
4354

44-
expect(unwrapOptions(returnEq).map(({ points, randomness }: any) => ({ points, randomness }))).toStrictEqual([
45-
{ points: 5n, randomness: 1n },
46-
{ points: 5n, randomness: 1n },
47-
]);
55+
expect(
56+
unwrapOptions(returnEq)
57+
.map(({ points, randomness }: any) => ({ points, randomness }))
58+
.sort(sortFunc),
59+
).toStrictEqual(
60+
[
61+
{ points: 5n, randomness: 1n },
62+
{ points: 5n, randomness: 0n },
63+
].sort(sortFunc),
64+
);
4865

4966
expect(
5067
unwrapOptions(returnNeq)
5168
.map(({ points, randomness }: any) => ({ points, randomness }))
52-
.sort((a: any, b: any) => (a.points > b.points ? 1 : -1)),
69+
.sort(sortFunc),
5370
).toStrictEqual(
5471
[
5572
{ points: 0n, randomness: 1n },
@@ -61,65 +78,65 @@ describe('e2e_note_getter', () => {
6178
{ points: 8n, randomness: 1n },
6279
{ points: 4n, randomness: 1n },
6380
{ points: 3n, randomness: 1n },
64-
].sort((a: any, b: any) => (a.points > b.points ? 1 : -1)),
81+
].sort(sortFunc),
6582
);
6683

6784
expect(
6885
unwrapOptions(returnLt)
6986
.map(({ points, randomness }: any) => ({ points, randomness }))
70-
.sort((a: any, b: any) => (a.points > b.points ? 1 : -1)),
87+
.sort(sortFunc),
7188
).toStrictEqual(
7289
[
7390
{ points: 0n, randomness: 1n },
7491
{ points: 1n, randomness: 1n },
7592
{ points: 2n, randomness: 1n },
7693
{ points: 4n, randomness: 1n },
7794
{ points: 3n, randomness: 1n },
78-
].sort((a: any, b: any) => (a.points > b.points ? 1 : -1)),
95+
].sort(sortFunc),
7996
);
8097

8198
expect(
8299
unwrapOptions(returnGt)
83100
.map(({ points, randomness }: any) => ({ points, randomness }))
84-
.sort((a: any, b: any) => (a.points > b.points ? 1 : -1)),
101+
.sort(sortFunc),
85102
).toStrictEqual(
86103
[
87104
{ points: 7n, randomness: 1n },
88105
{ points: 9n, randomness: 1n },
89106
{ points: 6n, randomness: 1n },
90107
{ points: 8n, randomness: 1n },
91-
].sort((a: any, b: any) => (a.points > b.points ? 1 : -1)),
108+
].sort(sortFunc),
92109
);
93110

94111
expect(
95112
unwrapOptions(returnLte)
96113
.map(({ points, randomness }: any) => ({ points, randomness }))
97-
.sort((a: any, b: any) => (a.points > b.points ? 1 : -1)),
114+
.sort(sortFunc),
98115
).toStrictEqual(
99116
[
100117
{ points: 5n, randomness: 1n },
101-
{ points: 5n, randomness: 1n },
118+
{ points: 5n, randomness: 0n },
102119
{ points: 0n, randomness: 1n },
103120
{ points: 1n, randomness: 1n },
104121
{ points: 2n, randomness: 1n },
105122
{ points: 4n, randomness: 1n },
106123
{ points: 3n, randomness: 1n },
107-
].sort((a: any, b: any) => (a.points > b.points ? 1 : -1)),
124+
].sort(sortFunc),
108125
);
109126

110127
expect(
111128
unwrapOptions(returnGte)
112129
.map(({ points, randomness }: any) => ({ points, randomness }))
113-
.sort((a: any, b: any) => (a.points > b.points ? 1 : -1)),
130+
.sort(sortFunc),
114131
).toStrictEqual(
115132
[
116-
{ points: 5n, randomness: 1n },
133+
{ points: 5n, randomness: 0n },
117134
{ points: 5n, randomness: 1n },
118135
{ points: 7n, randomness: 1n },
119136
{ points: 9n, randomness: 1n },
120137
{ points: 6n, randomness: 1n },
121138
{ points: 8n, randomness: 1n },
122-
].sort((a: any, b: any) => (a.points > b.points ? 1 : -1)),
139+
].sort(sortFunc),
123140
);
124141
}, 300_000);
125142
});

yarn-project/noir-contracts/contracts/docs_example_contract/src/main.nr

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,23 @@ contract DocsExample {
9696
}
9797

9898
#[aztec(private)]
99-
fn insert_note(amount: u8) {
100-
let mut note = CardNote::new(amount, 1, context.msg_sender());
99+
fn insert_notes(amounts: [u8; 10]) {
100+
for i in 0..amounts.len() {
101+
let mut note = CardNote::new(amounts[i], 1, context.msg_sender());
102+
storage.test.insert(&mut note, true);
103+
}
104+
}
105+
106+
#[aztec(private)]
107+
fn insert_note(amount: u8, randomness: Field) {
108+
let mut note = CardNote::new(amount, randomness, context.msg_sender());
101109
storage.test.insert(&mut note, true);
102110
}
103111

104112
unconstrained fn read_note(amount: Field, comparator: u3) -> pub [Option<CardNote>; 10] {
105113
let options = NoteViewerOptions::new().select(0, amount, Option::some(comparator));
106114
let notes = storage.test.view_notes(options);
107115

108-
for i in 0..notes.len() {
109-
if notes[i].is_some() {
110-
debug_log_format(
111-
"NOTES THAT MATCH: {0}",
112-
[notes[i].unwrap_unchecked().points as Field]
113-
);
114-
}
115-
}
116-
117116
notes
118117
}
119118

0 commit comments

Comments
 (0)