Skip to content

Commit

Permalink
chore(starknet_integration_tests): use available ports for rpc state …
Browse files Browse the repository at this point in the history
…reader

commit-id:066046d4
  • Loading branch information
Itay-Tsabary-Starkware committed Dec 18, 2024
1 parent 75d09c9 commit c813933
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
20 changes: 14 additions & 6 deletions crates/starknet_integration_tests/src/state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down

0 comments on commit c813933

Please sign in to comment.