Skip to content

Commit 166e8c1

Browse files
blockifier: extend revert test to check reverted events and messages (#11696)
1 parent 3a2ef85 commit 166e8c1

File tree

7 files changed

+6982
-6836
lines changed

7 files changed

+6982
-6836
lines changed

crates/blockifier/src/bouncer_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,11 +775,11 @@ fn class_hash_migration_data_from_state(
775775

776776
if should_migrate {
777777
expect![[r#"
778-
105191950
778+
105350389
779779
"#]]
780780
.assert_debug_eq(&migration_sierra_gas.0);
781781
expect![[r#"
782-
254015006
782+
254431248
783783
"#]]
784784
.assert_debug_eq(&migration_proving_gas.0);
785785
} else {

crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,17 +504,20 @@ fn test_empty_function_flow(#[case] runnable: RunnableCairo1) {
504504
assert!(!call_info.execution.failed);
505505
}
506506

507-
/// Test that storage is correctly reverted when nested calls write to the same key.
507+
/// Test that storage, events, and L1 messages are correctly reverted when nested calls write to
508+
/// the same key.
508509
///
509510
/// Scenario:
510511
/// - catch_write_revert_panic calls call_write_rewrite_panic and catches/ignores the revert
511512
/// - call_write_rewrite_panic calls write_1, then writes storage = 2, then panics
512-
/// - write_1 writes storage = 1
513+
/// - write_1 writes storage = 1, emits a dummy event, and sends a dummy L1 message
513514
///
514515
/// After call_write_rewrite_panic's revert, storage should be 0 (original), not 1 (write_1's
515516
/// write). This tests the fix for a bug where call_write_rewrite_panic would capture write_1's
516517
/// written value (1) as the "original" instead of the true original (0), causing incorrect state
517518
/// after revert.
519+
///
520+
/// Additionally, verifies that events and L1 messages emitted in write_1 are also reverted.
518521
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native; "Native"))]
519522
#[test_case(RunnableCairo1::Casm; "VM")]
520523
fn test_nested_call_storage_revert(runnable_version: RunnableCairo1) {
@@ -528,7 +531,7 @@ fn test_nested_call_storage_revert(runnable_version: RunnableCairo1) {
528531
// Call catch_write_revert_panic which:
529532
// 1. Calls call_write_rewrite_panic
530533
// 2. call_write_rewrite_panic calls write_1
531-
// 3. write_1 writes storage = 1
534+
// 3. write_1 writes storage = 1, emits an event, and sends an L1 message
532535
// 4. call_write_rewrite_panic writes storage = 2
533536
// 5. call_write_rewrite_panic panics (gets reverted)
534537
// 6. catch_write_revert_panic catches the revert and reads storage (should be 0)
@@ -554,4 +557,18 @@ fn test_nested_call_storage_revert(runnable_version: RunnableCairo1) {
554557
// Double-check by reading storage directly.
555558
let final_value = state.get_storage_at(contract_address, storage_key).unwrap();
556559
assert_eq!(final_value, felt!(0_u8), "Storage should be 0 after revert");
560+
561+
// Verify that events and L1 messages are reverted across the entire call hierarchy.
562+
// write_1 emits an event and sends an L1 message, but these should be cleared because
563+
// its parent (call_write_rewrite_panic) panicked.
564+
let events = call_info.get_sorted_events();
565+
let messages = call_info.get_sorted_l2_to_l1_messages();
566+
assert!(
567+
events.is_empty(),
568+
"All events should be reverted across the call hierarchy; got {events:?}."
569+
);
570+
assert!(
571+
messages.is_empty(),
572+
"All L1 messages should be reverted across the call hierarchy; got {messages:?}."
573+
);
557574
}

0 commit comments

Comments
 (0)