From 956a40e2aa3f5fd8adacb969d92087f2d667f56d Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Fri, 22 Nov 2024 15:47:27 +0200 Subject: [PATCH] chore(infra): remove duplication of get_available_socket commit-id:011da994 --- crates/starknet_integration_tests/Cargo.toml | 2 +- .../src/state_reader.rs | 3 +-- crates/starknet_integration_tests/src/utils.rs | 17 +---------------- .../starknet_sequencer_infra/src/test_utils.rs | 2 -- 4 files changed, 3 insertions(+), 21 deletions(-) diff --git a/crates/starknet_integration_tests/Cargo.toml b/crates/starknet_integration_tests/Cargo.toml index 945701af17..2a77b40534 100644 --- a/crates/starknet_integration_tests/Cargo.toml +++ b/crates/starknet_integration_tests/Cargo.toml @@ -36,7 +36,7 @@ starknet_gateway_types.workspace = true starknet_http_server.workspace = true starknet_mempool_p2p.workspace = true starknet_monitoring_endpoint = { workspace = true, features = ["testing"] } -starknet_sequencer_infra.workspace = true +starknet_sequencer_infra = { workspace = true, features = ["testing"] } starknet_sequencer_node = { workspace = true, features = ["testing"] } starknet_task_executor.workspace = true strum.workspace = true diff --git a/crates/starknet_integration_tests/src/state_reader.rs b/crates/starknet_integration_tests/src/state_reader.rs index 56540e6c7f..5015d52629 100644 --- a/crates/starknet_integration_tests/src/state_reader.rs +++ b/crates/starknet_integration_tests/src/state_reader.rs @@ -41,13 +41,12 @@ use starknet_api::state::{StorageKey, ThinStateDiff}; use starknet_api::transaction::fields::Fee; use starknet_api::{contract_address, felt}; use starknet_client::reader::PendingData; +use starknet_sequencer_infra::test_utils::get_available_socket; use starknet_types_core::felt::Felt; use strum::IntoEnumIterator; use tempfile::TempDir; use tokio::sync::RwLock; -use crate::utils::get_available_socket; - type ContractClassesMap = (Vec<(ClassHash, DeprecatedContractClass)>, Vec<(ClassHash, CasmContractClass)>); diff --git a/crates/starknet_integration_tests/src/utils.rs b/crates/starknet_integration_tests/src/utils.rs index f6079b6e03..fb89e98051 100644 --- a/crates/starknet_integration_tests/src/utils.rs +++ b/crates/starknet_integration_tests/src/utils.rs @@ -33,9 +33,9 @@ use starknet_gateway::config::{ }; use starknet_gateway_types::errors::GatewaySpecError; use starknet_http_server::config::HttpServerConfig; +use starknet_sequencer_infra::test_utils::get_available_socket; use starknet_sequencer_node::config::node_config::SequencerNodeConfig; use starknet_sequencer_node::config::test_utils::RequiredParams; -use tokio::net::TcpListener; pub fn create_chain_info() -> ChainInfo { let mut chain_info = ChainInfo::create_for_testing(); @@ -105,21 +105,6 @@ pub fn test_rpc_state_reader_config(rpc_server_addr: SocketAddr) -> RpcStateRead } } -/// Returns a unique IP address and port for testing purposes. -/// -/// Tests run in parallel, so servers (like RPC or web) running on separate tests must have -/// different ports, otherwise the server will fail with "address already in use". -pub async fn get_available_socket() -> SocketAddr { - // Dynamically select port. - // First, set the port to 0 (dynamic port). - TcpListener::bind("127.0.0.1:0") - .await - .expect("Failed to bind to address") - // Then, resolve to the actual selected port. - .local_addr() - .expect("Failed to get local address") -} - /// A test utility client for interacting with an http server. pub struct HttpTestClient { socket: SocketAddr, diff --git a/crates/starknet_sequencer_infra/src/test_utils.rs b/crates/starknet_sequencer_infra/src/test_utils.rs index 58603bc63a..464af8c708 100644 --- a/crates/starknet_sequencer_infra/src/test_utils.rs +++ b/crates/starknet_sequencer_infra/src/test_utils.rs @@ -2,8 +2,6 @@ use std::net::SocketAddr; use tokio::net::TcpListener; -// TODO(Nadin): Merge this get_available_socket function with the one in the test_integration crate -// and remove the duplicate there. /// Returns a unique IP address and port for testing purposes. /// Tests run in parallel, so servers (like RPC or web) running on separate tests must have /// different ports, otherwise the server will fail with "address already in use".