From 64adf22e1acc8309b9a2ab13fb242a821c558bb4 Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Wed, 18 Dec 2024 22:26:02 +0200 Subject: [PATCH] chore(starknet_integration_tests): add available ports to network config commit-id:f09b3b07 --- Cargo.lock | 1 + crates/papyrus_network/Cargo.toml | 3 ++- .../papyrus_network/src/network_manager/test_utils.rs | 4 ++++ .../starknet_integration_tests/src/flow_test_setup.rs | 10 +++++++--- .../src/integration_test_setup.rs | 5 ++++- .../starknet_integration_tests/src/test_identifiers.rs | 2 ++ crates/starknet_integration_tests/src/utils.rs | 2 ++ .../tests/mempool_p2p_flow_test.rs | 5 ++++- 8 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f1a2ea701..fa28609799 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7503,6 +7503,7 @@ dependencies = [ "replace_with", "serde", "starknet_api", + "starknet_sequencer_infra", "thiserror", "tokio", "tokio-retry", diff --git a/crates/papyrus_network/Cargo.toml b/crates/papyrus_network/Cargo.toml index 04a22212a7..1d7ddeb38c 100644 --- a/crates/papyrus_network/Cargo.toml +++ b/crates/papyrus_network/Cargo.toml @@ -6,7 +6,7 @@ repository.workspace = true license-file.workspace = true [features] -testing = [] +testing = ["starknet_sequencer_infra/testing"] [dependencies] async-stream.workspace = true @@ -35,6 +35,7 @@ papyrus_network_types.workspace = true replace_with.workspace = true serde = { workspace = true, features = ["derive"] } starknet_api.workspace = true +starknet_sequencer_infra = { workspace = true, optional = true, features = ["testing"] } thiserror.workspace = true tokio = { workspace = true, features = ["full", "sync"] } tokio-retry.workspace = true diff --git a/crates/papyrus_network/src/network_manager/test_utils.rs b/crates/papyrus_network/src/network_manager/test_utils.rs index be1f65427b..59f435bfac 100644 --- a/crates/papyrus_network/src/network_manager/test_utils.rs +++ b/crates/papyrus_network/src/network_manager/test_utils.rs @@ -12,6 +12,7 @@ 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::{ BroadcastTopicClient, @@ -177,9 +178,12 @@ 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, + available_ports: &mut AvailablePorts, ) -> (Vec, BroadcastTopicChannels) where T: TryFrom + 'static, diff --git a/crates/starknet_integration_tests/src/flow_test_setup.rs b/crates/starknet_integration_tests/src/flow_test_setup.rs index 35b9e1fd9a..da5539c022 100644 --- a/crates/starknet_integration_tests/src/flow_test_setup.rs +++ b/crates/starknet_integration_tests/src/flow_test_setup.rs @@ -47,10 +47,14 @@ impl FlowTestSetup { test_unique_index: u16, ) -> Self { let chain_info = create_chain_info(); + let mut available_ports = AvailablePorts::new(test_unique_index, 0); let accounts = tx_generator.accounts(); let (consensus_manager_configs, consensus_proposals_channels) = - create_consensus_manager_configs_and_channels(SEQUENCER_INDICES.len()); + create_consensus_manager_configs_and_channels( + SEQUENCER_INDICES.len(), + &mut available_ports, + ); let [sequencer_0_consensus_manager_config, sequencer_1_consensus_manager_config]: [ConsensusManagerConfig; 2] = consensus_manager_configs.try_into().unwrap(); @@ -66,7 +70,7 @@ impl FlowTestSetup { chain_info.clone(), sequencer_0_consensus_manager_config, sequencer_0_mempool_p2p_config, - AvailablePorts::new(test_unique_index, 0), + AvailablePorts::new(test_unique_index, 1), ) .await; let sequencer_1 = SequencerSetup::new( @@ -75,7 +79,7 @@ impl FlowTestSetup { chain_info, sequencer_1_consensus_manager_config, sequencer_1_mempool_p2p_config, - AvailablePorts::new(test_unique_index, 1), + AvailablePorts::new(test_unique_index, 2), ) .await; diff --git a/crates/starknet_integration_tests/src/integration_test_setup.rs b/crates/starknet_integration_tests/src/integration_test_setup.rs index 1594d5b3ba..aac64fa852 100644 --- a/crates/starknet_integration_tests/src/integration_test_setup.rs +++ b/crates/starknet_integration_tests/src/integration_test_setup.rs @@ -68,7 +68,10 @@ impl IntegrationTestSetup { .await; let (mut consensus_manager_configs, _consensus_proposals_channels) = - create_consensus_manager_configs_and_channels(SEQUENCER_INDICES.len()); + create_consensus_manager_configs_and_channels( + SEQUENCER_INDICES.len(), + &mut available_ports, + ); let mut mempool_p2p_configs = create_mempool_p2p_configs(SEQUENCER_INDICES.len(), chain_info.chain_id.clone()); diff --git a/crates/starknet_integration_tests/src/test_identifiers.rs b/crates/starknet_integration_tests/src/test_identifiers.rs index b448e34806..897a57884f 100644 --- a/crates/starknet_integration_tests/src/test_identifiers.rs +++ b/crates/starknet_integration_tests/src/test_identifiers.rs @@ -2,6 +2,7 @@ pub enum TestIdentifier { EndToEndIntegrationTest, EndToEndFlowTest, + MempoolP2pFlowTest, } impl From for u16 { @@ -9,6 +10,7 @@ impl From for u16 { match variant { TestIdentifier::EndToEndIntegrationTest => 0, TestIdentifier::EndToEndFlowTest => 1, + TestIdentifier::MempoolP2pFlowTest => 2, } } } diff --git a/crates/starknet_integration_tests/src/utils.rs b/crates/starknet_integration_tests/src/utils.rs index 944f2122a8..ad8766d316 100644 --- a/crates/starknet_integration_tests/src/utils.rs +++ b/crates/starknet_integration_tests/src/utils.rs @@ -95,6 +95,7 @@ pub async fn create_config( pub fn create_consensus_manager_configs_and_channels( n_managers: usize, + available_ports: &mut AvailablePorts, ) -> (Vec, BroadcastTopicChannels>) { let (network_configs, broadcast_channels) = create_network_configs_connected_to_broadcast_channels( @@ -102,6 +103,7 @@ pub fn create_consensus_manager_configs_and_channels( papyrus_network::gossipsub_impl::Topic::new( starknet_consensus_manager::consensus_manager::CONSENSUS_PROPOSALS_TOPIC, ), + available_ports, ); // TODO: Need to also add a channel for votes, in addition to the proposals channel. diff --git a/crates/starknet_integration_tests/tests/mempool_p2p_flow_test.rs b/crates/starknet_integration_tests/tests/mempool_p2p_flow_test.rs index 371c10f525..6a0233248a 100644 --- a/crates/starknet_integration_tests/tests/mempool_p2p_flow_test.rs +++ b/crates/starknet_integration_tests/tests/mempool_p2p_flow_test.rs @@ -19,6 +19,7 @@ use starknet_api::transaction::TransactionHash; use starknet_http_server::config::HttpServerConfig; use starknet_http_server::test_utils::HttpTestClient; use starknet_integration_tests::state_reader::{spawn_test_rpc_state_reader, StorageTestSetup}; +use starknet_integration_tests::test_identifiers::TestIdentifier; use starknet_integration_tests::utils::{ create_batcher_config, create_chain_info, @@ -32,6 +33,7 @@ use starknet_mempool_p2p::config::MempoolP2pConfig; use starknet_mempool_p2p::MEMPOOL_TOPIC; use starknet_monitoring_endpoint::config::MonitoringEndpointConfig; use starknet_monitoring_endpoint::test_utils::IsAliveClient; +use starknet_sequencer_infra::test_utils::AvailablePorts; use starknet_sequencer_node::config::component_config::ComponentConfig; use starknet_sequencer_node::config::component_execution_config::{ ActiveComponentExecutionConfig, @@ -47,7 +49,6 @@ fn tx_generator() -> MultiAccountTransactionGenerator { create_integration_test_tx_generator() } -// TODO(Shahak/AlonLukatch): add available_ports to the setup function. // TODO(Shahak/AlonLukatch): remove code duplication with FlowTestSetup. async fn setup( tx_generator: &MultiAccountTransactionGenerator, @@ -55,6 +56,7 @@ async fn setup( let accounts = tx_generator.accounts(); let chain_info = create_chain_info(); let storage_for_test = StorageTestSetup::new(accounts, &chain_info); + let mut available_ports = AvailablePorts::new(TestIdentifier::MempoolP2pFlowTest.into(), 0); // Spawn a papyrus rpc server for a papyrus storage reader. let rpc_server_addr = spawn_test_rpc_state_reader( @@ -88,6 +90,7 @@ async fn setup( create_network_configs_connected_to_broadcast_channels::( 1, Topic::new(MEMPOOL_TOPIC), + &mut available_ports, ); let network_config = network_configs.pop().unwrap(); let mempool_p2p_config = MempoolP2pConfig { network_config, ..Default::default() };