Skip to content

Commit a64812f

Browse files
committed
tests: cleaning + fix
1 parent 8c2bfc7 commit a64812f

File tree

7 files changed

+37
-188
lines changed

7 files changed

+37
-188
lines changed

crates/node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,5 @@ test-utils = [
156156
"scroll-network/test-utils",
157157
"alloy-eips",
158158
"reth-storage-api",
159-
"alloy-rpc-types-eth"
159+
"alloy-rpc-types-eth",
160160
]

crates/node/src/test_utils/block_builder.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ impl<'a> BlockBuilder<'a> {
5252
self
5353
}
5454

55-
/// Expect a specific base fee per gas.
56-
pub const fn expect_base_fee(mut self, base_fee: u64) -> Self {
57-
self.expected_base_fee = Some(base_fee);
58-
self
59-
}
60-
6155
/// Expect at least one L1 message in the block.
6256
pub const fn expect_l1_message(mut self) -> Self {
6357
self.expect_l1_message = true;

crates/node/src/test_utils/event_utils.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ impl<'a> EventWaiter<'a> {
3333
pub async fn block_sequenced(self, target: u64) -> eyre::Result<ScrollBlock> {
3434
self.wait_for_event(|e| {
3535
if let ChainOrchestratorEvent::BlockSequenced(block) = e {
36-
if block.header.number == target {
37-
Some(block.clone())
38-
} else {
39-
None
40-
}
36+
(block.header.number == target).then(|| block.clone())
4137
} else {
4238
None
4339
}
@@ -128,7 +124,7 @@ impl<'a> EventWaiter<'a> {
128124
self,
129125
mut predicate: impl FnMut(&ChainOrchestratorEvent) -> bool,
130126
) -> eyre::Result<ChainOrchestratorEvent> {
131-
self.wait_for_event(move |e| if predicate(e) { Some(e.clone()) } else { None }).await
127+
self.wait_for_event(move |e| predicate(e).then(|| e.clone())).await
132128
}
133129

134130
/// Wait for any event and extract a value from it.
@@ -318,7 +314,7 @@ impl<'a> MultiNodeEventWaiter<'a> {
318314
self,
319315
predicate: impl Fn(&ChainOrchestratorEvent) -> bool,
320316
) -> eyre::Result<Vec<ChainOrchestratorEvent>> {
321-
self.wait_for_event_on_all(move |e| if predicate(e) { Some(e.clone()) } else { None }).await
317+
self.wait_for_event_on_all(move |e| predicate(e).then(|| e.clone())).await
322318
}
323319

324320
/// Wait for any event and extract a value from it on all specified nodes.

crates/node/src/test_utils/fixture.rs

Lines changed: 21 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
};
1111

1212
use alloy_eips::BlockNumberOrTag;
13-
use alloy_primitives::{Address, BlockHash};
13+
use alloy_primitives::Address;
1414
use alloy_rpc_types_eth::Block;
1515
use alloy_signer_local::PrivateKeySigner;
1616
use reth_chainspec::EthChainSpec;
@@ -89,12 +89,12 @@ pub struct NodeHandle {
8989

9090
impl NodeHandle {
9191
/// Returns true if this is a handle to the sequencer.
92-
pub fn is_sequencer(&self) -> bool {
92+
pub const fn is_sequencer(&self) -> bool {
9393
matches!(self.typ, NodeType::Sequencer)
9494
}
9595

9696
/// Returns true if this is a handle to a follower.
97-
pub fn is_follower(&self) -> bool {
97+
pub const fn is_follower(&self) -> bool {
9898
matches!(self.typ, NodeType::Follower)
9999
}
100100
}
@@ -120,9 +120,7 @@ impl TestFixture {
120120
/// Get the sequencer node (assumes first node is sequencer).
121121
pub fn sequencer(&mut self) -> &mut NodeHandle {
122122
let handle = &mut self.nodes[0];
123-
if !handle.is_sequencer() {
124-
panic!("expected sequencer, got follower")
125-
}
123+
assert!(handle.is_sequencer(), "expected sequencer, got follower");
126124
handle
127125
}
128126

@@ -159,54 +157,6 @@ impl TestFixture {
159157
self.tx().transfer().inject().await
160158
}
161159

162-
/// Advance time by sleeping for the specified number of seconds.
163-
pub async fn advance_time(&self, seconds: u64) {
164-
tokio::time::sleep(tokio::time::Duration::from_secs(seconds)).await;
165-
}
166-
167-
/// Connect all nodes in a mesh network.
168-
pub async fn connect_all(&mut self) {
169-
let node_count = self.nodes.len();
170-
for i in 0..node_count {
171-
for j in (i + 1)..node_count {
172-
self.connect(i, j).await;
173-
}
174-
}
175-
}
176-
177-
/// Connect two nodes by index.
178-
pub async fn connect(&mut self, idx1: usize, idx2: usize) {
179-
// Split the nodes vector to get mutable references to both nodes
180-
if idx1 == idx2 {
181-
return;
182-
}
183-
184-
let (node1, node2) = if idx1 < idx2 {
185-
let (left, right) = self.nodes.split_at_mut(idx2);
186-
(&mut left[idx1], &mut right[0])
187-
} else {
188-
let (left, right) = self.nodes.split_at_mut(idx1);
189-
(&mut right[0], &mut left[idx2])
190-
};
191-
192-
node1.node.connect(&mut node2.node).await;
193-
}
194-
195-
/// Get the genesis hash from the chain spec.
196-
pub fn genesis_hash(&self) -> BlockHash {
197-
self.chain_spec.genesis_hash()
198-
}
199-
200-
/// Get the chain ID.
201-
pub fn chain_id(&self) -> u64 {
202-
self.chain_spec.chain().into()
203-
}
204-
205-
/// Get the RPC URL for a specific node.
206-
pub fn rpc_url(&self, node_index: usize) -> String {
207-
format!("http://localhost:{}", self.nodes[node_index].node.rpc_url().port().unwrap())
208-
}
209-
210160
/// Inject a raw transaction into a specific node's pool.
211161
pub async fn inject_tx_on(
212162
&mut self,
@@ -235,24 +185,6 @@ impl TestFixture {
235185
pub async fn get_sequencer_block(&self) -> eyre::Result<Block<Transaction>> {
236186
self.get_block(0).await
237187
}
238-
239-
/// Get a block by number from a specific node.
240-
pub async fn get_block_by_number(
241-
&self,
242-
node_index: usize,
243-
block_number: impl Into<BlockNumberOrTag>,
244-
) -> eyre::Result<Option<Block<Transaction>>> {
245-
use reth_rpc_api::EthApiServer;
246-
247-
self.nodes[node_index]
248-
.node
249-
.rpc
250-
.inner
251-
.eth_api()
252-
.block_by_number(block_number.into(), false)
253-
.await
254-
.map_err(Into::into)
255-
}
256188
}
257189

258190
/// Builder for creating test fixtures with a fluent API.
@@ -325,13 +257,13 @@ impl TestFixtureBuilder {
325257
}
326258

327259
/// Adds `count`s follower nodes to the test.
328-
pub fn followers(mut self, count: usize) -> TestFixtureBuilder {
260+
pub const fn followers(mut self, count: usize) -> Self {
329261
self.num_nodes += count;
330262
self
331263
}
332264

333265
/// Toggle the test field.
334-
pub fn with_test(mut self, test: bool) -> Self {
266+
pub const fn with_test(mut self, test: bool) -> Self {
335267
self.config.test = test;
336268
self
337269
}
@@ -343,7 +275,7 @@ impl TestFixtureBuilder {
343275
}
344276

345277
/// Set the sequencer auto start for the node.
346-
pub fn with_sequencer_auto_start(mut self, auto_start: bool) -> Self {
278+
pub const fn with_sequencer_auto_start(mut self, auto_start: bool) -> Self {
347279
self.config.sequencer_args.auto_start = auto_start;
348280
self
349281
}
@@ -370,26 +302,26 @@ impl TestFixtureBuilder {
370302
}
371303

372304
/// Set the block time for the sequencer.
373-
pub fn block_time(mut self, millis: u64) -> Self {
305+
pub const fn block_time(mut self, millis: u64) -> Self {
374306
self.config.sequencer_args.block_time = millis;
375307
self
376308
}
377309

378310
/// Set whether to allow empty blocks.
379-
pub fn allow_empty_blocks(mut self, allow: bool) -> Self {
311+
pub const fn allow_empty_blocks(mut self, allow: bool) -> Self {
380312
self.config.sequencer_args.allow_empty_blocks = allow;
381313
self
382314
}
383315

384316
/// Set L1 message inclusion mode with block depth.
385-
pub fn with_l1_message_delay(mut self, depth: u64) -> Self {
317+
pub const fn with_l1_message_delay(mut self, depth: u64) -> Self {
386318
self.config.sequencer_args.l1_message_inclusion_mode =
387319
L1MessageInclusionMode::BlockDepth(depth);
388320
self
389321
}
390322

391323
/// Set L1 message inclusion mode to finalized with optional block depth.
392-
pub fn with_finalized_l1_messages(mut self, depth: u64) -> Self {
324+
pub const fn with_finalized_l1_messages(mut self, depth: u64) -> Self {
393325
self.config.sequencer_args.l1_message_inclusion_mode =
394326
L1MessageInclusionMode::FinalizedWithBlockDepth(depth);
395327
self
@@ -408,13 +340,13 @@ impl TestFixtureBuilder {
408340
}
409341

410342
/// Use noop consensus (no validation).
411-
pub fn with_noop_consensus(mut self) -> Self {
343+
pub const fn with_noop_consensus(mut self) -> Self {
412344
self.config.consensus_args = ConsensusArgs::noop();
413345
self
414346
}
415347

416-
/// Use SystemContract consensus with the given authorized signer address.
417-
pub fn with_consensus_system_contract(mut self, authorized_signer: Address) -> Self {
348+
/// Use `SystemContract` consensus with the given authorized signer address.
349+
pub const fn with_consensus_system_contract(mut self, authorized_signer: Address) -> Self {
418350
self.config.consensus_args.algorithm = ConsensusAlgorithm::SystemContract;
419351
self.config.consensus_args.authorized_signer = Some(authorized_signer);
420352
self
@@ -427,59 +359,47 @@ impl TestFixtureBuilder {
427359
}
428360

429361
/// Set the payload building duration in milliseconds.
430-
pub fn payload_building_duration(mut self, millis: u64) -> Self {
362+
pub const fn payload_building_duration(mut self, millis: u64) -> Self {
431363
self.config.sequencer_args.payload_building_duration = millis;
432364
self
433365
}
434366

435367
/// Set the fee recipient address.
436-
pub fn fee_recipient(mut self, address: Address) -> Self {
368+
pub const fn fee_recipient(mut self, address: Address) -> Self {
437369
self.config.sequencer_args.fee_recipient = address;
438370
self
439371
}
440372

441373
/// Enable auto-start for the sequencer.
442-
pub fn auto_start(mut self, enabled: bool) -> Self {
374+
pub const fn auto_start(mut self, enabled: bool) -> Self {
443375
self.config.sequencer_args.auto_start = enabled;
444376
self
445377
}
446378

447379
/// Set the maximum number of L1 messages per block.
448-
pub fn max_l1_messages(mut self, max: u64) -> Self {
380+
pub const fn max_l1_messages(mut self, max: u64) -> Self {
449381
self.config.sequencer_args.max_l1_messages = Some(max);
450382
self
451383
}
452384

453385
/// Enable the Scroll wire protocol.
454-
pub fn with_scroll_wire(mut self, enabled: bool) -> Self {
386+
pub const fn with_scroll_wire(mut self, enabled: bool) -> Self {
455387
self.config.network_args.enable_scroll_wire = enabled;
456388
self
457389
}
458390

459391
/// Enable the ETH-Scroll wire bridge.
460-
pub fn with_eth_scroll_bridge(mut self, enabled: bool) -> Self {
392+
pub const fn with_eth_scroll_bridge(mut self, enabled: bool) -> Self {
461393
self.config.network_args.enable_eth_scroll_wire_bridge = enabled;
462394
self
463395
}
464396

465397
/// Set the optimistic sync trigger threshold.
466-
pub fn optimistic_sync_trigger(mut self, blocks: u64) -> Self {
398+
pub const fn optimistic_sync_trigger(mut self, blocks: u64) -> Self {
467399
self.config.chain_orchestrator_args.optimistic_sync_trigger = blocks;
468400
self
469401
}
470402

471-
/// Set the chain buffer size.
472-
pub fn chain_buffer_size(mut self, size: usize) -> Self {
473-
self.config.chain_orchestrator_args.chain_buffer_size = size;
474-
self
475-
}
476-
477-
/// Disable the test mode (enables real signing).
478-
pub fn production_mode(mut self) -> Self {
479-
self.config.test = false;
480-
self
481-
}
482-
483403
/// Get a mutable reference to the underlying config for advanced customization.
484404
pub fn config_mut(&mut self) -> &mut ScrollRollupNodeConfig {
485405
&mut self.config

crates/node/src/test_utils/l1_helpers.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,32 @@ impl<'a> L1Helper<'a> {
2828
}
2929

3030
/// Send a notification that L1 is synced.
31-
pub async fn sync(mut self) -> eyre::Result<()> {
31+
pub async fn sync(self) -> eyre::Result<()> {
3232
let notification = Arc::new(L1Notification::Synced);
3333
self.send_to_nodes(notification).await
3434
}
3535

3636
/// Send a new L1 block notification.
37-
pub async fn new_block(mut self, block_number: u64) -> eyre::Result<()> {
37+
pub async fn new_block(self, block_number: u64) -> eyre::Result<()> {
3838
let notification = Arc::new(L1Notification::NewBlock(block_number));
3939
self.send_to_nodes(notification).await
4040
}
4141

4242
/// Send an L1 reorg notification.
43-
pub async fn reorg_to(mut self, block_number: u64) -> eyre::Result<()> {
43+
pub async fn reorg_to(self, block_number: u64) -> eyre::Result<()> {
4444
let notification = Arc::new(L1Notification::Reorg(block_number));
4545
self.send_to_nodes(notification).await
4646
}
4747

4848
/// Send an L1 consensus notification.
49-
pub async fn signer_update(mut self, new_signer: Address) -> eyre::Result<()> {
49+
pub async fn signer_update(self, new_signer: Address) -> eyre::Result<()> {
5050
let notification =
5151
Arc::new(L1Notification::Consensus(ConsensusUpdate::AuthorizedSigner(new_signer)));
5252
self.send_to_nodes(notification).await
5353
}
5454

5555
/// Send an L1 reorg notification.
56-
pub async fn batch_commit(
57-
mut self,
58-
calldata_path: Option<&str>,
59-
index: u64,
60-
) -> eyre::Result<()> {
56+
pub async fn batch_commit(self, calldata_path: Option<&str>, index: u64) -> eyre::Result<()> {
6157
let raw_calldata = calldata_path
6258
.map(|path| {
6359
Result::<_, eyre::Report>::Ok(Bytes::from_str(&std::fs::read_to_string(path)?)?)
@@ -84,7 +80,7 @@ impl<'a> L1Helper<'a> {
8480
}
8581

8682
/// Send notification to target nodes.
87-
async fn send_to_nodes(&mut self, notification: Arc<L1Notification>) -> eyre::Result<()> {
83+
async fn send_to_nodes(&self, notification: Arc<L1Notification>) -> eyre::Result<()> {
8884
let nodes = if let Some(index) = self.target_node_index {
8985
vec![&self.fixture.nodes[index]]
9086
} else {

0 commit comments

Comments
 (0)