33//! This test suite covers the behavior of the rollup node when consuming events from L1
44//! in different sync states, handling reorgs, and recovering from shutdowns.
55//!
6- //! Related to: https://github.com/scroll-tech/rollup-node/issues/420
6+ //! Related to: < https://github.com/scroll-tech/rollup-node/issues/420>
77
88use alloy_primitives:: Bytes ;
99use rollup_node:: test_utils:: { EventAssertions , TestFixture } ;
1010use serde_json:: Value ;
1111
12-
13- /// Helper to read transaction from test_transactions.json
12+ /// Helper to read transaction from `test_transactions.json`
1413fn read_test_transaction ( tx_type : & str , index : & str ) -> eyre:: Result < Bytes > {
1514 let tx_json_path = "./tests/testdata/test_transactions.json" ;
1615 let tx_json_content = std:: fs:: read_to_string ( tx_json_path)
@@ -43,18 +42,18 @@ fn read_test_transaction(tx_type: &str, index: &str) -> eyre::Result<Bytes> {
4342// Test Suite 1: Correct behavior when consuming events from L1
4443// =============================================================================
4544
46- /// Test: BatchCommit during Syncing state should have no effect.
45+ /// Test: ` BatchCommit` during Syncing state should have no effect.
4746///
4847/// Expected: The node should not update the safe head since we only process
49- /// BatchCommit eventds after the node is synced (post L1Synced notification).
48+ /// ` BatchCommit` eventds after the node is synced (post ` L1Synced` notification).
5049#[ tokio:: test]
5150async fn test_l1_sync_batch_commit ( ) -> eyre:: Result < ( ) > {
5251 reth_tracing:: init_test_tracing ( ) ;
5352
5453 let mut fixture = TestFixture :: builder ( )
5554 . followers ( 1 )
5655 . skip_l1_synced_notifications ( )
57- . with_anvil_default_state ( )
56+ . with_anvil ( )
5857 . with_anvil_chain_id ( 22222222 )
5958 . build ( )
6059 . await ?;
@@ -94,15 +93,14 @@ async fn test_l1_sync_batch_commit() -> eyre::Result<()> {
9493 Ok ( ( ) )
9594}
9695
97-
9896#[ tokio:: test]
9997async fn test_l1_sync_batch_finalized ( ) -> eyre:: Result < ( ) > {
10098 reth_tracing:: init_test_tracing ( ) ;
10199
102100 let mut fixture = TestFixture :: builder ( )
103101 . followers ( 1 )
104102 . skip_l1_synced_notifications ( )
105- . with_anvil_default_state ( )
103+ . with_anvil ( )
106104 . with_anvil_chain_id ( 22222222 )
107105 . build ( )
108106 . await ?;
@@ -173,11 +171,13 @@ async fn test_l1_sync_batch_finalized() -> eyre::Result<()> {
173171 // Check that finalized head was updated
174172 let batch_finalized_status = fixture. get_sequencer_status ( ) . await ?;
175173 assert ! (
176- batch_finalized_status. l2. fcs. safe_block_info( ) . number == l1_synced_status. l2. fcs. safe_block_info( ) . number,
174+ batch_finalized_status. l2. fcs. safe_block_info( ) . number ==
175+ l1_synced_status. l2. fcs. safe_block_info( ) . number,
177176 "Safe head should not advance after BatchFinalized event when L1 Synced"
178177 ) ;
179178 assert ! (
180- batch_finalized_status. l2. fcs. finalized_block_info( ) . number > l1_synced_status. l2. fcs. finalized_block_info( ) . number,
179+ batch_finalized_status. l2. fcs. finalized_block_info( ) . number >
180+ l1_synced_status. l2. fcs. finalized_block_info( ) . number,
181181 "Finalized head should advance after BatchFinalized event when L1 Synced"
182182 ) ;
183183
@@ -191,7 +191,7 @@ async fn test_l1_sync_batch_revert() -> eyre::Result<()> {
191191 let mut fixture = TestFixture :: builder ( )
192192 . followers ( 1 )
193193 . skip_l1_synced_notifications ( )
194- . with_anvil_default_state ( )
194+ . with_anvil ( )
195195 . with_anvil_chain_id ( 22222222 )
196196 . build ( )
197197 . await ?;
@@ -206,10 +206,11 @@ async fn test_l1_sync_batch_revert() -> eyre::Result<()> {
206206 fixture. anvil_send_raw_transaction ( commit_batch_tx) . await ?;
207207 }
208208
209+ fixture. anvil_mine_blocks ( 64 ) . await ?;
210+
211+ // Trigger L1 synced event
209212 fixture. l1 ( ) . sync ( ) . await ?;
210213 fixture. expect_event ( ) . l1_synced ( ) . await ?;
211- fixture. expect_event ( ) . batch_consolidated ( ) . await ?;
212- fixture. anvil_mine_blocks ( 64 ) . await ?;
213214
214215 // Wait for l1 blocks to be processed
215216 tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 3 ) ) . await ;
@@ -218,13 +219,13 @@ async fn test_l1_sync_batch_revert() -> eyre::Result<()> {
218219 let new_status = fixture. get_sequencer_status ( ) . await ?;
219220 assert ! (
220221 new_status. l2. fcs. safe_block_info( ) . number > initial_safe,
221- "Safe head should advance after BatchCommit when synced and L1Synced"
222+ "Safe head should advance after BatchCommit when L1Synced"
222223 ) ;
223224
224225 // Send BatchRevert transactions
225226 let revert_batch_tx = read_test_transaction ( "revertBatch" , "0" ) ?;
226227 fixture. anvil_send_raw_transaction ( revert_batch_tx) . await ?;
227- fixture. anvil_mine_blocks ( 64 ) . await ?;
228+ fixture. anvil_mine_blocks ( 10 ) . await ?;
228229
229230 // Wait for l1 blocks to be processed
230231 tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 3 ) ) . await ;
@@ -243,18 +244,18 @@ async fn test_l1_sync_batch_revert() -> eyre::Result<()> {
243244// Test Suite 2: L1 Reorg handling for different batch events
244245// =============================================================================
245246
246- /// Test: L1 reorg of BatchCommit after L1Synced.
247+ /// Test: L1 reorg of ` BatchCommit` after ` L1Synced` .
247248///
248- /// Expected: When a BatchCommit is reorged after the node has synced (L1Synced),
249- /// the safe head should revert to the last block of the previous BatchCommit.
249+ /// Expected: When a ` BatchCommit` is reorged after the node has synced (` L1Synced` ),
250+ /// the safe head should revert to the last block of the previous ` BatchCommit` .
250251#[ tokio:: test]
251252async fn test_l1_reorg_batch_commit ( ) -> eyre:: Result < ( ) > {
252253 reth_tracing:: init_test_tracing ( ) ;
253254
254255 let mut fixture = TestFixture :: builder ( )
255256 . followers ( 1 )
256257 . skip_l1_synced_notifications ( )
257- . with_anvil_default_state ( )
258+ . with_anvil ( )
258259 . with_anvil_chain_id ( 22222222 )
259260 . build ( )
260261 . await ?;
@@ -267,7 +268,9 @@ async fn test_l1_reorg_batch_commit() -> eyre::Result<()> {
267268 for i in 0 ..=3 {
268269 let commit_batch_tx = read_test_transaction ( "commitBatch" , & i. to_string ( ) ) ?;
269270 fixture. anvil_send_raw_transaction ( commit_batch_tx) . await ?;
270- if i!=0 { fixture. expect_event ( ) . batch_consolidated ( ) . await ?; }
271+ if i != 0 {
272+ fixture. expect_event ( ) . batch_consolidated ( ) . await ?;
273+ }
271274 }
272275
273276 // Check that safe head was updated to batch 2
@@ -285,7 +288,8 @@ async fn test_l1_reorg_batch_commit() -> eyre::Result<()> {
285288 tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 3 ) ) . await ;
286289
287290 // Check that safe head advanced to batch 3
288- let status_after_batch_6: rollup_node_chain_orchestrator:: ChainOrchestratorStatus = fixture. get_sequencer_status ( ) . await ?;
291+ let status_after_batch_6: rollup_node_chain_orchestrator:: ChainOrchestratorStatus =
292+ fixture. get_sequencer_status ( ) . await ?;
289293 let safe_after_batch_6 = status_after_batch_6. l2 . fcs . safe_block_info ( ) . number ;
290294 tracing:: info!( "Safe head after batch 6: {}" , safe_after_batch_6) ;
291295 assert ! (
@@ -311,10 +315,10 @@ async fn test_l1_reorg_batch_commit() -> eyre::Result<()> {
311315 Ok ( ( ) )
312316}
313317
314- /// Test: L1 reorg of BatchFinalized event.
318+ /// Test: L1 reorg of ` BatchFinalized` event.
315319///
316- /// Expected: Reorging BatchFinalized should have no effect because we only update
317- /// the finalized head after the BatchFinalized event is itself finalized on L1,
320+ /// Expected: Reorging ` BatchFinalized` should have no effect because we only update
321+ /// the finalized head after the ` BatchFinalized` event is itself finalized on L1,
318322/// meaning it can never be reorged in practice.
319323#[ tokio:: test]
320324async fn test_l1_reorg_batch_finalized ( ) -> eyre:: Result < ( ) > {
@@ -323,7 +327,7 @@ async fn test_l1_reorg_batch_finalized() -> eyre::Result<()> {
323327 let mut fixture = TestFixture :: builder ( )
324328 . followers ( 1 )
325329 . skip_l1_synced_notifications ( )
326- . with_anvil_default_state ( )
330+ . with_anvil ( )
327331 . with_anvil_chain_id ( 22222222 )
328332 . build ( )
329333 . await ?;
@@ -372,9 +376,9 @@ async fn test_l1_reorg_batch_finalized() -> eyre::Result<()> {
372376 Ok ( ( ) )
373377}
374378
375- /// Test: L1 reorg of BatchRevert event.
379+ /// Test: L1 reorg of ` BatchRevert` event.
376380///
377- /// Expected: When a BatchRevert is reorged, the safe head should be restored to
381+ /// Expected: When a ` BatchRevert` is reorged, the safe head should be restored to
378382/// the state before the revert was applied. If the reverted batches are re-committed
379383/// after the reorg, the safe head should advance again.
380384#[ tokio:: test]
@@ -384,7 +388,7 @@ async fn test_l1_reorg_batch_revert() -> eyre::Result<()> {
384388 let mut fixture = TestFixture :: builder ( )
385389 . followers ( 1 )
386390 . skip_l1_synced_notifications ( )
387- . with_anvil_default_state ( )
391+ . with_anvil ( )
388392 . with_anvil_chain_id ( 22222222 )
389393 . build ( )
390394 . await ?;
@@ -420,10 +424,7 @@ async fn test_l1_reorg_batch_revert() -> eyre::Result<()> {
420424 let status_after_revert = fixture. get_sequencer_status ( ) . await ?;
421425 let safe_after_revert = status_after_revert. l2 . fcs . safe_block_info ( ) . number ;
422426 tracing:: info!( "Safe head after revert: {}" , safe_after_revert) ;
423- assert ! (
424- safe_after_revert < safe_after_commits,
425- "Safe head should decrease after BatchRevert"
426- ) ;
427+ assert ! ( safe_after_revert < safe_after_commits, "Safe head should decrease after BatchRevert" ) ;
427428
428429 // Reorg to remove the BatchRevert event (reorg depth 1)
429430 fixture. anvil_reorg ( 2 ) . await ?;
@@ -442,4 +443,4 @@ async fn test_l1_reorg_batch_revert() -> eyre::Result<()> {
442443 ) ;
443444
444445 Ok ( ( ) )
445- }
446+ }
0 commit comments