From 130800477f6bd7a329ff4836044ddf3526e7105a Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Tue, 14 Jan 2025 15:07:03 +0200 Subject: [PATCH 1/3] chore(starknet_integration_tests): delete deprecated fns commit-id:d9a2ae58 --- .../src/state_reader.rs | 46 +------------------ 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/crates/starknet_integration_tests/src/state_reader.rs b/crates/starknet_integration_tests/src/state_reader.rs index 7add790e68..8dd947743d 100644 --- a/crates/starknet_integration_tests/src/state_reader.rs +++ b/crates/starknet_integration_tests/src/state_reader.rs @@ -1,6 +1,4 @@ use std::collections::HashMap; -use std::net::SocketAddr; -use std::sync::Arc; use assert_matches::assert_matches; use blockifier::context::ChainInfo; @@ -11,15 +9,13 @@ use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use indexmap::IndexMap; use itertools::Itertools; use mempool_test_utils::starknet_api_test_utils::{AccountTransactionGenerator, Contract}; -use papyrus_common::pending_classes::PendingClasses; -use papyrus_rpc::{run_server, RpcConfig}; use papyrus_storage::body::BodyStorageWriter; use papyrus_storage::class::ClassStorageWriter; use papyrus_storage::compiled_class::CasmStorageWriter; use papyrus_storage::header::HeaderStorageWriter; use papyrus_storage::state::StateStorageWriter; use papyrus_storage::test_utils::TestStorageBuilder; -use papyrus_storage::{StorageConfig, StorageReader, StorageScope, StorageWriter}; +use papyrus_storage::{StorageConfig, StorageScope, StorageWriter}; use starknet_api::abi::abi_utils::get_fee_token_var_address; use starknet_api::block::{ BlockBody, @@ -30,7 +26,7 @@ use starknet_api::block::{ FeeType, GasPricePerToken, }; -use starknet_api::core::{ChainId, ClassHash, ContractAddress, Nonce, SequencerContractAddress}; +use starknet_api::core::{ClassHash, ContractAddress, Nonce, SequencerContractAddress}; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; use starknet_api::state::{SierraContractClass, StorageKey, ThinStateDiff}; use starknet_api::test_utils::{ @@ -41,12 +37,9 @@ use starknet_api::test_utils::{ }; use starknet_api::transaction::fields::Fee; use starknet_api::{contract_address, felt}; -use starknet_client::reader::PendingData; -use starknet_sequencer_infra::test_utils::get_available_socket; use starknet_types_core::felt::Felt; use strum::IntoEnumIterator; use tempfile::TempDir; -use tokio::sync::RwLock; type ContractClassesMap = (Vec<(ClassHash, DeprecatedContractClass)>, Vec<(ClassHash, CasmContractClass)>); @@ -287,41 +280,6 @@ fn test_block_header(block_number: BlockNumber) -> BlockHeader { } } -/// 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 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)), - Arc::new(RwLock::new(PendingData::default())), - Arc::new(RwLock::new(PendingClasses::default())), - storage_reader, - "NODE VERSION", - ) - .await - .unwrap(); - // Spawn the server handle to keep the server running, otherwise the server will stop once the - // handler is out of scope. - tokio::spawn(handle.stopped()); - addr -} - /// Constructs a thin state diff from lists of contracts, where each contract can be declared, /// deployed, and in case it is an account, funded. #[derive(Default)] From 1b914ec7a71f839b0e3ee633126d073020736402 Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Tue, 14 Jan 2025 15:20:15 +0200 Subject: [PATCH 2/3] chore(starknet_infra_utils): move fn from integration test commit-id:8c7534bd --- crates/starknet_infra_utils/Cargo.toml | 3 +++ crates/starknet_infra_utils/src/lib.rs | 2 ++ .../src/test_identifiers.rs | 0 crates/starknet_integration_tests/Cargo.toml | 2 +- crates/starknet_integration_tests/src/lib.rs | 1 - crates/starknet_integration_tests/src/sequencer_manager.rs | 2 +- .../starknet_integration_tests/tests/end_to_end_flow_test.rs | 2 +- 7 files changed, 8 insertions(+), 4 deletions(-) rename crates/{starknet_integration_tests => starknet_infra_utils}/src/test_identifiers.rs (100%) diff --git a/crates/starknet_infra_utils/Cargo.toml b/crates/starknet_infra_utils/Cargo.toml index 203de97ae0..de9fa0b1f1 100644 --- a/crates/starknet_infra_utils/Cargo.toml +++ b/crates/starknet_infra_utils/Cargo.toml @@ -6,6 +6,9 @@ repository.workspace = true license-file.workspace = true description = "Infrastructure utility." +[features] +testing = [] + [lints] workspace = true diff --git a/crates/starknet_infra_utils/src/lib.rs b/crates/starknet_infra_utils/src/lib.rs index 548702976e..ed5c7d9a11 100644 --- a/crates/starknet_infra_utils/src/lib.rs +++ b/crates/starknet_infra_utils/src/lib.rs @@ -3,5 +3,7 @@ pub mod metrics; pub mod path; pub mod run_until; pub mod tasks; +#[cfg(any(feature = "testing", test))] +pub mod test_identifiers; pub mod tracing; pub mod type_name; diff --git a/crates/starknet_integration_tests/src/test_identifiers.rs b/crates/starknet_infra_utils/src/test_identifiers.rs similarity index 100% rename from crates/starknet_integration_tests/src/test_identifiers.rs rename to crates/starknet_infra_utils/src/test_identifiers.rs diff --git a/crates/starknet_integration_tests/Cargo.toml b/crates/starknet_integration_tests/Cargo.toml index b8d2a5d537..11ec9e3790 100644 --- a/crates/starknet_integration_tests/Cargo.toml +++ b/crates/starknet_integration_tests/Cargo.toml @@ -35,7 +35,7 @@ starknet_consensus_manager.workspace = true starknet_gateway = { workspace = true, features = ["testing"] } starknet_gateway_types.workspace = true starknet_http_server = { workspace = true, features = ["testing"] } -starknet_infra_utils.workspace = true +starknet_infra_utils = { workspace = true, features = ["testing"] } starknet_mempool_p2p.workspace = true starknet_monitoring_endpoint = { workspace = true, features = ["testing"] } starknet_sequencer_infra = { workspace = true, features = ["testing"] } diff --git a/crates/starknet_integration_tests/src/lib.rs b/crates/starknet_integration_tests/src/lib.rs index b4a6d5463b..12d39b661f 100644 --- a/crates/starknet_integration_tests/src/lib.rs +++ b/crates/starknet_integration_tests/src/lib.rs @@ -4,5 +4,4 @@ pub mod flow_test_setup; pub mod integration_test_setup; pub mod sequencer_manager; pub mod state_reader; -pub mod test_identifiers; pub mod utils; diff --git a/crates/starknet_integration_tests/src/sequencer_manager.rs b/crates/starknet_integration_tests/src/sequencer_manager.rs index 5b400fd600..02d8d20258 100644 --- a/crates/starknet_integration_tests/src/sequencer_manager.rs +++ b/crates/starknet_integration_tests/src/sequencer_manager.rs @@ -15,6 +15,7 @@ use starknet_api::rpc_transaction::RpcTransaction; use starknet_api::state::StateNumber; use starknet_api::transaction::TransactionHash; use starknet_infra_utils::run_until::run_until; +use starknet_infra_utils::test_identifiers::TestIdentifier; use starknet_infra_utils::tracing::{CustomLogger, TraceLevel}; use starknet_sequencer_infra::test_utils::{AvailablePorts, MAX_NUMBER_OF_INSTANCES_PER_TEST}; use starknet_sequencer_node::config::component_config::ComponentConfig; @@ -28,7 +29,6 @@ use tokio::task::JoinHandle; use tracing::info; use crate::integration_test_setup::{SequencerExecutionId, SequencerSetup}; -use crate::test_identifiers::TestIdentifier; use crate::utils::{ create_chain_info, create_consensus_manager_configs_from_network_configs, diff --git a/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs b/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs index 9b10a33c97..9be4636260 100644 --- a/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs +++ b/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs @@ -18,8 +18,8 @@ use rstest::{fixture, rstest}; use starknet_api::block::{BlockHash, BlockNumber}; use starknet_api::rpc_transaction::RpcTransaction; use starknet_api::transaction::TransactionHash; +use starknet_infra_utils::test_identifiers::TestIdentifier; use starknet_integration_tests::flow_test_setup::{FlowSequencerSetup, FlowTestSetup}; -use starknet_integration_tests::test_identifiers::TestIdentifier; use starknet_integration_tests::utils::{ create_funding_txs, create_integration_test_tx_generator, From 6027fc67e3123188749437a1c24f27ea4710675c Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Tue, 14 Jan 2025 15:52:59 +0200 Subject: [PATCH 3/3] wip commit-id:24d31106 --- Cargo.lock | 1 + crates/starknet_sequencer_infra/Cargo.toml | 1 + .../remote_component_client_server_test.rs | 30 ++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ef5fea3552..4ab708895a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11141,6 +11141,7 @@ dependencies = [ "assert_matches", "async-trait", "hyper 0.14.32", + "once_cell", "papyrus_config", "pretty_assertions", "rstest", diff --git a/crates/starknet_sequencer_infra/Cargo.toml b/crates/starknet_sequencer_infra/Cargo.toml index 08d60b14e8..470a95b778 100644 --- a/crates/starknet_sequencer_infra/Cargo.toml +++ b/crates/starknet_sequencer_infra/Cargo.toml @@ -29,5 +29,6 @@ validator.workspace = true [dev-dependencies] assert_matches.workspace = true +once_cell.workspace = true pretty_assertions.workspace = true starknet-types-core.workspace = true diff --git a/crates/starknet_sequencer_infra/src/tests/remote_component_client_server_test.rs b/crates/starknet_sequencer_infra/src/tests/remote_component_client_server_test.rs index c0284a71a7..a7bc97f0df 100644 --- a/crates/starknet_sequencer_infra/src/tests/remote_component_client_server_test.rs +++ b/crates/starknet_sequencer_infra/src/tests/remote_component_client_server_test.rs @@ -1,7 +1,8 @@ use std::fmt::Debug; use std::net::SocketAddr; use std::sync::Arc; - +use once_cell::sync::Lazy; +use std::sync::{Arc, Mutex}; use async_trait::async_trait; use hyper::body::to_bytes; use hyper::header::CONTENT_TYPE; @@ -64,6 +65,33 @@ const DESERIALIZE_REQ_ERROR_MESSAGE: &str = "Could not deserialize client reques const DESERIALIZE_RES_ERROR_MESSAGE: &str = "Could not deserialize server response"; const VALID_VALUE_A: ValueA = Felt::ONE; + + +// Define the shared fixture +static TEST_PORTS: Lazy>> = Lazy::new(|| { + let mut available_ports = AvailablePorts::new(test_unique_index, 0); + Arc::new(Mutex::new(fixture)) +}); + +// Mock data type for illustration +struct YourSharedDataType { + value: u32, +} + +impl YourSharedDataType { + fn new() -> Self { + Self { value: 0 } + } + + fn increment(&mut self) { + self.value += 1; + } + + fn get_value(&self) -> u32 { + self.value + } +} + #[async_trait] impl ComponentAClientTrait for RemoteComponentClient { async fn a_get_value(&self) -> ResultA {