Skip to content

Commit 2d48822

Browse files
committed
tests: answer comments + finish migration
1 parent 81c5db8 commit 2d48822

File tree

8 files changed

+602
-1142
lines changed

8 files changed

+602
-1142
lines changed

Cargo.lock

Lines changed: 128 additions & 127 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/node/src/test_utils/block_builder.rs

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@ use super::fixture::TestFixture;
44
use crate::test_utils::EventAssertions;
55

66
use alloy_primitives::B256;
7-
use futures::StreamExt;
87
use reth_primitives_traits::transaction::TxHashRef;
9-
use reth_rpc_api::EngineApiClient;
10-
use reth_scroll_chainspec::ScrollChainSpec;
11-
use reth_scroll_engine_primitives::ScrollEngineTypes;
128
use reth_scroll_primitives::ScrollBlock;
13-
use rollup_node_sequencer::SequencerEvent;
149
use scroll_alloy_consensus::ScrollTransaction;
15-
use scroll_alloy_provider::ScrollAuthApiEngineClient;
16-
use scroll_db::Database;
1710

1811
/// Builder for constructing and validating blocks in tests.
1912
#[derive(Debug)]
20-
pub struct BlockBuilder<'a, EC> {
21-
fixture: &'a mut TestFixture<EC>,
13+
pub struct BlockBuilder<'a> {
14+
fixture: &'a mut TestFixture,
2215
expected_tx_hashes: Vec<B256>,
2316
expected_tx_count: Option<usize>,
2417
expected_base_fee: Option<u64>,
@@ -27,9 +20,9 @@ pub struct BlockBuilder<'a, EC> {
2720
expected_l1_message_count: Option<usize>,
2821
}
2922

30-
impl<'a, EC: EngineApiClient<ScrollEngineTypes> + Sync + Send + 'static> BlockBuilder<'a, EC> {
23+
impl<'a> BlockBuilder<'a> {
3124
/// Create a new block builder.
32-
pub(crate) fn new(fixture: &'a mut TestFixture<EC>) -> Self {
25+
pub(crate) fn new(fixture: &'a mut TestFixture) -> Self {
3326
Self {
3427
fixture,
3528
expected_tx_hashes: Vec::new(),
@@ -109,32 +102,6 @@ impl<'a, EC: EngineApiClient<ScrollEngineTypes> + Sync + Send + 'static> BlockBu
109102
self.validate_block(&block)
110103
}
111104

112-
/// Build a block using the low-level sequencer API (for direct sequencer tests).
113-
pub async fn build_with_sequencer(
114-
self,
115-
sequencer: &mut rollup_node_sequencer::Sequencer<Database, ScrollChainSpec>,
116-
engine: &mut scroll_engine::Engine<ScrollAuthApiEngineClient<EC>>,
117-
) -> eyre::Result<Option<ScrollBlock>> {
118-
// Start payload building
119-
sequencer.start_payload_building(engine).await?;
120-
121-
// Wait for the payload to be ready
122-
let payload_id = loop {
123-
if let Some(SequencerEvent::PayloadReady(id)) = sequencer.next().await {
124-
break id;
125-
}
126-
};
127-
128-
// Finalize the payload building
129-
let block_opt = sequencer.finalize_payload_building(payload_id, engine).await?;
130-
131-
if let Some(ref block) = block_opt {
132-
self.validate_block(block)?;
133-
}
134-
135-
Ok(block_opt)
136-
}
137-
138105
/// Validate the block against expectations.
139106
fn validate_block(self, block: &ScrollBlock) -> eyre::Result<ScrollBlock> {
140107
// Check transaction count

crates/node/src/test_utils/event_utils.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use tokio::time::timeout;
1111

1212
/// Builder for waiting for specific events with optional assertions.
1313
#[derive(Debug)]
14-
pub struct EventWaiter<'a, EC> {
15-
fixture: &'a mut TestFixture<EC>,
14+
pub struct EventWaiter<'a> {
15+
fixture: &'a mut TestFixture,
1616
node_index: usize,
1717
timeout_duration: Duration,
1818
}
1919

20-
impl<'a, EC> EventWaiter<'a, EC> {
20+
impl<'a> EventWaiter<'a> {
2121
/// Create a new event waiter.
22-
pub fn new(fixture: &'a mut TestFixture<EC>, node_index: usize) -> Self {
22+
pub fn new(fixture: &'a mut TestFixture, node_index: usize) -> Self {
2323
Self { fixture, node_index, timeout_duration: Duration::from_secs(30) }
2424
}
2525

@@ -60,7 +60,7 @@ impl<'a, EC> EventWaiter<'a, EC> {
6060
/// Wait for a chain extended event.
6161
pub async fn chain_extended(self, target: u64) -> eyre::Result<()> {
6262
self.wait_for_event(|e| {
63-
matches!(e, ChainOrchestratorEvent::ChainExtended(ChainImport { chain, .. }) if chain.last().map(|b| b.header.number) == Some(target))
63+
matches!(e, ChainOrchestratorEvent::ChainExtended(ChainImport { chain, .. }) if chain.last().map(|b| b.header.number) >= Some(target))
6464
.then_some(())
6565
})
6666
.await
@@ -174,6 +174,7 @@ impl<'a, EC> EventWaiter<'a, EC> {
174174

175175
let result = timeout(self.timeout_duration, async {
176176
while let Some(event) = events.next().await {
177+
tracing::debug!(target: "event_waiter", ?event);
177178
if let Some(value) = extractor(&event) {
178179
return Ok(value);
179180
}
@@ -188,15 +189,15 @@ impl<'a, EC> EventWaiter<'a, EC> {
188189

189190
/// Builder for waiting for events on multiple nodes.
190191
#[derive(Debug)]
191-
pub struct MultiNodeEventWaiter<'a, EC> {
192-
fixture: &'a mut TestFixture<EC>,
192+
pub struct MultiNodeEventWaiter<'a> {
193+
fixture: &'a mut TestFixture,
193194
node_indices: Vec<usize>,
194195
timeout_duration: Duration,
195196
}
196197

197-
impl<'a, EC> MultiNodeEventWaiter<'a, EC> {
198+
impl<'a> MultiNodeEventWaiter<'a> {
198199
/// Create a new multi-node event waiter.
199-
pub fn new(fixture: &'a mut TestFixture<EC>, node_indices: Vec<usize>) -> Self {
200+
pub fn new(fixture: &'a mut TestFixture, node_indices: Vec<usize>) -> Self {
200201
Self { fixture, node_indices, timeout_duration: Duration::from_secs(30) }
201202
}
202203

@@ -397,42 +398,42 @@ impl<'a, EC> MultiNodeEventWaiter<'a, EC> {
397398
}
398399

399400
/// Extension trait for `TestFixture` to add event waiting capabilities.
400-
pub trait EventAssertions<EC> {
401+
pub trait EventAssertions {
401402
/// Wait for an event on the sequencer node.
402-
fn expect_event(&mut self) -> EventWaiter<'_, EC>;
403+
fn expect_event(&mut self) -> EventWaiter<'_>;
403404

404405
/// Wait for an event on a specific node.
405-
fn expect_event_on(&mut self, node_index: usize) -> EventWaiter<'_, EC>;
406+
fn expect_event_on(&mut self, node_index: usize) -> EventWaiter<'_>;
406407

407408
/// Wait for an event on multiple nodes.
408-
fn expect_event_on_nodes(&mut self, node_indices: Vec<usize>) -> MultiNodeEventWaiter<'_, EC>;
409+
fn expect_event_on_nodes(&mut self, node_indices: Vec<usize>) -> MultiNodeEventWaiter<'_>;
409410

410411
/// Wait for an event on all nodes.
411-
fn expect_event_on_all_nodes(&mut self) -> MultiNodeEventWaiter<'_, EC>;
412+
fn expect_event_on_all_nodes(&mut self) -> MultiNodeEventWaiter<'_>;
412413

413414
/// Wait for an event on all follower nodes (excluding sequencer at index 0).
414-
fn expect_event_on_followers(&mut self) -> MultiNodeEventWaiter<'_, EC>;
415+
fn expect_event_on_followers(&mut self) -> MultiNodeEventWaiter<'_>;
415416
}
416417

417-
impl<EC> EventAssertions<EC> for TestFixture<EC> {
418-
fn expect_event(&mut self) -> EventWaiter<'_, EC> {
418+
impl EventAssertions for TestFixture {
419+
fn expect_event(&mut self) -> EventWaiter<'_> {
419420
EventWaiter::new(self, 0)
420421
}
421422

422-
fn expect_event_on(&mut self, node_index: usize) -> EventWaiter<'_, EC> {
423+
fn expect_event_on(&mut self, node_index: usize) -> EventWaiter<'_> {
423424
EventWaiter::new(self, node_index)
424425
}
425426

426-
fn expect_event_on_nodes(&mut self, node_indices: Vec<usize>) -> MultiNodeEventWaiter<'_, EC> {
427+
fn expect_event_on_nodes(&mut self, node_indices: Vec<usize>) -> MultiNodeEventWaiter<'_> {
427428
MultiNodeEventWaiter::new(self, node_indices)
428429
}
429430

430-
fn expect_event_on_all_nodes(&mut self) -> MultiNodeEventWaiter<'_, EC> {
431+
fn expect_event_on_all_nodes(&mut self) -> MultiNodeEventWaiter<'_> {
431432
let node_indices = (0..self.nodes.len()).collect();
432433
MultiNodeEventWaiter::new(self, node_indices)
433434
}
434435

435-
fn expect_event_on_followers(&mut self) -> MultiNodeEventWaiter<'_, EC> {
436+
fn expect_event_on_followers(&mut self) -> MultiNodeEventWaiter<'_> {
436437
let node_indices = (1..self.nodes.len()).collect();
437438
MultiNodeEventWaiter::new(self, node_indices)
438439
}

0 commit comments

Comments
 (0)