|
1 | 1 | use eyre::Result; |
2 | | -use std::sync::{atomic::AtomicBool, Arc}; |
| 2 | +use std::{ |
| 3 | + sync::{atomic::AtomicBool, Arc}, |
| 4 | + time::Duration, |
| 5 | +}; |
3 | 6 | use tests::*; |
4 | 7 |
|
5 | 8 | #[tokio::test] |
@@ -44,24 +47,45 @@ async fn docker_test_migrate_sequencer() -> Result<()> { |
44 | 47 |
|
45 | 48 | tracing::info!("🔄 Started continuous L1 message and L2 transaction sender for entire test"); |
46 | 49 |
|
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?; |
49 | 54 |
|
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?; |
53 | 57 |
|
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 | + }; |
57 | 60 |
|
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?; |
61 | 65 |
|
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?; |
65 | 89 |
|
66 | 90 | utils::stop_continuous_tx_sender(stop.clone(), tx_sender).await?; |
67 | 91 | utils::stop_continuous_l1_message_sender(stop, l1_message_sender).await?; |
|
0 commit comments