Skip to content

Commit

Permalink
chore(starknet_integration_tests): add available ports to network config
Browse files Browse the repository at this point in the history
commit-id:f09b3b07
  • Loading branch information
Itay-Tsabary-Starkware committed Dec 18, 2024
1 parent 4b5f655 commit 64adf22
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/papyrus_network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository.workspace = true
license-file.workspace = true

[features]
testing = []
testing = ["starknet_sequencer_infra/testing"]

[dependencies]
async-stream.workspace = true
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions crates/papyrus_network/src/network_manager/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -177,9 +178,12 @@ 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,
available_ports: &mut AvailablePorts,
) -> (Vec<NetworkConfig>, BroadcastTopicChannels<T>)
where
T: TryFrom<Bytes> + 'static,
Expand Down
10 changes: 7 additions & 3 deletions crates/starknet_integration_tests/src/flow_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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(
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
2 changes: 2 additions & 0 deletions crates/starknet_integration_tests/src/test_identifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
pub enum TestIdentifier {
EndToEndIntegrationTest,
EndToEndFlowTest,
MempoolP2pFlowTest,
}

impl From<TestIdentifier> for u16 {
fn from(variant: TestIdentifier) -> Self {
match variant {
TestIdentifier::EndToEndIntegrationTest => 0,
TestIdentifier::EndToEndFlowTest => 1,
TestIdentifier::MempoolP2pFlowTest => 2,
}
}
}
2 changes: 2 additions & 0 deletions crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ pub async fn create_config(

pub fn create_consensus_manager_configs_and_channels(
n_managers: usize,
available_ports: &mut AvailablePorts,
) -> (Vec<ConsensusManagerConfig>, BroadcastTopicChannels<StreamMessage<ProposalPart>>) {
let (network_configs, broadcast_channels) =
create_network_configs_connected_to_broadcast_channels(
n_managers,
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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -47,14 +49,14 @@ 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,
) -> (SequencerNodeConfig, BroadcastTopicChannels<RpcTransactionWrapper>) {
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(
Expand Down Expand Up @@ -88,6 +90,7 @@ async fn setup(
create_network_configs_connected_to_broadcast_channels::<RpcTransactionWrapper>(
1,
Topic::new(MEMPOOL_TOPIC),
&mut available_ports,
);
let network_config = network_configs.pop().unwrap();
let mempool_p2p_config = MempoolP2pConfig { network_config, ..Default::default() };
Expand Down

0 comments on commit 64adf22

Please sign in to comment.