Skip to content

Commit fe784c1

Browse files
committed
tests: migrate remaining tests
1 parent 2d48822 commit fe784c1

File tree

5 files changed

+240
-472
lines changed

5 files changed

+240
-472
lines changed

crates/node/src/test_utils/event_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ impl<'a> MultiNodeEventWaiter<'a> {
232232
}
233233

234234
/// Wait for chain extended event on all specified nodes.
235-
pub async fn chain_extended(self) -> eyre::Result<()> {
235+
pub async fn chain_extended(self, target: u64) -> eyre::Result<()> {
236236
self.wait_for_event_on_all(|e| {
237-
matches!(e, ChainOrchestratorEvent::ChainExtended(_)).then_some(())
237+
matches!(e, ChainOrchestratorEvent::ChainExtended(ChainImport{chain,..}) if chain.last().map(|b| b.header.number) >= Some(target)).then_some(())
238238
})
239239
.await?;
240240
Ok(())

crates/node/src/test_utils/fixture.rs

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ pub type ScrollNetworkHandle =
6060
pub type TestBlockChainProvider =
6161
BlockchainProvider<NodeTypesWithDBAdapter<ScrollRollupNode, TmpDB>>;
6262

63+
/// The node type (sequencer or follower).
64+
#[derive(Debug)]
65+
pub enum NodeType {
66+
/// A sequencer node.
67+
Sequencer,
68+
/// A follower node.
69+
Follower,
70+
}
71+
6372
/// Handle to a single test node with its components.
6473
pub struct NodeHandle {
6574
/// The underlying node context.
@@ -74,6 +83,20 @@ pub struct NodeHandle {
7483
pub rollup_manager_handle: ChainOrchestratorHandle<ScrollNetworkHandle>,
7584
/// Node index in the test setup.
7685
pub index: usize,
86+
/// The type of the node.
87+
pub typ: NodeType,
88+
}
89+
90+
impl NodeHandle {
91+
/// Returns true if this is a handle to the sequencer.
92+
pub fn is_sequencer(&self) -> bool {
93+
matches!(self.typ, NodeType::Sequencer)
94+
}
95+
96+
/// Returns true if this is a handle to a follower.
97+
pub fn is_follower(&self) -> bool {
98+
matches!(self.typ, NodeType::Follower)
99+
}
77100
}
78101

79102
impl Debug for NodeHandle {
@@ -95,18 +118,25 @@ impl TestFixture {
95118
}
96119

97120
/// Get the sequencer node (assumes first node is sequencer).
98-
pub fn sequencer_node(&mut self) -> &mut NodeHandle {
99-
&mut self.nodes[0]
121+
pub fn sequencer(&mut self) -> &mut NodeHandle {
122+
let handle = &mut self.nodes[0];
123+
if !handle.is_sequencer() {
124+
panic!("expected sequencer, got follower")
125+
}
126+
handle
100127
}
101128

102129
/// Get a follower node by index.
103-
pub fn follower_node(&mut self, index: usize) -> &mut NodeHandle {
104-
&mut self.nodes[index + 1]
130+
pub fn follower(&mut self, index: usize) -> &mut NodeHandle {
131+
if index == 0 && self.nodes[0].is_sequencer() {
132+
return &mut self.nodes[index + 1];
133+
}
134+
&mut self.nodes[index]
105135
}
106136

107-
/// Get the wallet address.
108-
pub fn wallet_address(&self) -> Address {
109-
self.wallet.blocking_lock().inner.address()
137+
/// Get the wallet.
138+
pub fn wallet(&self) -> Arc<Mutex<Wallet>> {
139+
self.wallet.clone()
110140
}
111141

112142
/// Start building a block using the sequencer.
@@ -246,7 +276,7 @@ impl TestFixtureBuilder {
246276
pub fn new() -> Self {
247277
Self {
248278
config: Self::default_config(),
249-
num_nodes: 1,
279+
num_nodes: 0,
250280
chain_spec: None,
251281
is_dev: false,
252282
no_local_transactions_propagation: false,
@@ -289,12 +319,14 @@ impl TestFixtureBuilder {
289319
L1MessageInclusionMode::BlockDepth(0);
290320
self.config.sequencer_args.allow_empty_blocks = true;
291321
self.config.database_args.rn_db_path = Some(PathBuf::from("sqlite::memory:"));
322+
323+
self.num_nodes += 1;
292324
self
293325
}
294326

295327
/// Adds `count`s follower nodes to the test.
296328
pub fn followers(mut self, count: usize) -> TestFixtureBuilder {
297-
self.num_nodes = count;
329+
self.num_nodes += count;
298330
self
299331
}
300332

@@ -459,7 +491,7 @@ impl TestFixtureBuilder {
459491
let chain_spec = self.chain_spec.unwrap_or_else(|| SCROLL_DEV.clone());
460492

461493
let (nodes, _tasks, wallet) = setup_engine(
462-
config,
494+
config.clone(),
463495
self.num_nodes,
464496
chain_spec.clone(),
465497
self.is_dev,
@@ -495,6 +527,11 @@ impl TestFixtureBuilder {
495527
l1_watcher_tx,
496528
rollup_manager_handle,
497529
index,
530+
typ: if config.sequencer_args.sequencer_enabled && index == 0 {
531+
NodeType::Sequencer
532+
} else {
533+
NodeType::Follower
534+
},
498535
});
499536
}
500537

crates/node/src/test_utils/l1_helpers.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ impl<'a> L1MessageBuilder<'a> {
173173

174174
/// Send the L1 message to the database and notify nodes.
175175
pub async fn send(self) -> eyre::Result<TxL1Message> {
176-
let sender = self.sender.unwrap_or_else(|| self.l1_helper.fixture.wallet_address());
176+
let sender = self
177+
.sender
178+
.unwrap_or_else(|| self.l1_helper.fixture.wallet().blocking_lock().inner.address());
177179

178180
let tx_l1_message = TxL1Message {
179181
queue_index: self.queue_index,

crates/node/tests/e2e.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ async fn can_handle_batch_revert() -> eyre::Result<()> {
971971
.where_event_n(42, |e| matches!(e, ChainOrchestratorEvent::BlockConsolidated(_)))
972972
.await?;
973973

974-
let status = fixture.follower_node(0).rollup_manager_handle.status().await?;
974+
let status = fixture.follower(0).rollup_manager_handle.status().await?;
975975

976976
// Assert the forkchoice state is above 4
977977
assert!(status.l2.fcs.head_block_info().number > 4);
@@ -983,7 +983,7 @@ async fn can_handle_batch_revert() -> eyre::Result<()> {
983983
// Wait for the third batch to be proceeded.
984984
tokio::time::sleep(Duration::from_millis(300)).await;
985985

986-
let status = fixture.follower_node(0).rollup_manager_handle.status().await?;
986+
let status = fixture.follower(0).rollup_manager_handle.status().await?;
987987

988988
// Assert the forkchoice state was reset to 4.
989989
assert_eq!(status.l2.fcs.head_block_info().number, 4);
@@ -1261,7 +1261,7 @@ async fn can_rpc_enable_disable_sequencing() -> eyre::Result<()> {
12611261
assert_ne!(fixture.get_sequencer_block().await?.header.number, 0, "Should produce blocks");
12621262

12631263
// Disable automatic sequencing via RPC
1264-
let client = fixture.sequencer_node().node.rpc_client().expect("Should have rpc client");
1264+
let client = fixture.sequencer().node.rpc_client().expect("Should have rpc client");
12651265
let result = RollupNodeExtApiClient::disable_automatic_sequencing(&client).await?;
12661266
assert!(result, "Disable automatic sequencing should return true");
12671267

@@ -1432,7 +1432,7 @@ async fn can_gossip_over_eth_wire() -> eyre::Result<()> {
14321432
fixture.expect_event().l1_synced().await?;
14331433

14341434
let mut eth_wire_blocks =
1435-
fixture.follower_node(0).node.inner.network.eth_wire_block_listener().await?;
1435+
fixture.follower(0).node.inner.network.eth_wire_block_listener().await?;
14361436

14371437
if let Some(block) = eth_wire_blocks.next().await {
14381438
println!("Received block from eth-wire network: {block:?}");
@@ -1485,7 +1485,7 @@ async fn signer_rotation() -> eyre::Result<()> {
14851485
fixture2.l1().for_node(0).sync().await?;
14861486

14871487
// connect the two sequencers
1488-
fixture1.sequencer_node().node.connect(&mut fixture2.sequencer_node().node).await;
1488+
fixture1.sequencer().node.connect(&mut fixture2.sequencer().node).await;
14891489

14901490
// wait for 5 blocks to be produced.
14911491
for i in 1..=5 {

0 commit comments

Comments
 (0)