Skip to content

Commit 3b97770

Browse files
authored
chore: Accumulated backports to v4-next (#22174)
BEGIN_COMMIT_OVERRIDE fix(aztec-nr): use registered accounts as capsule test scopes (#22171) END_COMMIT_OVERRIDE
2 parents 4ffd56d + 603dd71 commit 3b97770

File tree

8 files changed

+273
-242
lines changed

8 files changed

+273
-242
lines changed

noir-projects/aztec-nr/aztec/src/capsules/mod.nr

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -149,42 +149,43 @@ impl<T> CapsuleArray<T> {
149149
}
150150

151151
mod test {
152-
use crate::protocol::address::AztecAddress;
153152
use crate::test::helpers::test_environment::TestEnvironment;
154153
use super::CapsuleArray;
155154

156155
global SLOT: Field = 1230;
157-
global SCOPE: AztecAddress = AztecAddress { inner: 0xface };
158156

159157
#[test]
160158
unconstrained fn empty_array() {
161-
let env = TestEnvironment::new();
159+
let mut env = TestEnvironment::new();
160+
let scope = env.create_light_account();
162161
env.private_context(|context| {
163162
let contract_address = context.this_address();
164163

165-
let array: CapsuleArray<Field> = CapsuleArray::at(contract_address, SLOT, SCOPE);
164+
let array: CapsuleArray<Field> = CapsuleArray::at(contract_address, SLOT, scope);
166165
assert_eq(array.len(), 0);
167166
});
168167
}
169168

170169
#[test(should_fail_with = "Attempted to read past the length of a CapsuleArray")]
171170
unconstrained fn empty_array_read() {
172-
let env = TestEnvironment::new();
171+
let mut env = TestEnvironment::new();
172+
let scope = env.create_light_account();
173173
env.private_context(|context| {
174174
let contract_address = context.this_address();
175175

176-
let array = CapsuleArray::at(contract_address, SLOT, SCOPE);
176+
let array = CapsuleArray::at(contract_address, SLOT, scope);
177177
let _: Field = array.get(0);
178178
});
179179
}
180180

181181
#[test]
182182
unconstrained fn array_push() {
183-
let env = TestEnvironment::new();
183+
let mut env = TestEnvironment::new();
184+
let scope = env.create_light_account();
184185
env.private_context(|context| {
185186
let contract_address = context.this_address();
186187

187-
let array = CapsuleArray::at(contract_address, SLOT, SCOPE);
188+
let array = CapsuleArray::at(contract_address, SLOT, scope);
188189
array.push(5);
189190

190191
assert_eq(array.len(), 1);
@@ -194,11 +195,12 @@ mod test {
194195

195196
#[test(should_fail_with = "Attempted to read past the length of a CapsuleArray")]
196197
unconstrained fn read_past_len() {
197-
let env = TestEnvironment::new();
198+
let mut env = TestEnvironment::new();
199+
let scope = env.create_light_account();
198200
env.private_context(|context| {
199201
let contract_address = context.this_address();
200202

201-
let array = CapsuleArray::at(contract_address, SLOT, SCOPE);
203+
let array = CapsuleArray::at(contract_address, SLOT, scope);
202204
array.push(5);
203205

204206
let _ = array.get(1);
@@ -207,11 +209,12 @@ mod test {
207209

208210
#[test]
209211
unconstrained fn array_remove_last() {
210-
let env = TestEnvironment::new();
212+
let mut env = TestEnvironment::new();
213+
let scope = env.create_light_account();
211214
env.private_context(|context| {
212215
let contract_address = context.this_address();
213216

214-
let array = CapsuleArray::at(contract_address, SLOT, SCOPE);
217+
let array = CapsuleArray::at(contract_address, SLOT, scope);
215218

216219
array.push(5);
217220
array.remove(0);
@@ -222,11 +225,12 @@ mod test {
222225

223226
#[test]
224227
unconstrained fn array_remove_some() {
225-
let env = TestEnvironment::new();
228+
let mut env = TestEnvironment::new();
229+
let scope = env.create_light_account();
226230
env.private_context(|context| {
227231
let contract_address = context.this_address();
228232

229-
let array = CapsuleArray::at(contract_address, SLOT, SCOPE);
233+
let array = CapsuleArray::at(contract_address, SLOT, scope);
230234

231235
array.push(7);
232236
array.push(8);
@@ -247,11 +251,12 @@ mod test {
247251

248252
#[test]
249253
unconstrained fn array_remove_all() {
250-
let env = TestEnvironment::new();
254+
let mut env = TestEnvironment::new();
255+
let scope = env.create_light_account();
251256
env.private_context(|context| {
252257
let contract_address = context.this_address();
253258

254-
let array = CapsuleArray::at(contract_address, SLOT, SCOPE);
259+
let array = CapsuleArray::at(contract_address, SLOT, scope);
255260

256261
array.push(7);
257262
array.push(8);
@@ -267,10 +272,11 @@ mod test {
267272

268273
#[test]
269274
unconstrained fn for_each_called_with_all_elements() {
270-
let env = TestEnvironment::new();
275+
let mut env = TestEnvironment::new();
276+
let scope = env.create_light_account();
271277
env.private_context(|context| {
272278
let contract_address = context.this_address();
273-
let array = CapsuleArray::at(contract_address, SLOT, SCOPE);
279+
let array = CapsuleArray::at(contract_address, SLOT, scope);
274280

275281
array.push(4);
276282
array.push(5);
@@ -290,10 +296,11 @@ mod test {
290296

291297
#[test]
292298
unconstrained fn for_each_remove_some() {
293-
let env = TestEnvironment::new();
299+
let mut env = TestEnvironment::new();
300+
let scope = env.create_light_account();
294301
env.private_context(|context| {
295302
let contract_address = context.this_address();
296-
let array = CapsuleArray::at(contract_address, SLOT, SCOPE);
303+
let array = CapsuleArray::at(contract_address, SLOT, scope);
297304

298305
array.push(4);
299306
array.push(5);
@@ -313,10 +320,11 @@ mod test {
313320

314321
#[test]
315322
unconstrained fn for_each_remove_all() {
316-
let env = TestEnvironment::new();
323+
let mut env = TestEnvironment::new();
324+
let scope = env.create_light_account();
317325
env.private_context(|context| {
318326
let contract_address = context.this_address();
319-
let array = CapsuleArray::at(contract_address, SLOT, SCOPE);
327+
let array = CapsuleArray::at(contract_address, SLOT, scope);
320328

321329
array.push(4);
322330
array.push(5);
@@ -330,10 +338,11 @@ mod test {
330338

331339
#[test]
332340
unconstrained fn for_each_remove_all_no_copy() {
333-
let env = TestEnvironment::new();
341+
let mut env = TestEnvironment::new();
342+
let scope = env.create_light_account();
334343
env.private_context(|context| {
335344
let contract_address = context.this_address();
336-
let array = CapsuleArray::at(contract_address, SLOT, SCOPE);
345+
let array = CapsuleArray::at(contract_address, SLOT, scope);
337346

338347
array.push(4);
339348
array.push(5);
@@ -351,11 +360,11 @@ mod test {
351360

352361
#[test]
353362
unconstrained fn different_scopes_are_isolated() {
354-
let env = TestEnvironment::new();
363+
let mut env = TestEnvironment::new();
364+
let scope_a = env.create_light_account();
365+
let scope_b = env.create_light_account();
355366
env.private_context(|context| {
356367
let contract_address = context.this_address();
357-
let scope_a = AztecAddress { inner: 0xaaa };
358-
let scope_b = AztecAddress { inner: 0xbbb };
359368

360369
let array_a = CapsuleArray::at(contract_address, SLOT, scope_a);
361370
let array_b = CapsuleArray::at(contract_address, SLOT, scope_b);

noir-projects/aztec-nr/aztec/src/history/test.nr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@ use crate::{
66
},
77
test::{helpers::test_environment::TestEnvironment, mocks::mock_note::MockNote},
88
};
9-
use crate::protocol::{address::AztecAddress, traits::FromField};
109

1110
pub(crate) global NOTE_STORAGE_SLOT: Field = 420;
1211
pub(crate) global NOTE_CREATED_AT: u32 = 2;
1312
pub(crate) global NOTE_NULLIFIED_AT: u32 = 3;
14-
pub(crate) global NOTE_OWNER: AztecAddress = AztecAddress::from_field(50);
1513

1614
pub(crate) unconstrained fn create_note() -> (TestEnvironment, HintedNote<MockNote>) {
17-
let env = TestEnvironment::new();
15+
let mut env = TestEnvironment::new();
16+
let note_owner = env.create_light_account();
1817

1918
let note_message = env.private_context(|context| {
2019
let mut mock_note = MockNote::new(69);
2120

2221
lifecycle_create_note(
2322
context,
24-
NOTE_OWNER,
23+
note_owner,
2524
NOTE_STORAGE_SLOT,
2625
mock_note.build_note(),
2726
)
@@ -32,7 +31,7 @@ pub(crate) unconstrained fn create_note() -> (TestEnvironment, HintedNote<MockNo
3231

3332
env.discover_note(note_message);
3433

35-
let hinted_note = env.utility_context(|_| view_note(Option::some(NOTE_OWNER), NOTE_STORAGE_SLOT));
34+
let hinted_note = env.utility_context(|_| view_note(Option::some(note_owner), NOTE_STORAGE_SLOT));
3635

3736
(env, hinted_note)
3837
}

noir-projects/aztec-nr/aztec/src/messages/discovery/mod.nr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,17 @@ mod test {
200200
};
201201
use crate::protocol::address::AztecAddress;
202202

203-
global SCOPE: AztecAddress = AztecAddress { inner: 0xcafe };
204-
205203
#[test]
206204
unconstrained fn do_sync_state_does_not_panic_on_empty_logs() {
207-
let env = TestEnvironment::new();
205+
let mut env = TestEnvironment::new();
206+
let scope = env.create_light_account();
208207

209208
let contract_address = AztecAddress { inner: 0xdeadbeef };
210209

211210
env.utility_context_at(contract_address, |_| {
212211
let base_slot = PENDING_TAGGED_LOG_ARRAY_BASE_SLOT;
213212

214-
let logs: CapsuleArray<PendingTaggedLog> = CapsuleArray::at(contract_address, base_slot, SCOPE);
213+
let logs: CapsuleArray<PendingTaggedLog> = CapsuleArray::at(contract_address, base_slot, scope);
215214
logs.push(PendingTaggedLog { log: BoundedVec::new(), context: std::mem::zeroed() });
216215
assert_eq(logs.len(), 1);
217216

@@ -223,7 +222,7 @@ mod test {
223222
dummy_compute_note_nullifier,
224223
no_handler,
225224
no_inbox_sync,
226-
SCOPE,
225+
scope,
227226
);
228227

229228
assert_eq(logs.len(), 0);

0 commit comments

Comments
 (0)