Skip to content

Commit

Permalink
chore(starknet_integration_tests): use available ports for create con…
Browse files Browse the repository at this point in the history
…fig (unused)

commit-id:b339724d
  • Loading branch information
Itay-Tsabary-Starkware committed Dec 18, 2024
1 parent c813933 commit b108b6f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::integration_test_setup::IntegrationTestSetup;
use crate::utils::send_account_txs;

// TODO(Tsabary): create an enum that maps test names to unique indices, replace constants.
const TEST_UNIQUE_INDEX: u16 = 0;
const END_TO_END_INTEGRATION_TEST_UNIQUE_ID: u16 = 0;

/// Reads the latest block number from the storage.
fn get_latest_block_number(storage_reader: &StorageReader) -> BlockNumber {
Expand Down Expand Up @@ -65,8 +65,11 @@ pub async fn end_to_end_integration(mut tx_generator: MultiAccountTransactionGen

info!("Running integration test setup.");
// Creating the storage for the test.
let integration_test_setup =
IntegrationTestSetup::new_from_tx_generator(&tx_generator, TEST_UNIQUE_INDEX).await;
let integration_test_setup = IntegrationTestSetup::new_from_tx_generator(
&tx_generator,
END_TO_END_INTEGRATION_TEST_UNIQUE_ID,
)
.await;

info!("Running sequencer node.");
let node_run_handle = spawn_run_node(integration_test_setup.node_config_path).await;
Expand Down
10 changes: 9 additions & 1 deletion crates/starknet_integration_tests/src/flow_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use starknet_http_server::test_utils::HttpTestClient;
use starknet_mempool_p2p::config::MempoolP2pConfig;
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::node_config::SequencerNodeConfig;
use starknet_sequencer_node::servers::run_component_servers;
use starknet_sequencer_node::utils::create_node_modules;
Expand Down Expand Up @@ -41,7 +42,10 @@ pub struct FlowTestSetup {

impl FlowTestSetup {
#[instrument(skip(tx_generator), level = "debug")]
pub async fn new_from_tx_generator(tx_generator: &MultiAccountTransactionGenerator) -> Self {
pub async fn new_from_tx_generator(
tx_generator: &MultiAccountTransactionGenerator,
test_unique_index: u16,
) -> Self {
let chain_info = create_chain_info();

let accounts = tx_generator.accounts();
Expand All @@ -62,6 +66,7 @@ impl FlowTestSetup {
chain_info.clone(),
sequencer_0_consensus_manager_config,
sequencer_0_mempool_p2p_config,
AvailablePorts::new(test_unique_index, 0),
)
.await;
let sequencer_1 = SequencerSetup::new(
Expand All @@ -70,6 +75,7 @@ impl FlowTestSetup {
chain_info,
sequencer_1_consensus_manager_config,
sequencer_1_mempool_p2p_config,
AvailablePorts::new(test_unique_index, 1),
)
.await;

Expand Down Expand Up @@ -108,6 +114,7 @@ impl SequencerSetup {
chain_info: ChainInfo,
consensus_manager_config: ConsensusManagerConfig,
mempool_p2p_config: MempoolP2pConfig,
mut available_ports: AvailablePorts,
) -> Self {
let storage_for_test = StorageTestSetup::new(accounts, &chain_info);

Expand All @@ -120,6 +127,7 @@ impl SequencerSetup {

// Derive the configuration for the sequencer node.
let (config, _required_params) = create_config(
&mut available_ports,
sequencer_index,
chain_info,
rpc_server_addr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl IntegrationTestSetup {

// Derive the configuration for the sequencer node.
let (config, required_params) = create_config(
&mut available_ports,
SEQUENCER_INDEX,
chain_info,
rpc_server_addr,
Expand Down
6 changes: 5 additions & 1 deletion crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use starknet_gateway::config::{
use starknet_http_server::config::HttpServerConfig;
use starknet_mempool_p2p::config::MempoolP2pConfig;
use starknet_monitoring_endpoint::config::MonitoringEndpointConfig;
use starknet_sequencer_infra::test_utils::get_available_socket;
use starknet_sequencer_infra::test_utils::{get_available_socket, AvailablePorts};
use starknet_sequencer_node::config::node_config::SequencerNodeConfig;
use starknet_sequencer_node::config::test_utils::RequiredParams;
use starknet_state_sync::config::StateSyncConfig;
Expand All @@ -45,9 +45,13 @@ pub fn create_chain_info() -> ChainInfo {
chain_info
}

// TODO(Tsabary/Shahak/Yair/AlonH): this function needs a proper cleaning.
// TODO(yair, Tsabary): Create config presets for tests, then remove all the functions that modify
// the config.
#[allow(clippy::too_many_arguments)]
#[allow(unused_variables)]
pub async fn create_config(
available_ports: &mut AvailablePorts,
sequencer_index: usize,
chain_info: ChainInfo,
rpc_server_addr: SocketAddr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ use tracing::debug;
const INITIAL_HEIGHT: BlockNumber = BlockNumber(0);
const LAST_HEIGHT: BlockNumber = BlockNumber(2);

// TODO(Tsabary): create an enum that maps test names to unique indices, replace constants.
const END_TO_END_FLOW_TEST_UNIQUE_ID: u16 = 1;

#[fixture]
fn tx_generator() -> MultiAccountTransactionGenerator {
create_integration_test_tx_generator()
Expand All @@ -41,7 +44,8 @@ async fn end_to_end_flow(mut tx_generator: MultiAccountTransactionGenerator) {
const LISTEN_TO_BROADCAST_MESSAGES_TIMEOUT: std::time::Duration =
std::time::Duration::from_secs(50);
// Setup.
let mut mock_running_system = FlowTestSetup::new_from_tx_generator(&tx_generator).await;
let mut mock_running_system =
FlowTestSetup::new_from_tx_generator(&tx_generator, END_TO_END_FLOW_TEST_UNIQUE_ID).await;

tokio::join!(
wait_for_sequencer_node(&mock_running_system.sequencer_0),
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_sequencer_infra/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const MAX_NUMBER_OF_NODES: u16 = 10;
const MAX_NUMBER_OF_TESTS: u16 = 10;
const BASE_PORT: u16 = 55000;

#[derive(Debug)]
pub struct AvailablePorts {
current_port: u16,
max_port: u16,
Expand Down

0 comments on commit b108b6f

Please sign in to comment.