@@ -7,7 +7,7 @@ use anyhow::{Result, ensure};
7
7
use blockifier:: execution:: contract_class:: TrackedResource ;
8
8
use blockifier:: execution:: entry_point:: EntryPointExecutionContext ;
9
9
use blockifier:: state:: cached_state:: CachedState ;
10
- use cairo_lang_runner:: { Arg , RunResult , SierraCasmRunner } ;
10
+ use cairo_lang_runner:: { Arg , RunResultValue , SierraCasmRunner } ;
11
11
use cairo_lang_sierra:: extensions:: NamedType ;
12
12
use cairo_lang_sierra:: extensions:: bitwise:: BitwiseType ;
13
13
use cairo_lang_sierra:: extensions:: circuit:: { AddModType , MulModType } ;
@@ -97,7 +97,6 @@ pub fn run_test(
97
97
extract_test_case_summary (
98
98
run_result,
99
99
& case,
100
- vec ! [ ] ,
101
100
& test_runner_config. contracts_data ,
102
101
& versioned_program_path,
103
102
)
@@ -138,29 +137,54 @@ pub(crate) fn run_fuzz_test(
138
137
extract_test_case_summary (
139
138
run_result,
140
139
& case,
141
- vec ! [ ] ,
142
140
& test_runner_config. contracts_data ,
143
141
& versioned_program_path,
144
142
)
145
143
} )
146
144
}
147
145
148
- pub struct RunResultWithInfo {
149
- pub ( crate ) run_result : Result < RunResult , Box < CairoRunError > > ,
146
+ pub enum RunStatus {
147
+ Success ( Vec < Felt252 > ) ,
148
+ Panic ( Vec < Felt252 > ) ,
149
+ }
150
+
151
+ impl From < RunResultValue > for RunStatus {
152
+ fn from ( value : RunResultValue ) -> Self {
153
+ match value {
154
+ RunResultValue :: Success ( value) => Self :: Success ( value) ,
155
+ RunResultValue :: Panic ( value) => Self :: Panic ( value) ,
156
+ }
157
+ }
158
+ }
159
+
160
+ pub struct RunCompleted {
161
+ pub ( crate ) status : RunStatus ,
150
162
pub ( crate ) call_trace : Rc < RefCell < CallTrace > > ,
151
163
pub ( crate ) gas_used : GasVector ,
152
164
pub ( crate ) used_resources : UsedResources ,
153
165
pub ( crate ) encountered_errors : EncounteredErrors ,
154
166
pub ( crate ) fuzzer_args : Vec < String > ,
155
167
}
156
168
169
+ pub struct RunError {
170
+ pub ( crate ) error : Box < CairoRunError > ,
171
+ pub ( crate ) call_trace : Rc < RefCell < CallTrace > > ,
172
+ pub ( crate ) encountered_errors : EncounteredErrors ,
173
+ pub ( crate ) fuzzer_args : Vec < String > ,
174
+ }
175
+
176
+ pub enum RunResult {
177
+ Completed ( Box < RunCompleted > ) ,
178
+ Error ( RunError ) ,
179
+ }
180
+
157
181
#[ expect( clippy:: too_many_lines) ]
158
182
pub fn run_test_case (
159
183
case : & TestCaseWithResolvedConfig ,
160
184
casm_program : & AssembledProgramWithDebugInfo ,
161
185
runtime_config : & RuntimeConfig ,
162
186
fuzzer_rng : Option < Arc < Mutex < StdRng > > > ,
163
- ) -> Result < RunResultWithInfo > {
187
+ ) -> Result < RunResult > {
164
188
ensure ! (
165
189
case. config
166
190
. available_gas
@@ -255,7 +279,7 @@ pub fn run_test_case(
255
279
256
280
let ap = runner. relocated_trace . as_ref ( ) . unwrap ( ) . last ( ) . unwrap ( ) . ap ;
257
281
258
- let ( results_data, gas_counter ) = get_results_data (
282
+ let results_data = get_results_data (
259
283
& case. test_details . return_types ,
260
284
& runner. relocated_memory ,
261
285
ap,
@@ -274,7 +298,7 @@ pub fn run_test_case(
274
298
275
299
update_top_call_vm_trace ( & mut forge_runtime, & mut runner) ;
276
300
277
- Ok ( ( gas_counter , runner . relocated_memory , value) )
301
+ Ok ( value)
278
302
}
279
303
Err ( err) => Err ( err) ,
280
304
} ;
@@ -287,7 +311,7 @@ pub fn run_test_case(
287
311
. encountered_errors
288
312
. clone ( ) ;
289
313
290
- let call_trace_ref = get_call_trace_ref ( & mut forge_runtime) ;
314
+ let call_trace = get_call_trace_ref ( & mut forge_runtime) ;
291
315
292
316
update_top_call_resources ( & mut forge_runtime, & tracked_resource) ;
293
317
update_top_call_l1_resources ( & mut forge_runtime) ;
@@ -303,25 +327,27 @@ pub fn run_test_case(
303
327
let transaction_context = get_context ( & forge_runtime) . tx_context . clone ( ) ;
304
328
let used_resources =
305
329
get_all_used_resources ( forge_runtime, & transaction_context, tracked_resource) ;
306
- let gas = calculate_used_gas (
330
+ let gas_used = calculate_used_gas (
307
331
& transaction_context,
308
332
& mut cached_state,
309
333
used_resources. clone ( ) ,
310
334
) ?;
311
335
312
- Ok ( RunResultWithInfo {
313
- run_result : run_result. map ( |( gas_counter, memory, value) | RunResult {
314
- used_resources : used_resources. execution_resources . clone ( ) ,
315
- gas_counter,
316
- memory,
317
- value,
318
- profiling_info : None ,
336
+ Ok ( match run_result {
337
+ Ok ( result) => RunResult :: Completed ( Box :: from ( RunCompleted {
338
+ status : result. into ( ) ,
339
+ call_trace,
340
+ gas_used,
341
+ used_resources,
342
+ encountered_errors,
343
+ fuzzer_args,
344
+ } ) ) ,
345
+ Err ( error) => RunResult :: Error ( RunError {
346
+ error,
347
+ call_trace,
348
+ encountered_errors,
349
+ fuzzer_args,
319
350
} ) ,
320
- gas_used : gas,
321
- used_resources,
322
- call_trace : call_trace_ref,
323
- encountered_errors,
324
- fuzzer_args,
325
351
} )
326
352
}
327
353
@@ -333,7 +359,7 @@ pub fn get_results_data(
333
359
return_types : & [ ( GenericTypeId , i16 ) ] ,
334
360
cells : & [ Option < Felt252 > ] ,
335
361
mut ap : usize ,
336
- ) -> ( Vec < ( GenericTypeId , Vec < Felt252 > ) > , Option < Felt252 > ) {
362
+ ) -> Vec < ( GenericTypeId , Vec < Felt252 > ) > {
337
363
let mut results_data = vec ! [ ] ;
338
364
for ( ty, ty_size) in return_types. iter ( ) . rev ( ) {
339
365
let size = * ty_size as usize ;
@@ -345,11 +371,10 @@ pub fn get_results_data(
345
371
}
346
372
347
373
// Handling implicits.
348
- let mut gas_counter = None ;
349
374
results_data. retain_mut ( |( ty, values) | {
350
375
let generic_ty = ty;
351
376
if * generic_ty == GasBuiltinType :: ID {
352
- gas_counter = Some ( values. remove ( 0 ) ) ;
377
+ values. remove ( 0 ) ;
353
378
assert ! ( values. is_empty( ) ) ;
354
379
false
355
380
} else {
@@ -372,73 +397,60 @@ pub fn get_results_data(
372
397
}
373
398
} ) ;
374
399
375
- ( results_data, gas_counter )
400
+ results_data
376
401
}
377
402
378
403
fn extract_test_case_summary (
379
- run_result : Result < RunResultWithInfo > ,
404
+ run_result : Result < RunResult > ,
380
405
case : & TestCaseWithResolvedConfig ,
381
- args : Vec < Felt > ,
382
406
contracts_data : & ContractsData ,
383
407
versioned_program_path : & Utf8Path ,
384
408
) -> TestCaseSummary < Single > {
385
409
match run_result {
386
- Ok ( result_with_info) => {
387
- match result_with_info. run_result {
388
- Ok ( run_result) => TestCaseSummary :: from_run_result_and_info (
389
- run_result,
390
- case,
391
- args,
392
- result_with_info. fuzzer_args ,
393
- result_with_info. gas_used ,
394
- result_with_info. used_resources ,
395
- & result_with_info. call_trace ,
396
- & result_with_info. encountered_errors ,
397
- contracts_data,
398
- versioned_program_path,
399
- ) ,
400
- // CairoRunError comes from VirtualMachineError which may come from HintException that originates in TestExecutionSyscallHandler
401
- Err ( error) => {
402
- let mut message = format ! (
403
- "\n {}\n " ,
404
- error. to_string( ) . replace( " Custom Hint Error: " , "\n " )
405
- ) ;
406
- if let CairoRunError :: VirtualMachine ( VirtualMachineError :: UnfinishedExecution ) =
407
- * error
408
- {
409
- message. push_str (
410
- "\n Suggestion: Consider using the flag `--max-n-steps` to increase allowed limit of steps" ,
411
- ) ;
412
- }
413
- TestCaseSummary :: Failed {
414
- name : case. name . clone ( ) ,
415
- msg : Some ( message) . map ( |msg| {
416
- add_backtrace_footer (
417
- msg,
418
- contracts_data,
419
- & result_with_info. encountered_errors ,
420
- )
421
- } ) ,
422
- arguments : args,
423
- fuzzer_args : result_with_info. fuzzer_args ,
424
- test_statistics : ( ) ,
425
- debugging_trace : cfg ! ( feature = "debugging" ) . then ( || {
426
- debugging:: Trace :: new (
427
- & result_with_info. call_trace . borrow ( ) ,
428
- contracts_data,
429
- case. name . clone ( ) ,
430
- )
431
- } ) ,
432
- }
410
+ Ok ( run_result) => match run_result {
411
+ RunResult :: Completed ( run_completed) => TestCaseSummary :: from_run_completed (
412
+ * run_completed,
413
+ case,
414
+ contracts_data,
415
+ versioned_program_path,
416
+ ) ,
417
+ RunResult :: Error ( run_error) => {
418
+ let mut message = format ! (
419
+ "\n {}\n " ,
420
+ run_error
421
+ . error
422
+ . to_string( )
423
+ . replace( " Custom Hint Error: " , "\n " )
424
+ ) ;
425
+ if let CairoRunError :: VirtualMachine ( VirtualMachineError :: UnfinishedExecution ) =
426
+ * run_error. error
427
+ {
428
+ message. push_str (
429
+ "\n Suggestion: Consider using the flag `--max-n-steps` to increase allowed limit of steps" ,
430
+ ) ;
431
+ }
432
+ TestCaseSummary :: Failed {
433
+ name : case. name . clone ( ) ,
434
+ msg : Some ( message) . map ( |msg| {
435
+ add_backtrace_footer ( msg, contracts_data, & run_error. encountered_errors )
436
+ } ) ,
437
+ fuzzer_args : run_error. fuzzer_args ,
438
+ test_statistics : ( ) ,
439
+ debugging_trace : cfg ! ( feature = "debugging" ) . then ( || {
440
+ debugging:: Trace :: new (
441
+ & run_error. call_trace . borrow ( ) ,
442
+ contracts_data,
443
+ case. name . clone ( ) ,
444
+ )
445
+ } ) ,
433
446
}
434
447
}
435
- }
448
+ } ,
436
449
// `ForkStateReader.get_block_info`, `get_fork_state_reader, `calculate_used_gas` may return an error
437
450
// `available_gas` may be specified with Scarb ~2.4
438
451
Err ( error) => TestCaseSummary :: Failed {
439
452
name : case. name . clone ( ) ,
440
453
msg : Some ( error. to_string ( ) ) ,
441
- arguments : args,
442
454
fuzzer_args : Vec :: default ( ) ,
443
455
test_statistics : ( ) ,
444
456
debugging_trace : None ,
0 commit comments