Skip to content

Commit 82d4178

Browse files
committed
test: add test_l1_sync_batch_commit
1 parent c703985 commit 82d4178

File tree

13 files changed

+197
-960
lines changed

13 files changed

+197
-960
lines changed

crates/node/src/args.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,23 @@ use scroll_network::ScrollNetworkManager;
5353
use scroll_wire::ScrollWireEvent;
5454
use tokio::sync::mpsc::{Sender, UnboundedReceiver};
5555

56-
/// A struct that represents the arguments for the rollup node.
57-
#[derive(Debug, Clone, clap::Args)]
58-
pub struct ScrollRollupNodeConfig {
56+
/// Test-related configuration arguments.
57+
#[derive(Debug, Clone, Default, clap::Args)]
58+
pub struct TestArgs {
5959
/// Whether the rollup node should be run in test mode.
6060
#[arg(long)]
6161
pub test: bool,
62+
/// Test mode: skip L1 watcher Synced notifications.
63+
#[arg(long, default_value = "false")]
64+
pub skip_l1_synced: bool,
65+
}
66+
67+
/// A struct that represents the arguments for the rollup node.
68+
#[derive(Debug, Clone, clap::Args)]
69+
pub struct ScrollRollupNodeConfig {
70+
/// Test-related arguments
71+
#[command(flatten)]
72+
pub test_args: TestArgs,
6273
/// Consensus args
6374
#[command(flatten)]
6475
pub consensus_args: ConsensusArgs,
@@ -226,7 +237,7 @@ impl ScrollRollupNodeConfig {
226237
// Run the database migrations
227238
if let Some(named) = chain_spec.chain().named() {
228239
named
229-
.migrate(db.inner().get_connection(), self.test)
240+
.migrate(db.inner().get_connection(), self.test_args.test)
230241
.await
231242
.expect("failed to perform migration");
232243
} else {
@@ -341,7 +352,9 @@ impl ScrollRollupNodeConfig {
341352
let consensus = self.consensus_args.consensus(authorized_signer)?;
342353

343354
let (l1_notification_tx, l1_notification_rx): (Option<Sender<Arc<L1Notification>>>, _) =
344-
if let Some(provider) = l1_provider.filter(|_| !self.test||self.blob_provider_args.anvil_url.is_some()) {
355+
if let Some(provider) = l1_provider
356+
.filter(|_| !self.test_args.test || self.blob_provider_args.anvil_url.is_some())
357+
{
345358
tracing::info!(target: "scroll::node::args", ?l1_block_startup_info, "Starting L1 watcher");
346359
(
347360
None,
@@ -351,6 +364,7 @@ impl ScrollRollupNodeConfig {
351364
l1_block_startup_info,
352365
node_config,
353366
self.l1_provider_args.logs_query_block_range,
367+
self.test_args.test && self.test_args.skip_l1_synced,
354368
)
355369
.await,
356370
),
@@ -410,7 +424,7 @@ impl ScrollRollupNodeConfig {
410424
let signer = if let Some(configured_signer) = self.signer_args.signer(chain_id).await? {
411425
// Use the signer configured by SignerArgs
412426
Some(rollup_node_signer::Signer::spawn(configured_signer))
413-
} else if self.test {
427+
} else if self.test_args.test {
414428
// Use a random private key signer for testing
415429
Some(rollup_node_signer::Signer::spawn(PrivateKeySigner::random()))
416430
} else {
@@ -887,7 +901,7 @@ mod tests {
887901
#[test]
888902
fn test_validate_sequencer_enabled_without_any_signer_fails() {
889903
let config = ScrollRollupNodeConfig {
890-
test: false,
904+
test_args: TestArgs::default(),
891905
sequencer_args: SequencerArgs { sequencer_enabled: true, ..Default::default() },
892906
signer_args: SignerArgs { key_file: None, aws_kms_key_id: None, private_key: None },
893907
database_args: RollupNodeDatabaseArgs::default(),
@@ -915,7 +929,7 @@ mod tests {
915929
#[test]
916930
fn test_validate_sequencer_enabled_with_both_signers_fails() {
917931
let config = ScrollRollupNodeConfig {
918-
test: false,
932+
test_args: TestArgs::default(),
919933
sequencer_args: SequencerArgs { sequencer_enabled: true, ..Default::default() },
920934
signer_args: SignerArgs {
921935
key_file: Some(PathBuf::from("/path/to/key")),
@@ -945,7 +959,7 @@ mod tests {
945959
#[test]
946960
fn test_validate_sequencer_enabled_with_key_file_succeeds() {
947961
let config = ScrollRollupNodeConfig {
948-
test: false,
962+
test_args: TestArgs::default(),
949963
sequencer_args: SequencerArgs { sequencer_enabled: true, ..Default::default() },
950964
signer_args: SignerArgs {
951965
key_file: Some(PathBuf::from("/path/to/key")),
@@ -970,7 +984,7 @@ mod tests {
970984
#[test]
971985
fn test_validate_sequencer_enabled_with_aws_kms_succeeds() {
972986
let config = ScrollRollupNodeConfig {
973-
test: false,
987+
test_args: TestArgs::default(),
974988
sequencer_args: SequencerArgs { sequencer_enabled: true, ..Default::default() },
975989
signer_args: SignerArgs {
976990
key_file: None,
@@ -995,7 +1009,7 @@ mod tests {
9951009
#[test]
9961010
fn test_validate_sequencer_disabled_without_any_signer_succeeds() {
9971011
let config = ScrollRollupNodeConfig {
998-
test: false,
1012+
test_args: TestArgs::default(),
9991013
sequencer_args: SequencerArgs { sequencer_enabled: false, ..Default::default() },
10001014
signer_args: SignerArgs { key_file: None, aws_kms_key_id: None, private_key: None },
10011015
database_args: RollupNodeDatabaseArgs::default(),

crates/node/src/test_utils/fixture.rs

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ use super::{
66
use crate::{
77
BlobProviderArgs, ChainOrchestratorArgs, ConsensusAlgorithm, ConsensusArgs, EngineDriverArgs,
88
L1ProviderArgs, RollupNodeDatabaseArgs, RollupNodeGasPriceOracleArgs, RollupNodeNetworkArgs,
9-
RpcArgs, ScrollRollupNode, ScrollRollupNodeConfig, SequencerArgs, SignerArgs,
9+
RpcArgs, ScrollRollupNode, ScrollRollupNodeConfig, SequencerArgs, SignerArgs, TestArgs,
1010
};
1111

1212
use alloy_eips::BlockNumberOrTag;
13-
use alloy_primitives::Address;
13+
use alloy_primitives::{address, Address};
14+
use alloy_provider::{Provider, ProviderBuilder};
1415
use alloy_rpc_types_eth::Block;
1516
use alloy_signer_local::PrivateKeySigner;
1617
use reth_chainspec::EthChainSpec;
@@ -230,13 +231,27 @@ impl TestFixture {
230231
self.anvil.is_some()
231232
}
232233

234+
/// Generate Anvil blocks by calling anvil_mine RPC method.
235+
pub async fn anvil_mine_blocks(&self, num_blocks: u64) -> eyre::Result<()> {
236+
// Ensure Anvil is running
237+
let anvil_endpoint =
238+
self.anvil_endpoint().ok_or_else(|| eyre::eyre!("Anvil is not running"))?;
239+
240+
// Create RPC client
241+
let client = alloy_rpc_client::RpcClient::new_http(anvil_endpoint.parse()?);
242+
243+
// Mine blocks using anvil_mine RPC method
244+
// Parameters: (num_blocks, interval_in_seconds)
245+
let _: () = client.request("anvil_mine", (num_blocks, 0)).await?;
246+
247+
Ok(())
248+
}
249+
233250
/// Send a raw transaction to Anvil.
234251
pub async fn anvil_send_raw_transaction(
235252
&self,
236253
raw_tx: impl Into<alloy_primitives::Bytes>,
237254
) -> eyre::Result<alloy_primitives::B256> {
238-
use alloy_provider::{Provider, ProviderBuilder};
239-
240255
// Ensure Anvil is running
241256
let anvil_endpoint =
242257
self.anvil_endpoint().ok_or_else(|| eyre::eyre!("Anvil is not running"))?;
@@ -294,7 +309,7 @@ impl TestFixtureBuilder {
294309
/// Returns the default rollup node config.
295310
fn default_config() -> ScrollRollupNodeConfig {
296311
ScrollRollupNodeConfig {
297-
test: true,
312+
test_args: TestArgs { test: true, skip_l1_synced: false },
298313
network_args: RollupNodeNetworkArgs::default(),
299314
database_args: RollupNodeDatabaseArgs::default(),
300315
l1_provider_args: L1ProviderArgs::default(),
@@ -339,8 +354,15 @@ impl TestFixtureBuilder {
339354
}
340355

341356
/// Toggle the test field.
342-
pub const fn with_test(mut self, test: bool) -> Self {
343-
self.config.test = test;
357+
pub fn with_test(mut self, test: bool) -> Self {
358+
self.config.test_args.test = test;
359+
self
360+
}
361+
362+
/// Enable test mode to skip L1 watcher Synced notifications.
363+
/// This is useful for tests that don't want to wait for L1 sync completion events.
364+
pub fn skip_l1_synced_notifications(mut self) -> Self {
365+
self.config.test_args.skip_l1_synced = true;
344366
self
345367
}
346368

@@ -487,7 +509,7 @@ impl TestFixtureBuilder {
487509
self
488510
}
489511

490-
/// Enable Anvil with the default state file (`tests/anvil_state.json`).
512+
/// Enable Anvil with the default state file (`./tests/testdata/anvil_state.json`).
491513
pub fn with_anvil_default_state(mut self) -> Self {
492514
self.enable_anvil = true;
493515
self.anvil_state_path = Some(PathBuf::from("./tests/testdata/anvil_state.json"));
@@ -513,6 +535,23 @@ impl TestFixtureBuilder {
513535
self
514536
}
515537

538+
/// Set custom L1 config addresses for Anvil testing.
539+
/// This method reads contract addresses from tests/anvil.env.
540+
pub fn with_anvil_l1_config(mut self) -> Self {
541+
let chain_spec = self.chain_spec.take().unwrap_or_else(|| SCROLL_DEV.clone());
542+
let mut spec = (*chain_spec).clone();
543+
spec.config.l1_config.scroll_chain_address =
544+
address!("0x5FC8d32690cc91D4c39d9d3abcBD16989F875707");
545+
spec.config.l1_config.l1_message_queue_address =
546+
address!("0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9");
547+
spec.config.l1_config.l1_message_queue_v2_address =
548+
address!("0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9");
549+
spec.config.l1_config.l2_system_config_address =
550+
address!("0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0");
551+
self.chain_spec = Some(Arc::new(spec));
552+
self
553+
}
554+
516555
/// Build the test fixture.
517556
pub async fn build(self) -> eyre::Result<TestFixture> {
518557
let mut config = self.config;
@@ -609,7 +648,7 @@ impl TestFixtureBuilder {
609648
if let Some(id) = chain_id {
610649
config.chain_id = Some(id);
611650
}
612-
651+
613652
config.port = 8544;
614653

615654
// Configure block time
@@ -619,14 +658,9 @@ impl TestFixtureBuilder {
619658

620659
// Load state from file if provided
621660
if let Some(path) = state_path {
622-
let state = anvil::eth::backend::db::SerializableState::load(path)
623-
.map_err(|e| {
624-
eyre::eyre!(
625-
"Failed to load Anvil state from {}: {:?}",
626-
path.display(),
627-
e
628-
)
629-
})?;
661+
let state = anvil::eth::backend::db::SerializableState::load(path).map_err(|e| {
662+
eyre::eyre!("Failed to load Anvil state from {}: {:?}", path.display(), e)
663+
})?;
630664
tracing::info!("Loaded Anvil state from: {}", path.display());
631665
config.init_state = Some(state);
632666
}

crates/node/src/test_utils/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub use network_helpers::{
7878
use crate::{
7979
BlobProviderArgs, ChainOrchestratorArgs, ConsensusArgs, EngineDriverArgs, L1ProviderArgs,
8080
RollupNodeDatabaseArgs, RollupNodeNetworkArgs, RpcArgs, ScrollRollupNode,
81-
ScrollRollupNodeConfig, SequencerArgs,
81+
ScrollRollupNodeConfig, SequencerArgs, TestArgs,
8282
};
8383
use alloy_primitives::Bytes;
8484
use reth_chainspec::EthChainSpec;
@@ -220,7 +220,7 @@ pub async fn generate_tx(wallet: Arc<Mutex<Wallet>>) -> Bytes {
220220
/// Returns a default [`ScrollRollupNodeConfig`] preconfigured for testing.
221221
pub fn default_test_scroll_rollup_node_config() -> ScrollRollupNodeConfig {
222222
ScrollRollupNodeConfig {
223-
test: true,
223+
test_args: TestArgs { test: true, skip_l1_synced: false },
224224
network_args: RollupNodeNetworkArgs::default(),
225225
database_args: RollupNodeDatabaseArgs::default(),
226226
l1_provider_args: L1ProviderArgs::default(),
@@ -253,7 +253,7 @@ pub fn default_test_scroll_rollup_node_config() -> ScrollRollupNodeConfig {
253253
/// interval.
254254
pub fn default_sequencer_test_scroll_rollup_node_config() -> ScrollRollupNodeConfig {
255255
ScrollRollupNodeConfig {
256-
test: true,
256+
test_args: TestArgs { test: true, skip_l1_synced: false },
257257
network_args: RollupNodeNetworkArgs::default(),
258258
database_args: RollupNodeDatabaseArgs {
259259
rn_db_path: Some(PathBuf::from("sqlite::memory:")),

0 commit comments

Comments
 (0)