Skip to content

Commit

Permalink
chore(infra): remove duplication of get_available_socket
Browse files Browse the repository at this point in the history
commit-id:011da994
  • Loading branch information
Itay-Tsabary-Starkware committed Nov 24, 2024
1 parent 8e75016 commit 956a40e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/starknet_integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions crates/starknet_integration_tests/src/state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>);

Expand Down
17 changes: 1 addition & 16 deletions crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions crates/starknet_sequencer_infra/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down

0 comments on commit 956a40e

Please sign in to comment.