@@ -83,6 +83,11 @@ fn get_shared_mutable_num_slots() -> Field {
83
83
value_change_and_delay_change_packed_len + with_hash_additional_slots
84
84
}
85
85
86
+ global CONTRACT_DEPLOYED_AT : u32 = 3 ;
87
+
88
+ // In env.deploy_self("Test").with_private_initializer(initializer); it first deploys the contract, then advances a block, then calls the initializer.
89
+ global CONTRACT_INITIALIZED_AT : u32 = CONTRACT_DEPLOYED_AT + 1 ;
90
+
86
91
pub unconstrained fn setup () -> (&mut TestEnvironment , AztecAddress , AztecAddress ) {
87
92
// Setup env, generate keys
88
93
let mut env = TestEnvironment ::new ();
@@ -92,6 +97,9 @@ pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddres
92
97
// TODO(#12276): This is here because we are testing historical proofs, and we cannot get a valid block_header at 1 due to a bug in world state.
93
98
env .advance_block_by (1 );
94
99
100
+ // We sanity check that we are building block 3, thus block 3 is where the contract will be deployed.
101
+ assert_eq (env .pending_block_number (), CONTRACT_DEPLOYED_AT );
102
+
95
103
// Deploy contract and initialize
96
104
let initializer = Test ::interface ().initialize ();
97
105
let test_contract = env .deploy_self ("Test" ).with_private_initializer (initializer );
@@ -110,17 +118,25 @@ pub unconstrained fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddres
110
118
unconstrained fn contract_historical_proofs_happy_path () {
111
119
let (env , contract_address ) = setup ();
112
120
113
- let context = env .private ();
114
- let header_at_block_before_deployment = context .get_block_header_at (2 );
115
- let current_header = context .historical_header ;
121
+ let context_at_block_before_deployment = env .private_at (CONTRACT_DEPLOYED_AT - 1 );
122
+ let context_at_block_of_deployment = env .private_at (CONTRACT_DEPLOYED_AT );
123
+
124
+ let context_at_block_before_initialization = env .private_at (CONTRACT_INITIALIZED_AT - 1 );
125
+ let context_at_block_of_initialization = env .private_at (CONTRACT_INITIALIZED_AT );
116
126
117
127
// We prove that the contract had not been deployed nor initialized at the block before deployment
118
- header_at_block_before_deployment .prove_contract_non_deployment (contract_address );
119
- header_at_block_before_deployment .prove_contract_non_initialization (contract_address );
128
+ context_at_block_before_deployment .historical_header .prove_contract_non_deployment (
129
+ contract_address ,
130
+ );
131
+ context_at_block_before_initialization .historical_header .prove_contract_non_initialization (
132
+ contract_address ,
133
+ );
120
134
121
135
// And we prove that the contract has been been deployed and initialized at the block after deployment
122
- current_header .prove_contract_deployment (contract_address );
123
- current_header .prove_contract_initialization (contract_address );
136
+ context_at_block_of_deployment .historical_header .prove_contract_deployment (contract_address );
137
+ context_at_block_of_initialization .historical_header .prove_contract_initialization (
138
+ contract_address ,
139
+ );
124
140
}
125
141
126
142
// In this test, we fail to prove contract deployment at the block before it was deployed. This checks for inclusion
@@ -129,42 +145,38 @@ unconstrained fn contract_historical_proofs_happy_path() {
129
145
unconstrained fn proving_contract_deployment_fails () {
130
146
let (env , contract_address ) = setup ();
131
147
132
- let context = env .private ();
133
- let header_at_block_before_deployment = context .get_block_header_at (2 );
148
+ let context = env .private_at (CONTRACT_DEPLOYED_AT - 1 );
134
149
135
- header_at_block_before_deployment .prove_contract_deployment (contract_address );
150
+ context . historical_header .prove_contract_deployment (contract_address );
136
151
}
137
152
138
153
// In this test, we fail to prove contract initialization at the block before it was deployed. This checks for inclusion
139
154
// of the initialization nullifier in state.
140
- #[test(should_fail_with = "Nullifier membership witness not found at block 2 .")]
155
+ #[test(should_fail_with = "Nullifier membership witness not found at block 3 .")]
141
156
unconstrained fn proving_contract_initialization_fails () {
142
157
let (env , contract_address ) = setup ();
143
158
144
- let context = env .private ();
145
- let header_at_block_before_deployment = context .get_block_header_at (2 );
159
+ let context = env .private_at (CONTRACT_INITIALIZED_AT - 1 );
146
160
147
- header_at_block_before_deployment .prove_contract_initialization (contract_address );
161
+ context . historical_header .prove_contract_initialization (contract_address );
148
162
}
149
163
150
- // In this test, we fail to prove contract non-deployment at the block after it was deployed .
164
+ // In this test, we fail to prove contract non-deployment at the block of its deployment .
151
165
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
152
166
unconstrained fn proving_contract_non_deployment_fails () {
153
167
let (env , contract_address ) = setup ();
154
168
155
- let context = env .private ();
156
- let current_header = context .historical_header ;
169
+ let context = env .private_at (CONTRACT_DEPLOYED_AT );
157
170
158
- current_header .prove_contract_non_deployment (contract_address );
171
+ context . historical_header .prove_contract_non_deployment (contract_address );
159
172
}
160
173
161
- // In this test, we fail to prove contract non-initialization at the block after it was deployed .
174
+ // In this test, we fail to prove contract non-initialization at the block of its deployment .
162
175
#[test(should_fail_with = "Proving nullifier non-inclusion failed")]
163
176
unconstrained fn proving_contract_non_initialization_fails () {
164
177
let (env , contract_address ) = setup ();
165
178
166
- let context = env .private ();
167
- let current_header = context .historical_header ;
179
+ let context = env .private_at (CONTRACT_INITIALIZED_AT );
168
180
169
- current_header .prove_contract_non_initialization (contract_address );
181
+ context . historical_header .prove_contract_non_initialization (contract_address );
170
182
}
0 commit comments