@@ -12,6 +12,12 @@ pub struct DockerComposeEnv {
12
12
}
13
13
14
14
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
+
15
21
// ===== CONSTRUCTOR AND LIFECYCLE =====
16
22
17
23
/// Create a new DockerComposeEnv and wait for all services to be ready
@@ -22,7 +28,7 @@ impl DockerComposeEnv {
22
28
let project_name = format ! ( "test-{test_name}-{timestamp}" ) ;
23
29
let compose_file = "docker-compose.test.yml" . to_string ( ) ;
24
30
25
- println ! ( "🚀 Starting test environment: {project_name}" ) ;
31
+ tracing :: info !( "🚀 Starting test environment: {project_name}" ) ;
26
32
27
33
// Pre-cleanup existing containers to avoid conflicts
28
34
Self :: cleanup ( & compose_file, & project_name) ;
@@ -31,16 +37,16 @@ impl DockerComposeEnv {
31
37
let env = Self :: start_environment ( & compose_file, & project_name) ?;
32
38
33
39
// Wait for all services to be ready
34
- println ! ( "⏳ Waiting for services to be ready..." ) ;
40
+ tracing :: info !( "⏳ Waiting for services to be ready..." ) ;
35
41
env. wait_for_sequencer_ready ( ) . await ?;
36
42
env. wait_for_follower_ready ( ) . await ?;
37
43
38
- println ! ( "✅ All services are ready!" ) ;
44
+ tracing :: info !( "✅ All services are ready!" ) ;
39
45
Ok ( env)
40
46
}
41
47
42
48
fn start_environment ( compose_file : & str , project_name : & str ) -> Result < Self > {
43
- println ! ( "📦 Starting docker-compose services..." ) ;
49
+ tracing :: info !( "📦 Starting docker-compose services..." ) ;
44
50
45
51
let mut child = Command :: new ( "docker" )
46
52
. args ( [
@@ -63,14 +69,14 @@ impl DockerComposeEnv {
63
69
use std:: io:: { BufRead , BufReader } ;
64
70
let reader = BufReader :: new ( stdout) ;
65
71
for line in reader. lines ( ) . map_while ( Result :: ok) {
66
- println ! ( "📦 Docker: {line}" ) ;
72
+ tracing :: debug !( "📦 Docker: {line}" ) ;
67
73
}
68
74
}
69
75
70
76
let output = child. wait_with_output ( ) . expect ( "Failed to wait for docker-compose" ) ;
71
77
72
78
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) ) ;
74
80
75
81
// Show logs for debugging before returning error
76
82
Self :: show_all_container_logs ( compose_file, project_name) ;
@@ -83,7 +89,7 @@ impl DockerComposeEnv {
83
89
84
90
/// Cleanup the environment
85
91
fn cleanup ( compose_file : & str , project_name : & str ) {
86
- println ! ( "🧹 Cleaning up environment: {project_name}" ) ;
92
+ tracing :: info !( "🧹 Cleaning up environment: {project_name}" ) ;
87
93
88
94
let _result = Command :: new ( "docker" )
89
95
. args ( [
@@ -100,31 +106,19 @@ impl DockerComposeEnv {
100
106
] )
101
107
. output ( ) ;
102
108
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" ) ;
116
110
}
117
111
118
112
// ===== READINESS CHECKS =====
119
113
120
114
/// Wait for sequencer to be ready
121
115
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
123
117
}
124
118
125
119
/// Wait for follower to be ready
126
120
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
128
122
}
129
123
130
124
/// Wait for L2 node to be ready
@@ -137,17 +131,19 @@ impl DockerComposeEnv {
137
131
{
138
132
Ok ( provider) => match provider. get_chain_id ( ) . await {
139
133
Ok ( chain_id) => {
140
- println ! ( "✅ L2 node ready - Chain ID: {chain_id}" ) ;
134
+ tracing :: info !( "✅ L2 node ready - Chain ID: {chain_id}" ) ;
141
135
return Ok ( ( ) ) ;
142
136
}
143
137
Err ( e) => {
144
138
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
+ ) ;
146
142
}
147
143
} ,
148
144
Err ( e) => {
149
145
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}" ) ;
151
147
}
152
148
}
153
149
tokio:: time:: sleep ( Duration :: from_secs ( 2 ) ) . await ;
@@ -163,7 +159,7 @@ impl DockerComposeEnv {
163
159
pub async fn get_sequencer_provider ( & self ) -> Result < impl Provider < Scroll > > {
164
160
ProviderBuilder :: < _ , _ , Scroll > :: default ( )
165
161
. with_recommended_fillers ( )
166
- . connect ( & self . get_sequencer_rpc_url ( ) )
162
+ . connect ( Self :: SEQUENCER_RPC_URL )
167
163
. await
168
164
. map_err ( |e| eyre:: eyre!( "Failed to connect to sequencer: {}" , e) )
169
165
}
@@ -172,7 +168,7 @@ impl DockerComposeEnv {
172
168
pub async fn get_follower_provider ( & self ) -> Result < impl Provider < Scroll > > {
173
169
ProviderBuilder :: < _ , _ , Scroll > :: default ( )
174
170
. with_recommended_fillers ( )
175
- . connect ( & self . get_follower_rpc_url ( ) )
171
+ . connect ( Self :: FOLLOWER_RPC_URL )
176
172
. await
177
173
. map_err ( |e| eyre:: eyre!( "Failed to connect to follower: {}" , e) )
178
174
}
@@ -181,7 +177,7 @@ impl DockerComposeEnv {
181
177
182
178
/// Show logs for all containers
183
179
fn show_all_container_logs ( compose_file : & str , project_name : & str ) {
184
- println ! ( "🔍 Getting all container logs..." ) ;
180
+ tracing :: info !( "🔍 Getting all container logs..." ) ;
185
181
186
182
let logs_output = Command :: new ( "docker" )
187
183
. args ( [ "compose" , "-f" , compose_file, "-p" , project_name, "logs" ] )
@@ -191,10 +187,10 @@ impl DockerComposeEnv {
191
187
let stdout = String :: from_utf8_lossy ( & logs. stdout ) ;
192
188
let stderr = String :: from_utf8_lossy ( & logs. stderr ) ;
193
189
if !stdout. trim ( ) . is_empty ( ) {
194
- eprintln ! ( "❌ All container logs (stdout):\n {stdout}" ) ;
190
+ tracing :: error !( "❌ All container logs (stdout):\n {stdout}" ) ;
195
191
}
196
192
if !stderr. trim ( ) . is_empty ( ) {
197
- eprintln ! ( "❌ All container logs (stderr):\n {stderr}" ) ;
193
+ tracing :: error !( "❌ All container logs (stderr):\n {stderr}" ) ;
198
194
}
199
195
}
200
196
}
0 commit comments