Skip to content

Commit 8d0cd7a

Browse files
committed
address comments
1 parent a978bee commit 8d0cd7a

File tree

5 files changed

+51
-49
lines changed

5 files changed

+51
-49
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ scroll-alloy-network = { workspace = true }
1616
tokio = { workspace = true, features = ["rt", "time"] }
1717
eyre = { workspace = true }
1818
getrandom = { workspace = true }
19+
tracing = { workspace = true }

tests/src/docker_compose.rs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ pub struct DockerComposeEnv {
1212
}
1313

1414
impl DockerComposeEnv {
15+
/// The sequencer node RPC URL for the Docker Compose environment.
16+
const SEQUENCER_RPC_URL: &str = "http://localhost:8545";
17+
18+
/// The follower node RPC URL for the Docker Compose environment.
19+
const FOLLOWER_RPC_URL: &str = "http://localhost:8547";
20+
1521
// ===== CONSTRUCTOR AND LIFECYCLE =====
1622

1723
/// Create a new DockerComposeEnv and wait for all services to be ready
@@ -22,7 +28,7 @@ impl DockerComposeEnv {
2228
let project_name = format!("test-{test_name}-{timestamp}");
2329
let compose_file = "docker-compose.test.yml".to_string();
2430

25-
println!("🚀 Starting test environment: {project_name}");
31+
tracing::info!("🚀 Starting test environment: {project_name}");
2632

2733
// Pre-cleanup existing containers to avoid conflicts
2834
Self::cleanup(&compose_file, &project_name);
@@ -31,16 +37,16 @@ impl DockerComposeEnv {
3137
let env = Self::start_environment(&compose_file, &project_name)?;
3238

3339
// Wait for all services to be ready
34-
println!("⏳ Waiting for services to be ready...");
40+
tracing::info!("⏳ Waiting for services to be ready...");
3541
env.wait_for_sequencer_ready().await?;
3642
env.wait_for_follower_ready().await?;
3743

38-
println!("✅ All services are ready!");
44+
tracing::info!("✅ All services are ready!");
3945
Ok(env)
4046
}
4147

4248
fn start_environment(compose_file: &str, project_name: &str) -> Result<Self> {
43-
println!("📦 Starting docker-compose services...");
49+
tracing::info!("📦 Starting docker-compose services...");
4450

4551
let mut child = Command::new("docker")
4652
.args([
@@ -63,14 +69,14 @@ impl DockerComposeEnv {
6369
use std::io::{BufRead, BufReader};
6470
let reader = BufReader::new(stdout);
6571
for line in reader.lines().map_while(Result::ok) {
66-
println!("📦 Docker: {line}");
72+
tracing::debug!("📦 Docker: {line}");
6773
}
6874
}
6975

7076
let output = child.wait_with_output().expect("Failed to wait for docker-compose");
7177

7278
if !output.status.success() {
73-
eprintln!("Docker-compose stderr: {}", String::from_utf8_lossy(&output.stderr));
79+
tracing::error!("Docker-compose stderr: {}", String::from_utf8_lossy(&output.stderr));
7480

7581
// Show logs for debugging before returning error
7682
Self::show_all_container_logs(compose_file, project_name);
@@ -83,7 +89,7 @@ impl DockerComposeEnv {
8389

8490
/// Cleanup the environment
8591
fn cleanup(compose_file: &str, project_name: &str) {
86-
println!("🧹 Cleaning up environment: {project_name}");
92+
tracing::info!("🧹 Cleaning up environment: {project_name}");
8793

8894
let _result = Command::new("docker")
8995
.args([
@@ -100,31 +106,19 @@ impl DockerComposeEnv {
100106
])
101107
.output();
102108

103-
println!("✅ Cleanup completed");
104-
}
105-
106-
// ===== INTERNAL CONFIGURATION =====
107-
108-
/// Get Sequencer RPC URL
109-
fn get_sequencer_rpc_url(&self) -> String {
110-
"http://localhost:8545".to_string()
111-
}
112-
113-
/// Get Follower RPC URL
114-
fn get_follower_rpc_url(&self) -> String {
115-
"http://localhost:8547".to_string()
109+
tracing::info!("✅ Cleanup completed");
116110
}
117111

118112
// ===== READINESS CHECKS =====
119113

120114
/// Wait for sequencer to be ready
121115
async fn wait_for_sequencer_ready(&self) -> Result<()> {
122-
Self::wait_for_l2_node_ready(&self.get_sequencer_rpc_url(), 30).await
116+
Self::wait_for_l2_node_ready(Self::SEQUENCER_RPC_URL, 30).await
123117
}
124118

125119
/// Wait for follower to be ready
126120
async fn wait_for_follower_ready(&self) -> Result<()> {
127-
Self::wait_for_l2_node_ready(&self.get_follower_rpc_url(), 30).await
121+
Self::wait_for_l2_node_ready(Self::FOLLOWER_RPC_URL, 30).await
128122
}
129123

130124
/// Wait for L2 node to be ready
@@ -137,17 +131,19 @@ impl DockerComposeEnv {
137131
{
138132
Ok(provider) => match provider.get_chain_id().await {
139133
Ok(chain_id) => {
140-
println!("✅ L2 node ready - Chain ID: {chain_id}");
134+
tracing::info!("✅ L2 node ready - Chain ID: {chain_id}");
141135
return Ok(());
142136
}
143137
Err(e) => {
144138
let attempt = i + 1;
145-
println!("⏳ L2 node not ready yet (attempt {attempt}/{max_retries}): {e}");
139+
tracing::warn!(
140+
"⏳ L2 node not ready yet (attempt {attempt}/{max_retries}): {e}"
141+
);
146142
}
147143
},
148144
Err(e) => {
149145
let attempt = i + 1;
150-
println!("⏳ Waiting for L2 node (attempt {attempt}/{max_retries}): {e}");
146+
tracing::warn!("⏳ Waiting for L2 node (attempt {attempt}/{max_retries}): {e}");
151147
}
152148
}
153149
tokio::time::sleep(Duration::from_secs(2)).await;
@@ -163,7 +159,7 @@ impl DockerComposeEnv {
163159
pub async fn get_sequencer_provider(&self) -> Result<impl Provider<Scroll>> {
164160
ProviderBuilder::<_, _, Scroll>::default()
165161
.with_recommended_fillers()
166-
.connect(&self.get_sequencer_rpc_url())
162+
.connect(Self::SEQUENCER_RPC_URL)
167163
.await
168164
.map_err(|e| eyre::eyre!("Failed to connect to sequencer: {}", e))
169165
}
@@ -172,7 +168,7 @@ impl DockerComposeEnv {
172168
pub async fn get_follower_provider(&self) -> Result<impl Provider<Scroll>> {
173169
ProviderBuilder::<_, _, Scroll>::default()
174170
.with_recommended_fillers()
175-
.connect(&self.get_follower_rpc_url())
171+
.connect(Self::FOLLOWER_RPC_URL)
176172
.await
177173
.map_err(|e| eyre::eyre!("Failed to connect to follower: {}", e))
178174
}
@@ -181,7 +177,7 @@ impl DockerComposeEnv {
181177

182178
/// Show logs for all containers
183179
fn show_all_container_logs(compose_file: &str, project_name: &str) {
184-
println!("🔍 Getting all container logs...");
180+
tracing::info!("🔍 Getting all container logs...");
185181

186182
let logs_output = Command::new("docker")
187183
.args(["compose", "-f", compose_file, "-p", project_name, "logs"])
@@ -191,10 +187,10 @@ impl DockerComposeEnv {
191187
let stdout = String::from_utf8_lossy(&logs.stdout);
192188
let stderr = String::from_utf8_lossy(&logs.stderr);
193189
if !stdout.trim().is_empty() {
194-
eprintln!("❌ All container logs (stdout):\n{stdout}");
190+
tracing::error!("❌ All container logs (stdout):\n{stdout}");
195191
}
196192
if !stderr.trim().is_empty() {
197-
eprintln!("❌ All container logs (stderr):\n{stderr}");
193+
tracing::error!("❌ All container logs (stderr):\n{stderr}");
198194
}
199195
}
200196
}

tests/tests/block_production.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ use tests::DockerComposeEnv;
88

99
#[tokio::test]
1010
async fn test_docker_block_production() -> Result<()> {
11-
println!("=== STARTING test_docker_block_production ===");
11+
tracing::info!("=== STARTING test_docker_block_production ===");
1212
let env = DockerComposeEnv::new("block-production").await?;
1313

1414
let sequencer = env.get_sequencer_provider().await?;
15-
println!("✅ Sequencer provider created");
15+
tracing::info!("✅ Sequencer provider created");
1616

1717
let initial_block = sequencer.get_block_number().await?;
18-
println!("Initial block number: {initial_block}");
18+
tracing::info!("Initial block number: {initial_block}");
1919

2020
let final_block = wait_for_sequencer_blocks(&sequencer, 20).await?;
21-
println!("Final block number: {final_block}");
21+
tracing::info!("Final block number: {final_block}");
2222

2323
assert!(
2424
final_block >= initial_block + 5,
2525
"Sequencer should have produced at least 5 new blocks."
2626
);
2727

28-
println!("✅ Block production test completed successfully!");
28+
tracing::info!("✅ Block production test completed successfully!");
2929
Ok(())
3030
}
3131

@@ -36,13 +36,15 @@ async fn wait_for_sequencer_blocks(
3636
) -> Result<u64> {
3737
let start_block = sequencer.get_block_number().await?;
3838
let target_block = start_block + num_blocks;
39-
println!("⏳ Waiting for sequencer to produce {num_blocks} blocks (target: {target_block})...");
39+
tracing::info!(
40+
"⏳ Waiting for sequencer to produce {num_blocks} blocks (target: {target_block})..."
41+
);
4042

4143
for _ in 0..10 {
4244
// 10 second timeout
4345
let current_block = sequencer.get_block_number().await?;
4446
if current_block >= target_block {
45-
println!("✅ Sequencer reached block {current_block}");
47+
tracing::info!("✅ Sequencer reached block {current_block}");
4648
return Ok(current_block);
4749
}
4850
tokio::time::sleep(Duration::from_secs(1)).await;

tests/tests/block_propagation.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,32 @@ use tests::DockerComposeEnv;
99

1010
#[tokio::test]
1111
async fn test_docker_block_propagation() -> Result<()> {
12-
println!("=== STARTING test_docker_block_propagation ===");
12+
tracing::info!("=== STARTING test_docker_block_propagation ===");
1313
let env = DockerComposeEnv::new("basic-block-propagation").await?;
1414

1515
let sequencer = env.get_sequencer_provider().await?;
16-
println!("✅ Sequencer provider created");
16+
tracing::info!("✅ Sequencer provider created");
1717

1818
let follower = env.get_follower_provider().await?;
19-
println!("✅ Follower provider created");
19+
tracing::info!("✅ Follower provider created");
2020

2121
let s_chain_id = sequencer.get_chain_id().await?;
2222
let f_chain_id = follower.get_chain_id().await?;
23-
println!(
23+
tracing::info!(
2424
"✅ Sequencer (Chain ID: {s_chain_id}) & Follower (Chain ID: {f_chain_id}) connected."
2525
);
2626
assert_eq!(s_chain_id, f_chain_id, "Chain IDs must match");
2727

2828
let target_block = wait_for_sequencer_blocks(&sequencer, 20).await?;
29-
println!("Sequencer produced {target_block} blocks, now waiting for follower sync...");
29+
tracing::info!("Sequencer produced {target_block} blocks, now waiting for follower sync...");
3030

3131
wait_for_follower_sync(&follower, target_block).await?;
32-
println!("Follower synced to block {target_block}");
32+
tracing::info!("Follower synced to block {target_block}");
3333

3434
for block_num in 1..=target_block {
3535
verify_blocks_match(&sequencer, &follower, block_num).await?;
3636
}
37-
println!("✅ Block hashes match for all blocks up to {target_block}, Basic block propagation test completed successfully!");
37+
tracing::info!("✅ Block hashes match for all blocks up to {target_block}, Basic block propagation test completed successfully!");
3838

3939
Ok(())
4040
}
@@ -46,13 +46,15 @@ async fn wait_for_sequencer_blocks(
4646
) -> Result<u64> {
4747
let start_block = sequencer.get_block_number().await?;
4848
let target_block = start_block + num_blocks;
49-
println!("⏳ Waiting for sequencer to produce {num_blocks} blocks (target: {target_block})...",);
49+
tracing::info!(
50+
"⏳ Waiting for sequencer to produce {num_blocks} blocks (target: {target_block})..."
51+
);
5052

5153
for _ in 0..10 {
5254
// 10 second timeout
5355
let current_block = sequencer.get_block_number().await?;
5456
if current_block >= target_block {
55-
println!("✅ Sequencer reached block {current_block}");
57+
tracing::info!("✅ Sequencer reached block {current_block}");
5658
return Ok(current_block);
5759
}
5860
tokio::time::sleep(Duration::from_secs(1)).await;
@@ -62,13 +64,13 @@ async fn wait_for_sequencer_blocks(
6264

6365
/// Waits for the follower to sync up to the target block.
6466
async fn wait_for_follower_sync(follower: &impl Provider<Scroll>, target_block: u64) -> Result<()> {
65-
println!("⏳ Waiting for follower to sync to block {target_block}...");
67+
tracing::info!("⏳ Waiting for follower to sync to block {target_block}...");
6668

6769
for _ in 0..10 {
6870
// 10 second timeout
6971
let follower_block = follower.get_block_number().await?;
7072
if follower_block >= target_block {
71-
println!("✅ Follower synced to block {follower_block}");
73+
tracing::info!("✅ Follower synced to block {follower_block}");
7274
return Ok(());
7375
}
7476
tokio::time::sleep(Duration::from_secs(1)).await;
@@ -105,6 +107,6 @@ async fn verify_blocks_match(
105107
);
106108
}
107109

108-
println!("✅ Block {block_number} matches: hash={seq_hash:?}");
110+
tracing::debug!("✅ Block {block_number} matches: hash={seq_hash:?}");
109111
Ok(())
110112
}

0 commit comments

Comments
 (0)