Skip to content

Commit

Permalink
chore(starknet_integration_tests): add available ports to mempool p2p…
Browse files Browse the repository at this point in the history
… flow test

commit-id:7fdfc0fb
  • Loading branch information
Itay-Tsabary-Starkware committed Dec 18, 2024
1 parent 64adf22 commit a88ffe4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
12 changes: 6 additions & 6 deletions crates/papyrus_network/src/network_manager/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -149,8 +148,11 @@ where
Ok(TestSubscriberChannels { subscriber_channels, mock_network })
}

pub fn create_connected_network_configs(n: usize) -> Vec<NetworkConfig> {
let mut ports = find_n_free_ports(n);
pub fn create_connected_network_configs(
n: usize,
available_ports: &mut AvailablePorts,
) -> Vec<NetworkConfig> {
let mut ports = available_ports.get_next_ports(n);
let port0 = ports.remove(0);

let secret_key0 = [1u8; 32];
Expand Down Expand Up @@ -178,8 +180,6 @@ pub fn create_connected_network_configs(n: usize) -> Vec<NetworkConfig> {
configs
}

// TODO(Tsabary): remove #[allow(unused_variables)].
#[allow(unused_variables)]
pub fn create_network_configs_connected_to_broadcast_channels<T>(
n_configs: usize,
topic: Topic,
Expand All @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions crates/starknet_integration_tests/src/flow_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MempoolP2pConfig> {
create_connected_network_configs(n_mempools)
pub fn create_mempool_p2p_configs(
n_mempools: usize,
chain_id: ChainId,
available_ports: &mut AvailablePorts,
) -> Vec<MempoolP2pConfig> {
create_connected_network_configs(n_mempools, available_ports)
.into_iter()
.map(|mut network_config| {
network_config.chain_id = chain_id.clone();
Expand Down
4 changes: 4 additions & 0 deletions crates/starknet_sequencer_infra/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ impl AvailablePorts {
port
}

pub fn get_next_ports(&mut self, n: usize) -> Vec<u16> {
(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())
}
Expand Down

0 comments on commit a88ffe4

Please sign in to comment.