Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(starknet_integration_tests): use available ports for rpc state reader #2781

Open
wants to merge 1 commit into
base: spr/main/bcd73021
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading