diff --git a/crates/papyrus_network/src/network_manager/test_utils.rs b/crates/papyrus_network/src/network_manager/test_utils.rs index 59f435bfac..1c23c4bee5 100644 --- a/crates/papyrus_network/src/network_manager/test_utils.rs +++ b/crates/papyrus_network/src/network_manager/test_utils.rs @@ -11,7 +11,6 @@ use libp2p::core::multiaddr::Protocol; use libp2p::gossipsub::SubscriptionError; use libp2p::identity::Keypair; use libp2p::{Multiaddr, PeerId}; -use papyrus_common::tcp::find_n_free_ports; use starknet_sequencer_infra::test_utils::AvailablePorts; use super::{ @@ -149,8 +148,11 @@ where Ok(TestSubscriberChannels { subscriber_channels, mock_network }) } -pub fn create_connected_network_configs(n: usize) -> Vec { - let mut ports = find_n_free_ports(n); +pub fn create_connected_network_configs( + n: usize, + available_ports: &mut AvailablePorts, +) -> Vec { + let mut ports = available_ports.get_next_ports(n); let port0 = ports.remove(0); let secret_key0 = [1u8; 32]; @@ -178,8 +180,6 @@ pub fn create_connected_network_configs(n: usize) -> Vec { configs } -// TODO(Tsabary): remove #[allow(unused_variables)]. -#[allow(unused_variables)] pub fn create_network_configs_connected_to_broadcast_channels( n_configs: usize, topic: Topic, @@ -191,7 +191,7 @@ where { const BUFFER_SIZE: usize = 1000; - let mut channels_configs = create_connected_network_configs(n_configs + 1); + let mut channels_configs = create_connected_network_configs(n_configs + 1, available_ports); let broadcast_channels = channels_configs.remove(0); let mut channels_network_manager = NetworkManager::new(broadcast_channels, None); diff --git a/crates/starknet_integration_tests/src/flow_test_setup.rs b/crates/starknet_integration_tests/src/flow_test_setup.rs index da5539c022..d135c275f8 100644 --- a/crates/starknet_integration_tests/src/flow_test_setup.rs +++ b/crates/starknet_integration_tests/src/flow_test_setup.rs @@ -58,8 +58,11 @@ impl FlowTestSetup { let [sequencer_0_consensus_manager_config, sequencer_1_consensus_manager_config]: [ConsensusManagerConfig; 2] = consensus_manager_configs.try_into().unwrap(); - let mempool_p2p_configs = - create_mempool_p2p_configs(SEQUENCER_INDICES.len(), chain_info.chain_id.clone()); + let mempool_p2p_configs = create_mempool_p2p_configs( + SEQUENCER_INDICES.len(), + chain_info.chain_id.clone(), + &mut available_ports, + ); let [sequencer_0_mempool_p2p_config, sequencer_1_mempool_p2p_config]: [MempoolP2pConfig; 2] = mempool_p2p_configs.try_into().unwrap(); diff --git a/crates/starknet_integration_tests/src/integration_test_setup.rs b/crates/starknet_integration_tests/src/integration_test_setup.rs index aac64fa852..e6a4e57e72 100644 --- a/crates/starknet_integration_tests/src/integration_test_setup.rs +++ b/crates/starknet_integration_tests/src/integration_test_setup.rs @@ -72,8 +72,11 @@ impl IntegrationTestSetup { SEQUENCER_INDICES.len(), &mut available_ports, ); - let mut mempool_p2p_configs = - create_mempool_p2p_configs(SEQUENCER_INDICES.len(), chain_info.chain_id.clone()); + let mut mempool_p2p_configs = create_mempool_p2p_configs( + SEQUENCER_INDICES.len(), + chain_info.chain_id.clone(), + &mut available_ports, + ); // Derive the configuration for the sequencer node. let (config, required_params) = create_config( diff --git a/crates/starknet_integration_tests/src/utils.rs b/crates/starknet_integration_tests/src/utils.rs index ad8766d316..361e469f86 100644 --- a/crates/starknet_integration_tests/src/utils.rs +++ b/crates/starknet_integration_tests/src/utils.rs @@ -138,8 +138,12 @@ pub fn test_rpc_state_reader_config(rpc_server_addr: SocketAddr) -> RpcStateRead RpcStateReaderConfig::from_url(format!("http://{rpc_server_addr:?}/rpc/{RPC_SPEC_VERSION}")) } -pub fn create_mempool_p2p_configs(n_mempools: usize, chain_id: ChainId) -> Vec { - create_connected_network_configs(n_mempools) +pub fn create_mempool_p2p_configs( + n_mempools: usize, + chain_id: ChainId, + available_ports: &mut AvailablePorts, +) -> Vec { + create_connected_network_configs(n_mempools, available_ports) .into_iter() .map(|mut network_config| { network_config.chain_id = chain_id.clone(); diff --git a/crates/starknet_sequencer_infra/src/test_utils.rs b/crates/starknet_sequencer_infra/src/test_utils.rs index 40a6a41668..c1ace573cf 100644 --- a/crates/starknet_sequencer_infra/src/test_utils.rs +++ b/crates/starknet_sequencer_infra/src/test_utils.rs @@ -53,6 +53,10 @@ impl AvailablePorts { port } + pub fn get_next_ports(&mut self, n: usize) -> Vec { + (0..n).map(|_| self.get_next_port()).collect() + } + pub fn get_next_local_host_socket(&mut self) -> SocketAddr { SocketAddr::new(IpAddr::from(Ipv4Addr::LOCALHOST), self.get_next_port()) }