diff --git a/crates/testing-utils/src/node_proc.rs b/crates/testing-utils/src/node_proc.rs index 19aec492b..e5b21324d 100644 --- a/crates/testing-utils/src/node_proc.rs +++ b/crates/testing-utils/src/node_proc.rs @@ -79,7 +79,7 @@ where pub struct TestNodeProcessBuilder { node_path: OsString, authority: Option, - scan_port_range: bool, + port: u16, chain_type: String, force_authoring: bool, bootnode: Option, @@ -100,7 +100,7 @@ impl TestNodeProcessBuilder { Self { node_path: node_path.as_ref().into(), authority: None, - scan_port_range: false, + port: 9944, chain_type, force_authoring, bootnode, @@ -114,11 +114,9 @@ impl TestNodeProcessBuilder { self } - /// Enable port scanning to scan for open ports. - /// - /// Allows spawning multiple node instances for tests to run in parallel. - pub fn scan_for_open_ports(&mut self) -> &mut Self { - self.scan_port_range = true; + /// Set the port for websocket rpc + pub fn set_port(&mut self, port: u16) -> &mut Self { + self.port = port; self } @@ -148,17 +146,18 @@ impl TestNodeProcessBuilder { cmd.arg(arg); } - let ws_port = if self.scan_port_range { - let (p2p_port, _http_port, ws_port) = next_open_port() - .ok_or_else(|| "No available ports in the given port range".to_owned())?; - cmd.arg(format!("--port={p2p_port}")); - cmd.arg(format!("--rpc-port={ws_port}")); - tracing::info!("ws port: {ws_port}"); - ws_port - } else { - // the default Websockets port - 9944 - }; + cmd.arg(format!("--port={}", self.port)); + // let ws_port = if self.scan_port_range { + // // let (p2p_port, _http_port, ws_port) = next_open_port() + // // .ok_or_else(|| "No available ports in the given port range".to_owned())?; + // cmd.arg(format!("--port={p2p_port}")); + // cmd.arg(format!("--rpc-port={ws_port}")); + // tracing::info!("ws port: {ws_port}"); + // ws_port + // } else { + // // the default Websockets port + // 9944 + // }; let arg = "--rpc-external"; cmd.arg(arg); @@ -166,7 +165,7 @@ impl TestNodeProcessBuilder { let arg = "--rpc-cors=all"; cmd.arg(arg); - let ws_url = format!("ws://127.0.0.1:{ws_port}"); + let ws_url = format!("ws://127.0.0.1:{}", self.port); let mut proc = cmd.spawn().map_err(|e| { format!("Error spawning substrate node '{}': {e}", self.node_path.to_string_lossy()) diff --git a/crates/testing-utils/src/substrate_context.rs b/crates/testing-utils/src/substrate_context.rs index 404e18b10..b0c9b8ed5 100644 --- a/crates/testing-utils/src/substrate_context.rs +++ b/crates/testing-utils/src/substrate_context.rs @@ -63,6 +63,7 @@ pub async fn test_node_process_with( force_authoring: bool, bootnode: Option, tss_server_endpoint: Option, + port: Option, ) -> TestNodeProcess { let path = get_path(); let path = path.to_str().expect("Path should've been checked to be valid earlier."); @@ -75,7 +76,7 @@ pub async fn test_node_process_with( tss_server_endpoint, ) .with_authority(key) - .scan_for_open_ports() + .set_port(port.unwrap_or(9944)) .spawn::() .await; proc.unwrap() @@ -99,7 +100,8 @@ pub async fn test_node( } pub async fn test_node_process() -> TestNodeProcess { - test_node_process_with(AccountKeyring::Alice, "--dev".to_string(), false, None, None).await + test_node_process_with(AccountKeyring::Alice, "--dev".to_string(), false, None, None, None) + .await } pub async fn test_node_process_stationary() -> TestNodeProcess { @@ -116,7 +118,6 @@ pub async fn test_node_process_testing_state( "/ip4/127.0.0.1/tcp/30333/p2p/12D3KooWM7EoKJfwgzAR1nAVmYRuuFq2f3GpJPLrdfhQaRsKjn38" .to_string(), ); - // reduses message from chain to same TSS cleaning up a lot of logging let result = test_node(AccountKeyring::Alice, "--chain=dev".to_string(), force_authoring, None).await; let result_bob = test_node_process_with( @@ -125,6 +126,7 @@ pub async fn test_node_process_testing_state( force_authoring, alice_bootnode.clone(), Some("http://localhost:3002".to_string()), + Some(9945), ) .await; let result_charlie = test_node_process_with( @@ -133,6 +135,7 @@ pub async fn test_node_process_testing_state( force_authoring, alice_bootnode.clone(), Some("http://localhost:3003".to_string()), + Some(9946), ) .await; let result_dave = test_node_process_with( @@ -141,6 +144,7 @@ pub async fn test_node_process_testing_state( force_authoring, alice_bootnode.clone(), Some("http://localhost:3004".to_string()), + Some(9947), ) .await;