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

wip #3313

Open
wants to merge 3 commits into
base: spr/main/8c7534bd
Choose a base branch
from
Open

wip #3313

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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/starknet_infra_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ repository.workspace = true
license-file.workspace = true
description = "Infrastructure utility."

[features]
testing = []

[lints]
workspace = true

Expand Down
2 changes: 2 additions & 0 deletions crates/starknet_infra_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion crates/starknet_integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
1 change: 0 additions & 1 deletion crates/starknet_integration_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion crates/starknet_integration_tests/src/sequencer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
46 changes: 2 additions & 44 deletions crates/starknet_integration_tests/src/state_reader.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -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::{
Expand All @@ -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)>);
Expand Down Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_sequencer_infra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Arc<Mutex<YourSharedDataType>>> = 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<ComponentARequest, ComponentAResponse> {
async fn a_get_value(&self) -> ResultA {
Expand Down
Loading