66//! Related to: https://github.com/scroll-tech/rollup-node/issues/420
77
88use alloy_primitives:: Bytes ;
9- use reth_scroll_chainspec:: SCROLL_DEV ;
109use rollup_node:: test_utils:: { EventAssertions , TestFixture } ;
1110use serde_json:: Value ;
1211
@@ -47,14 +46,13 @@ fn read_test_transaction(tx_type: &str, index: &str) -> eyre::Result<Bytes> {
4746/// Test: BatchCommit during Syncing state should have no effect.
4847///
4948/// Expected: The node should not update the safe head since we only process
50- /// BatchCommit events after the node is synced (post L1Synced notification).
49+ /// BatchCommit eventds after the node is synced (post L1Synced notification).
5150#[ tokio:: test]
5251async fn test_l1_sync_batch_commit ( ) -> eyre:: Result < ( ) > {
5352 reth_tracing:: init_test_tracing ( ) ;
5453
5554 let mut fixture = TestFixture :: builder ( )
5655 . followers ( 1 )
57- . with_chain_spec ( SCROLL_DEV . clone ( ) )
5856 . skip_l1_synced_notifications ( )
5957 . with_anvil_default_state ( )
6058 . with_anvil_chain_id ( 22222222 )
@@ -103,7 +101,6 @@ async fn test_l1_sync_batch_finalized() -> eyre::Result<()> {
103101
104102 let mut fixture = TestFixture :: builder ( )
105103 . followers ( 1 )
106- . with_chain_spec ( SCROLL_DEV . clone ( ) )
107104 . skip_l1_synced_notifications ( )
108105 . with_anvil_default_state ( )
109106 . with_anvil_chain_id ( 22222222 )
@@ -170,8 +167,8 @@ async fn test_l1_sync_batch_finalized() -> eyre::Result<()> {
170167 }
171168 fixture. anvil_mine_blocks ( 64 ) . await ?;
172169
173- // Wait for l1 blocks to be processed
174- tokio :: time :: sleep ( tokio :: time :: Duration :: from_secs ( 3 ) ) . await ;
170+ // Wait for batch finalized event
171+ fixture . expect_event ( ) . batch_finalized ( ) . await ? ;
175172
176173 // Check that finalized head was updated
177174 let batch_finalized_status = fixture. get_sequencer_status ( ) . await ?;
@@ -193,7 +190,6 @@ async fn test_l1_sync_batch_revert() -> eyre::Result<()> {
193190
194191 let mut fixture = TestFixture :: builder ( )
195192 . followers ( 1 )
196- . with_chain_spec ( SCROLL_DEV . clone ( ) )
197193 . skip_l1_synced_notifications ( )
198194 . with_anvil_default_state ( )
199195 . with_anvil_chain_id ( 22222222 )
@@ -257,58 +253,58 @@ async fn test_l1_reorg_batch_commit() -> eyre::Result<()> {
257253
258254 let mut fixture = TestFixture :: builder ( )
259255 . followers ( 1 )
260- . with_chain_spec ( SCROLL_DEV . clone ( ) )
261256 . skip_l1_synced_notifications ( )
262257 . with_anvil_default_state ( )
263258 . with_anvil_chain_id ( 22222222 )
264259 . build ( )
265260 . await ?;
266261
267- // Send BatchCommit transactions 0-2
268- for i in 0 ..=2 {
262+ // Trigger L1 synced event
263+ fixture. l1 ( ) . sync ( ) . await ?;
264+ fixture. expect_event ( ) . l1_synced ( ) . await ?;
265+
266+ // Send BatchCommit transactions 0-3
267+ for i in 0 ..=3 {
269268 let commit_batch_tx = read_test_transaction ( "commitBatch" , & i. to_string ( ) ) ?;
270269 fixture. anvil_send_raw_transaction ( commit_batch_tx) . await ?;
270+ if i!=0 { fixture. expect_event ( ) . batch_consolidated ( ) . await ?; }
271271 }
272272
273- // Trigger L1 sync
274- fixture. l1 ( ) . sync ( ) . await ?;
275- fixture. expect_event ( ) . l1_synced ( ) . await ?;
276- fixture. expect_event ( ) . batch_consolidated ( ) . await ?;
277-
278273 // Check that safe head was updated to batch 2
279- let status_after_sync = fixture. get_sequencer_status ( ) . await ?;
280- let safe_after_batch_2 = status_after_sync . l2 . fcs . safe_block_info ( ) . number ;
281- tracing:: info!( "Safe head after batch 2 : {}" , safe_after_batch_2 ) ;
274+ let status_after_batch_3 = fixture. get_sequencer_status ( ) . await ?;
275+ let safe_after_batch_3 = status_after_batch_3 . l2 . fcs . safe_block_info ( ) . number ;
276+ tracing:: info!( "Safe head after batch 3 : {}" , safe_after_batch_3 ) ;
282277
283- // Send BatchCommit transaction 3
284- let commit_batch_3_tx = read_test_transaction ( "commitBatch" , "3" ) ?;
285- fixture. anvil_send_raw_transaction ( commit_batch_3_tx) . await ?;
278+ // Send BatchCommit transactions 4-6
279+ for i in 4 ..=6 {
280+ let commit_batch_tx = read_test_transaction ( "commitBatch" , & i. to_string ( ) ) ?;
281+ fixture. anvil_send_raw_transaction ( commit_batch_tx) . await ?;
282+ }
286283
287284 // Wait for processing
288285 tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 3 ) ) . await ;
289286
290287 // Check that safe head advanced to batch 3
291- let status_after_batch_3 = fixture. get_sequencer_status ( ) . await ?;
292- let safe_after_batch_3 = status_after_batch_3 . l2 . fcs . safe_block_info ( ) . number ;
293- tracing:: info!( "Safe head after batch 3 : {}" , safe_after_batch_3 ) ;
288+ let status_after_batch_6 : rollup_node_chain_orchestrator :: ChainOrchestratorStatus = fixture. get_sequencer_status ( ) . await ?;
289+ let safe_after_batch_6 = status_after_batch_6 . l2 . fcs . safe_block_info ( ) . number ;
290+ tracing:: info!( "Safe head after batch 6 : {}" , safe_after_batch_6 ) ;
294291 assert ! (
295- safe_after_batch_3 > safe_after_batch_2 ,
292+ safe_after_batch_6 > safe_after_batch_6 ,
296293 "Safe head should advance after BatchCommit when L1Synced"
297294 ) ;
298295
299296 // Reorg to remove batch 3 (reorg depth 1)
300- fixture. anvil_reorg ( 1 ) . await ?;
297+ fixture. anvil_reorg ( 3 ) . await ?;
301298 fixture. anvil_mine_blocks ( 1 ) . await ?;
302299
303- // Wait for reorg to be detected and processed
304- tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 3 ) ) . await ;
300+ fixture. expect_event ( ) . l1_reorg ( ) . await ?;
305301
306- // Check that safe head reverted to batch 2
302+ // Check that safe head reverted
307303 let status_after_reorg = fixture. get_sequencer_status ( ) . await ?;
308304 let safe_after_reorg = status_after_reorg. l2 . fcs . safe_block_info ( ) . number ;
309305 tracing:: info!( "Safe head after reorg: {}" , safe_after_reorg) ;
310306 assert_eq ! (
311- safe_after_reorg, safe_after_batch_2 ,
307+ safe_after_reorg, safe_after_batch_3 ,
312308 "Safe head should revert to previous BatchCommit after reorg"
313309 ) ;
314310
@@ -326,7 +322,6 @@ async fn test_l1_reorg_batch_finalized() -> eyre::Result<()> {
326322
327323 let mut fixture = TestFixture :: builder ( )
328324 . followers ( 1 )
329- . with_chain_spec ( SCROLL_DEV . clone ( ) )
330325 . skip_l1_synced_notifications ( )
331326 . with_anvil_default_state ( )
332327 . with_anvil_chain_id ( 22222222 )
@@ -388,7 +383,6 @@ async fn test_l1_reorg_batch_revert() -> eyre::Result<()> {
388383
389384 let mut fixture = TestFixture :: builder ( )
390385 . followers ( 1 )
391- . with_chain_spec ( SCROLL_DEV . clone ( ) )
392386 . skip_l1_synced_notifications ( )
393387 . with_anvil_default_state ( )
394388 . with_anvil_chain_id ( 22222222 )
0 commit comments