Skip to content

Commit f3613ef

Browse files
committed
add frequent sequencer switching test
1 parent a4092ee commit f3613ef

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

tests/src/utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ pub async fn wait_for_l1_message_queue_index_reached(
181181
tokio::time::sleep(Duration::from_millis(500)).await;
182182
}
183183

184-
Ok(())
184+
eyre::bail!(
185+
"Timeout after {}s waiting for all nodes to reach queue index {}",
186+
timeout_secs,
187+
expected_index
188+
)
185189
}
186190

187191
/// Waits for all provided nodes to reach the target block number.

tests/tests/migrate_sequencer.rs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use eyre::Result;
2-
use std::sync::{atomic::AtomicBool, Arc};
2+
use std::{
3+
sync::{atomic::AtomicBool, Arc},
4+
time::Duration,
5+
};
36
use tests::*;
47

58
#[tokio::test]
@@ -44,24 +47,45 @@ async fn docker_test_migrate_sequencer() -> Result<()> {
4447

4548
tracing::info!("🔄 Started continuous L1 message and L2 transaction sender for entire test");
4649

47-
// Enable block production on l2geth sequencer
48-
utils::miner_start(&l2geth_sequencer).await?;
50+
let enable_l2geth_sequencing = async || -> Result<()> {
51+
utils::disable_automatic_sequencing(&rn_sequencer).await?;
52+
let latest_block = rn_sequencer.get_block_number().await?;
53+
utils::wait_for_block(&nodes, latest_block).await?;
4954

50-
// Wait for at least 60 blocks to be produced
51-
let target_block = 30;
52-
utils::wait_for_block(&[&l2geth_sequencer], target_block).await?;
55+
tracing::info!("Enabling sequencing on l2geth sequencer");
56+
utils::miner_start(&l2geth_sequencer).await?;
5357

54-
let target_block = 60;
55-
utils::wait_for_block(&nodes, target_block).await?;
56-
utils::assert_blocks_match(&nodes, target_block).await?;
58+
Ok(())
59+
};
5760

58-
let target_block = 90;
59-
utils::wait_for_block(&nodes, target_block).await?;
60-
utils::assert_blocks_match(&nodes, target_block).await?;
61+
let enable_rn_sequencing = async || -> Result<()> {
62+
utils::miner_stop(&l2geth_sequencer).await?;
63+
let latest_block = l2geth_sequencer.get_block_number().await?;
64+
utils::wait_for_block(&nodes, latest_block).await?;
6165

62-
let target_block = 120;
63-
utils::wait_for_block(&nodes, target_block).await?;
64-
utils::assert_blocks_match(&nodes, target_block).await?;
66+
tracing::info!("Enabling sequencing on RN sequencer");
67+
utils::enable_automatic_sequencing(&rn_sequencer).await?;
68+
69+
Ok(())
70+
};
71+
72+
// Alternate sequencing between l2geth and rn sequencer every 5 seconds. With a block time of
73+
// 500ms we should produce about 10 blocks each handoff.
74+
let latest_block = 0u64;
75+
loop {
76+
enable_l2geth_sequencing().await?;
77+
tokio::time::sleep(Duration::from_secs(5)).await;
78+
enable_rn_sequencing().await?;
79+
tokio::time::sleep(Duration::from_secs(5)).await;
80+
81+
let latest_block = rn_sequencer.get_block_number().await?;
82+
if latest_block >= 120 {
83+
break;
84+
}
85+
}
86+
87+
utils::wait_for_block(&nodes, latest_block).await?;
88+
utils::assert_blocks_match(&nodes, latest_block).await?;
6589

6690
utils::stop_continuous_tx_sender(stop.clone(), tx_sender).await?;
6791
utils::stop_continuous_l1_message_sender(stop, l1_message_sender).await?;

0 commit comments

Comments
 (0)