@@ -88,9 +88,25 @@ pub(crate) struct TestParameters {
88
88
pub ( crate ) messages_to_l2 : Vec < MessageToL2 > ,
89
89
}
90
90
91
- pub ( crate ) struct FlowTestTx {
92
- tx : BlockifierTransaction ,
93
- revert_reason : Option < String > ,
91
+ pub ( crate ) enum FlowTestTx {
92
+ Successful ( BlockifierTransaction ) ,
93
+ Reverted { tx : BlockifierTransaction , revert_reason : String } ,
94
+ }
95
+
96
+ impl FlowTestTx {
97
+ pub ( crate ) fn tx ( & self ) -> & BlockifierTransaction {
98
+ match self {
99
+ FlowTestTx :: Successful ( tx) => tx,
100
+ FlowTestTx :: Reverted { tx, .. } => tx,
101
+ }
102
+ }
103
+
104
+ pub ( crate ) fn revert_reason ( & self ) -> Option < & String > {
105
+ match self {
106
+ FlowTestTx :: Reverted { revert_reason, .. } => Some ( revert_reason) ,
107
+ FlowTestTx :: Successful ( _) => None ,
108
+ }
109
+ }
94
110
}
95
111
96
112
/// Manages the execution of flow tests by maintaining the initial state and transactions.
@@ -293,12 +309,11 @@ impl<S: FlowTestState> TestManager<S> {
293
309
else {
294
310
panic ! ( "Expected a V1 contract class" ) ;
295
311
} ;
296
- self . last_block_txs_mut ( ) . push ( FlowTestTx {
297
- tx : BlockifierTransaction :: new_for_sequencing ( StarknetApiTransaction :: Account (
312
+ self . last_block_txs_mut ( ) . push ( FlowTestTx :: Successful (
313
+ BlockifierTransaction :: new_for_sequencing ( StarknetApiTransaction :: Account (
298
314
AccountTransaction :: Declare ( tx) ,
299
315
) ) ,
300
- revert_reason : None ,
301
- } ) ;
316
+ ) ) ;
302
317
303
318
self . execution_contracts
304
319
. declared_class_hash_to_component_hashes
@@ -311,11 +326,16 @@ impl<S: FlowTestState> TestManager<S> {
311
326
}
312
327
313
328
pub ( crate ) fn add_invoke_tx ( & mut self , tx : InvokeTransaction , revert_reason : Option < String > ) {
314
- self . last_block_txs_mut ( ) . push ( FlowTestTx {
315
- tx : BlockifierTransaction :: new_for_sequencing ( StarknetApiTransaction :: Account (
316
- AccountTransaction :: Invoke ( tx) ,
329
+ self . last_block_txs_mut ( ) . push ( match revert_reason {
330
+ Some ( revert_reason) => FlowTestTx :: Reverted {
331
+ tx : BlockifierTransaction :: new_for_sequencing ( StarknetApiTransaction :: Account (
332
+ AccountTransaction :: Invoke ( tx) ,
333
+ ) ) ,
334
+ revert_reason,
335
+ } ,
336
+ None => FlowTestTx :: Successful ( BlockifierTransaction :: new_for_sequencing (
337
+ StarknetApiTransaction :: Account ( AccountTransaction :: Invoke ( tx) ) ,
317
338
) ) ,
318
- revert_reason,
319
339
} ) ;
320
340
}
321
341
@@ -339,35 +359,40 @@ impl<S: FlowTestState> TestManager<S> {
339
359
let ContractClass :: V0 ( class) = tx. class_info . contract_class . clone ( ) else {
340
360
panic ! ( "Expected a V0 contract class" ) ;
341
361
} ;
342
- self . last_block_txs_mut ( ) . push ( FlowTestTx {
343
- tx : BlockifierTransaction :: new_for_sequencing ( StarknetApiTransaction :: Account (
362
+ self . last_block_txs_mut ( ) . push ( FlowTestTx :: Successful (
363
+ BlockifierTransaction :: new_for_sequencing ( StarknetApiTransaction :: Account (
344
364
AccountTransaction :: Declare ( tx) ,
345
365
) ) ,
346
- revert_reason : None ,
347
- } ) ;
366
+ ) ) ;
348
367
self . execution_contracts
349
368
. executed_contracts
350
369
. deprecated_contracts
351
370
. insert ( compiled_class_hash, class) ;
352
371
}
353
372
354
373
pub ( crate ) fn add_deploy_account_tx ( & mut self , tx : DeployAccountTransaction ) {
355
- self . last_block_txs_mut ( ) . push ( FlowTestTx {
356
- tx : BlockifierTransaction :: new_for_sequencing ( StarknetApiTransaction :: Account (
374
+ self . last_block_txs_mut ( ) . push ( FlowTestTx :: Successful (
375
+ BlockifierTransaction :: new_for_sequencing ( StarknetApiTransaction :: Account (
357
376
AccountTransaction :: DeployAccount ( tx) ,
358
377
) ) ,
359
- revert_reason : None ,
360
- } ) ;
378
+ ) ) ;
361
379
}
362
380
363
381
pub ( crate ) fn add_l1_handler_tx (
364
382
& mut self ,
365
383
tx : L1HandlerTransaction ,
366
384
revert_reason : Option < String > ,
367
385
) {
368
- self . last_block_txs_mut ( ) . push ( FlowTestTx {
369
- tx : BlockifierTransaction :: new_for_sequencing ( StarknetApiTransaction :: L1Handler ( tx) ) ,
370
- revert_reason,
386
+ self . last_block_txs_mut ( ) . push ( match revert_reason {
387
+ Some ( revert_reason) => FlowTestTx :: Reverted {
388
+ tx : BlockifierTransaction :: new_for_sequencing ( StarknetApiTransaction :: L1Handler (
389
+ tx,
390
+ ) ) ,
391
+ revert_reason,
392
+ } ,
393
+ None => FlowTestTx :: Successful ( BlockifierTransaction :: new_for_sequencing (
394
+ StarknetApiTransaction :: L1Handler ( tx) ,
395
+ ) ) ,
371
396
} ) ;
372
397
}
373
398
@@ -536,7 +561,10 @@ impl<S: FlowTestState> TestManager<S> {
536
561
{
537
562
let ( block_txs, revert_reasons) : ( Vec < _ > , Vec < _ > ) = block_txs_with_reason
538
563
. into_iter ( )
539
- . map ( |flow_test_tx| ( flow_test_tx. tx , flow_test_tx. revert_reason ) )
564
+ . map ( |flow_test_tx| match flow_test_tx {
565
+ FlowTestTx :: Successful ( tx) => ( tx, None ) ,
566
+ FlowTestTx :: Reverted { tx, revert_reason } => ( tx, Some ( revert_reason) ) ,
567
+ } )
540
568
. unzip ( ) ;
541
569
// Clone the block info for later use.
542
570
let block_info = block_context. block_info ( ) . clone ( ) ;
0 commit comments