@@ -160,96 +160,98 @@ pub struct Expectations {
160
160
161
161
impl Expectations {
162
162
fn reset ( & mut self ) {
163
+ self . skip_verification_on_drop = true ;
163
164
* self = Default :: default ( ) ;
164
165
}
165
166
166
167
fn verify ( & mut self ) {
167
- assert ! ( !self . expect_validate_caller_any, "expected ValidateCallerAny, not received" ) ;
168
+ // If we don't reset them, we'll try to re-verify on drop. If something fails, we'll panic
169
+ // twice and abort making the tests difficult to debug.
170
+ self . skip_verification_on_drop = true ;
171
+ let this = std:: mem:: take ( self ) ;
172
+
173
+ assert ! ( !this. expect_validate_caller_any, "expected ValidateCallerAny, not received" ) ;
168
174
assert ! (
169
- self . expect_validate_caller_addr. is_none( ) ,
175
+ this . expect_validate_caller_addr. is_none( ) ,
170
176
"expected ValidateCallerAddr {:?}, not received" ,
171
- self . expect_validate_caller_addr
177
+ this . expect_validate_caller_addr
172
178
) ;
173
179
assert ! (
174
- self . expect_validate_caller_type. is_none( ) ,
180
+ this . expect_validate_caller_type. is_none( ) ,
175
181
"expected ValidateCallerType {:?}, not received" ,
176
- self . expect_validate_caller_type
182
+ this . expect_validate_caller_type
177
183
) ;
178
184
assert ! (
179
- self . expect_sends. is_empty( ) ,
185
+ this . expect_sends. is_empty( ) ,
180
186
"expected all message to be send, unsent messages {:?}" ,
181
- self . expect_sends
187
+ this . expect_sends
182
188
) ;
183
189
assert ! (
184
- self . expect_create_actor. is_none( ) ,
190
+ this . expect_create_actor. is_none( ) ,
185
191
"expected actor to be created, uncreated actor: {:?}" ,
186
- self . expect_create_actor
192
+ this . expect_create_actor
187
193
) ;
188
194
assert ! (
189
- self . expect_delete_actor. is_none( ) ,
195
+ this . expect_delete_actor. is_none( ) ,
190
196
"expected actor to be deleted: {:?}" ,
191
- self . expect_delete_actor
197
+ this . expect_delete_actor
192
198
) ;
193
199
assert ! (
194
- self . expect_verify_sigs. is_empty( ) ,
200
+ this . expect_verify_sigs. is_empty( ) ,
195
201
"expect_verify_sigs: {:?}, not received" ,
196
- self . expect_verify_sigs
202
+ this . expect_verify_sigs
197
203
) ;
198
204
assert ! (
199
- self . expect_verify_seal. is_none( ) ,
205
+ this . expect_verify_seal. is_none( ) ,
200
206
"expect_verify_seal {:?}, not received" ,
201
- self . expect_verify_seal
207
+ this . expect_verify_seal
202
208
) ;
203
209
assert ! (
204
- self . expect_verify_post. is_none( ) ,
210
+ this . expect_verify_post. is_none( ) ,
205
211
"expect_verify_post {:?}, not received" ,
206
- self . expect_verify_post
212
+ this . expect_verify_post
207
213
) ;
208
214
assert ! (
209
- self . expect_compute_unsealed_sector_cid. is_empty( ) ,
215
+ this . expect_compute_unsealed_sector_cid. is_empty( ) ,
210
216
"expect_compute_unsealed_sector_cid: {:?}, not received" ,
211
- self . expect_compute_unsealed_sector_cid
217
+ this . expect_compute_unsealed_sector_cid
212
218
) ;
213
219
assert ! (
214
- self . expect_verify_consensus_fault. is_none( ) ,
220
+ this . expect_verify_consensus_fault. is_none( ) ,
215
221
"expect_verify_consensus_fault {:?}, not received" ,
216
- self . expect_verify_consensus_fault
222
+ this . expect_verify_consensus_fault
217
223
) ;
218
224
assert ! (
219
- self . expect_get_randomness_tickets. is_empty( ) ,
225
+ this . expect_get_randomness_tickets. is_empty( ) ,
220
226
"expect_get_randomness_tickets {:?}, not received" ,
221
- self . expect_get_randomness_tickets
227
+ this . expect_get_randomness_tickets
222
228
) ;
223
229
assert ! (
224
- self . expect_get_randomness_beacon. is_empty( ) ,
230
+ this . expect_get_randomness_beacon. is_empty( ) ,
225
231
"expect_get_randomness_beacon {:?}, not received" ,
226
- self . expect_get_randomness_beacon
232
+ this . expect_get_randomness_beacon
227
233
) ;
228
234
assert ! (
229
- self . expect_batch_verify_seals. is_none( ) ,
235
+ this . expect_batch_verify_seals. is_none( ) ,
230
236
"expect_batch_verify_seals {:?}, not received" ,
231
- self . expect_batch_verify_seals
237
+ this . expect_batch_verify_seals
232
238
) ;
233
239
assert ! (
234
- self . expect_aggregate_verify_seals. is_none( ) ,
240
+ this . expect_aggregate_verify_seals. is_none( ) ,
235
241
"expect_aggregate_verify_seals {:?}, not received" ,
236
- self . expect_aggregate_verify_seals
242
+ this . expect_aggregate_verify_seals
237
243
) ;
238
244
assert ! (
239
- self . expect_replica_verify. is_none( ) ,
245
+ this . expect_replica_verify. is_none( ) ,
240
246
"expect_replica_verify {:?}, not received" ,
241
- self . expect_replica_verify
247
+ this . expect_replica_verify
242
248
) ;
243
249
assert ! (
244
- self . expect_gas_charge. is_empty( ) ,
250
+ this . expect_gas_charge. is_empty( ) ,
245
251
"expect_gas_charge {:?}, not received" ,
246
- self . expect_gas_charge
252
+ this . expect_gas_charge
247
253
) ;
248
254
}
249
-
250
- fn skip_verification_on_drop ( & mut self ) {
251
- self . skip_verification_on_drop = true ;
252
- }
253
255
}
254
256
255
257
impl Default for MockRuntime {
@@ -467,14 +469,13 @@ impl<BS: Blockstore> MockRuntime<BS> {
467
469
res
468
470
}
469
471
470
- /// Verifies that all mock expectations have been met.
472
+ /// Verifies that all mock expectations have been met (and resets the expectations) .
471
473
pub fn verify ( & mut self ) {
472
474
self . expectations . borrow_mut ( ) . verify ( )
473
475
}
474
476
475
477
/// Clears all mock expectations.
476
478
pub fn reset ( & mut self ) {
477
- self . expectations . borrow_mut ( ) . skip_verification_on_drop ( ) ;
478
479
self . expectations . borrow_mut ( ) . reset ( ) ;
479
480
}
480
481
0 commit comments