From 8cb426adb088fa0e7270d6ca2b66f89da82ad5f8 Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Wed, 18 Dec 2024 20:02:04 +0200 Subject: [PATCH] chore(starknet_integration_tests): use available ports for rpc state reader commit-id:066046d4 --- .../src/integration_test_setup.rs | 7 ++++--- .../src/state_reader.rs | 20 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/crates/starknet_integration_tests/src/integration_test_setup.rs b/crates/starknet_integration_tests/src/integration_test_setup.rs index 673f3b61520..91502e49da0 100644 --- a/crates/starknet_integration_tests/src/integration_test_setup.rs +++ b/crates/starknet_integration_tests/src/integration_test_setup.rs @@ -11,7 +11,7 @@ use starknet_sequencer_infra::test_utils::AvailablePorts; use tempfile::{tempdir, TempDir}; use crate::config_utils::dump_config_file_changes; -use crate::state_reader::{spawn_test_rpc_state_reader, StorageTestSetup}; +use crate::state_reader::{spawn_test_rpc_state_reader_with_socket, StorageTestSetup}; use crate::utils::{ create_chain_info, create_config, @@ -53,16 +53,17 @@ impl IntegrationTestSetup { tx_generator: &MultiAccountTransactionGenerator, test_unique_index: u16, ) -> Self { - let available_ports = AvailablePorts::new(test_unique_index, 0); + let mut available_ports = AvailablePorts::new(test_unique_index, 0); let chain_info = create_chain_info(); // Creating the storage for the test. let storage_for_test = StorageTestSetup::new(tx_generator.accounts(), &chain_info); // Spawn a papyrus rpc server for a papyrus storage reader. - let rpc_server_addr = spawn_test_rpc_state_reader( + let rpc_server_addr = spawn_test_rpc_state_reader_with_socket( storage_for_test.rpc_storage_reader, chain_info.chain_id.clone(), + available_ports.get_next_local_host_socket(), ) .await; diff --git a/crates/starknet_integration_tests/src/state_reader.rs b/crates/starknet_integration_tests/src/state_reader.rs index 61d511ad4d7..e75ea8cd0c2 100644 --- a/crates/starknet_integration_tests/src/state_reader.rs +++ b/crates/starknet_integration_tests/src/state_reader.rs @@ -274,17 +274,25 @@ fn test_block_header(block_number: BlockNumber) -> BlockHeader { } } -/// Spawns a papyrus rpc server for given state reader. +/// Spawns a papyrus rpc server for given state reader and chain id. /// Returns the address of the rpc server. pub async fn spawn_test_rpc_state_reader( storage_reader: StorageReader, chain_id: ChainId, ) -> SocketAddr { - let rpc_config = RpcConfig { - chain_id, - server_address: get_available_socket().await.to_string(), - ..Default::default() - }; + let socket = get_available_socket().await; + spawn_test_rpc_state_reader_with_socket(storage_reader, chain_id, socket).await; + socket +} + +/// Spawns a papyrus rpc server for given state reader, chain id, and socket address. +pub async fn spawn_test_rpc_state_reader_with_socket( + storage_reader: StorageReader, + chain_id: ChainId, + socket: SocketAddr, +) -> SocketAddr { + let rpc_config = + RpcConfig { chain_id, server_address: socket.to_string(), ..Default::default() }; let (addr, handle) = run_server( &rpc_config, Arc::new(RwLock::new(None)),