@@ -15,7 +15,8 @@ pub unconstrained fn setup(
15
15
let owner = env .create_account (1 );
16
16
env .impersonate (owner );
17
17
18
- // Advance a block so we know that at block 2 our contract has not been deployed yet.
18
+ // We need to advance two blocks here, because we want to deploy our contract at block 3.
19
+ // This is because we will do tests later that prove the non inclusion of values and of the contract itself at block 2.
19
20
env .advance_block_by (2 );
20
21
21
22
// Deploy contract and initialize
@@ -30,42 +31,47 @@ pub unconstrained fn setup(
30
31
#[test]
31
32
unconstrained fn note_flow () {
32
33
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
33
-
34
34
env .impersonate (owner );
35
35
36
- let block_number = env .block_number ();
36
+ let note_creation_block_number = env .block_number ();
37
37
38
38
let NOTE_VALUE = 69 ;
39
39
InclusionProofs ::at (contract_address ).create_note (owner , NOTE_VALUE ).call (&mut env .private ());
40
40
41
+ // We have to advance two blocks here because if we only advanced it by one, the current block would be 4, and the note creation block would be 3.
42
+ // But when we do not use the block_number, env.private would get the last block header, which is still 3. Fix this !
43
+ // TODO: env.block_number() should actually return the private context inputs block number, not the block that is currently being built !
44
+ // Change env.block_number to subtract one, then just use `env.block_number()`.
41
45
env .advance_block_by (2 );
42
46
43
47
let current_contract_address = get_contract_address ();
44
48
cheatcodes:: set_contract_address (contract_address );
45
49
50
+ // We fetch the note we created and make sure that it is valid.
46
51
let note = InclusionProofs ::get_note (owner );
47
52
cheatcodes:: set_contract_address (current_contract_address );
48
53
49
54
assert (note .owner .eq (owner ));
50
55
assert (note .value .eq (NOTE_VALUE ));
51
56
57
+ // Each of these tests (note inclusion, note non-nullification, and validity (inclusion & non-nullification)) check the assertion at the block of creation of note, as well as at the "current" block
52
58
InclusionProofs ::at (contract_address )
53
- .test_note_inclusion (owner , true , block_number , false )
59
+ .test_note_inclusion (owner , true , note_creation_block_number , false )
54
60
.call (&mut env .private ());
55
61
InclusionProofs ::at (contract_address ).test_note_inclusion (owner , false , 0 , false ).call (
56
62
&mut env .private (),
57
63
);
58
64
59
65
InclusionProofs ::at (contract_address )
60
- .test_note_not_nullified (owner , true , block_number , false )
66
+ .test_note_not_nullified (owner , true , note_creation_block_number , false )
61
67
.call (&mut env .private ());
62
68
InclusionProofs ::at (contract_address ).test_note_not_nullified (owner , false , 0 , false ).call (
63
69
&mut env .private (),
64
70
);
65
71
66
- InclusionProofs ::at (contract_address ). test_note_validity ( owner , true , block_number , false ). call (
67
- & mut env . private (),
68
- );
72
+ InclusionProofs ::at (contract_address )
73
+ . test_note_validity ( owner , true , note_creation_block_number , false )
74
+ . call (& mut env . private () );
69
75
InclusionProofs ::at (contract_address ).test_note_validity (owner , false , 0 , false ).call (
70
76
&mut env .private (),
71
77
);
@@ -74,7 +80,6 @@ unconstrained fn note_flow() {
74
80
#[test]
75
81
unconstrained fn nullify_note_flow () {
76
82
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
77
-
78
83
env .impersonate (owner );
79
84
80
85
let note_valid_block_number = env .block_number ();
@@ -87,6 +92,7 @@ unconstrained fn nullify_note_flow() {
87
92
88
93
env .advance_block_by (1 );
89
94
95
+ // We test note inclusion at the note creation block and at current block
90
96
InclusionProofs ::at (contract_address )
91
97
.test_note_inclusion (owner , true , note_valid_block_number , true )
92
98
.call (&mut env .private ());
@@ -95,6 +101,7 @@ unconstrained fn nullify_note_flow() {
95
101
&mut env .private (),
96
102
);
97
103
104
+ // We test note non-nullification and validity at the note creation block
98
105
InclusionProofs ::at (contract_address )
99
106
.test_note_not_nullified (owner , true , note_valid_block_number , true )
100
107
.call (&mut env .private ());
@@ -106,7 +113,6 @@ unconstrained fn nullify_note_flow() {
106
113
#[test(should_fail_with = "Assertion failed: Proving nullifier non-inclusion failed: low_nullifier.value < nullifier.value check failed")]
107
114
unconstrained fn note_not_nullified_after_nullified () {
108
115
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
109
-
110
116
env .impersonate (owner );
111
117
112
118
InclusionProofs ::at (contract_address ).create_note (owner , 5 ).call (&mut env .private ());
@@ -127,7 +133,6 @@ unconstrained fn note_not_nullified_after_nullified() {
127
133
#[test(should_fail_with = "Assertion failed: Proving nullifier non-inclusion failed: low_nullifier.value < nullifier.value check failed")]
128
134
unconstrained fn note_not_nullified_after_nullified_no_block_number () {
129
135
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
130
-
131
136
env .impersonate (owner );
132
137
133
138
InclusionProofs ::at (contract_address ).create_note (owner , 5 ).call (&mut env .private ());
@@ -146,7 +151,6 @@ unconstrained fn note_not_nullified_after_nullified_no_block_number() {
146
151
#[test(should_fail_with = "Assertion failed: Proving nullifier non-inclusion failed: low_nullifier.value < nullifier.value check failed")]
147
152
unconstrained fn validity_after_nullified () {
148
153
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
149
-
150
154
env .impersonate (owner );
151
155
152
156
InclusionProofs ::at (contract_address ).create_note (owner , 5 ).call (&mut env .private ());
@@ -165,7 +169,6 @@ unconstrained fn validity_after_nullified() {
165
169
#[test(should_fail_with = "Assertion failed: Proving nullifier non-inclusion failed: low_nullifier.value < nullifier.value check failed")]
166
170
unconstrained fn validity_after_nullified_no_block_number () {
167
171
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
168
-
169
172
env .impersonate (owner );
170
173
171
174
InclusionProofs ::at (contract_address ).create_note (owner , 5 ).call (&mut env .private ());
@@ -184,8 +187,8 @@ unconstrained fn validity_after_nullified_no_block_number() {
184
187
#[test(should_fail_with = "not found in NOTE_HASH_TREE")]
185
188
unconstrained fn note_inclusion_fail_case () {
186
189
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
187
-
188
190
env .impersonate (owner );
191
+
189
192
let random_owner = AztecAddress ::from_field (dep::aztec::oracle::random:: random ());
190
193
191
194
let block_number = env .block_number ();
@@ -200,8 +203,8 @@ unconstrained fn note_inclusion_fail_case() {
200
203
#[test(should_fail_with = "not found in NOTE_HASH_TREE")]
201
204
unconstrained fn note_inclusion_fail_case_no_block_number () {
202
205
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
203
-
204
206
env .impersonate (owner );
207
+
205
208
let random_owner = AztecAddress ::from_field (dep::aztec::oracle::random:: random ());
206
209
207
210
env .advance_block_by (1 );
@@ -231,7 +234,6 @@ unconstrained fn nullifier_inclusion() {
231
234
#[test]
232
235
unconstrained fn nullifier_inclusion_public () {
233
236
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
234
-
235
237
env .impersonate (owner );
236
238
237
239
let unsiloed_nullifier = 0xffffff ;
@@ -248,9 +250,10 @@ unconstrained fn nullifier_inclusion_public() {
248
250
#[test(should_fail_with = "Nullifier witness not found for nullifier")]
249
251
unconstrained fn nullifier_non_existence () {
250
252
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
253
+ env .impersonate (owner );
251
254
252
255
let block_number = env .block_number () - 1 ;
253
- env . impersonate ( owner );
256
+
254
257
let random_nullifier = dep::aztec::oracle::random:: random ();
255
258
256
259
InclusionProofs ::at (contract_address )
@@ -261,8 +264,8 @@ unconstrained fn nullifier_non_existence() {
261
264
#[test(should_fail_with = "Nullifier witness not found for nullifier")]
262
265
unconstrained fn nullifier_non_existence_no_block_number () {
263
266
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
264
-
265
267
env .impersonate (owner );
268
+
266
269
let random_nullifier = dep::aztec::oracle::random:: random ();
267
270
268
271
InclusionProofs ::at (contract_address ).test_nullifier_inclusion (random_nullifier , false , 0 ).call (
@@ -273,7 +276,6 @@ unconstrained fn nullifier_non_existence_no_block_number() {
273
276
#[test]
274
277
unconstrained fn historical_reads () {
275
278
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
276
-
277
279
env .impersonate (owner );
278
280
279
281
let block_number = env .block_number () - 1 ;
@@ -298,7 +300,6 @@ unconstrained fn historical_reads() {
298
300
#[test]
299
301
unconstrained fn contract_flow () {
300
302
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
301
-
302
303
env .impersonate (owner );
303
304
304
305
let block_number = env .block_number () - 1 ;
@@ -316,7 +317,6 @@ unconstrained fn contract_flow() {
316
317
#[test(should_fail_with = "Nullifier witness not found for nullifier")]
317
318
unconstrained fn test_contract_not_initialized () {
318
319
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
319
-
320
320
env .impersonate (owner );
321
321
322
322
// We are using block number 2 because we know the contract has not been deployed nor initialized at this point.
@@ -328,11 +328,32 @@ unconstrained fn test_contract_not_initialized() {
328
328
#[test(should_fail_with = "Nullifier witness not found for nullifier")]
329
329
unconstrained fn test_contract_not_deployed () {
330
330
let (env , contract_address , owner ) = setup (INITIAL_VALUE );
331
-
332
331
env .impersonate (owner );
333
332
334
333
// We are using block number 2 because we know the contract has not been deployed nor initialized at this point.
335
334
InclusionProofs ::at (contract_address )
336
335
.test_contract_inclusion (contract_address , 2 , false , true )
337
336
.call (&mut env .private ());
338
337
}
338
+
339
+ #[test]
340
+ unconstrained fn test_deployed_contract_not_deployed () {
341
+ let (env , contract_address , owner ) = setup (INITIAL_VALUE );
342
+ env .impersonate (owner );
343
+
344
+ // We are using block number 2 because we know the contract has been deployed nor initialized at this point.
345
+ InclusionProofs ::at (contract_address )
346
+ .test_contract_non_inclusion (contract_address , 3 , true , false )
347
+ .call (&mut env .private ());
348
+ }
349
+
350
+ #[test]
351
+ unconstrained fn test_deployed_contract_not_initialized () {
352
+ let (env , contract_address , owner ) = setup (INITIAL_VALUE );
353
+ env .impersonate (owner );
354
+
355
+ // We are using block number 2 because we know the contract has been deployed nor initialized at this point.
356
+ InclusionProofs ::at (contract_address )
357
+ .test_contract_non_inclusion (contract_address , 3 , false , true )
358
+ .call (&mut env .private ());
359
+ }
0 commit comments