diff --git a/Cargo.lock b/Cargo.lock index 820ae787d..ed7c3ddd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5470,6 +5470,7 @@ dependencies = [ "starknet_mempool_infra", "starknet_mempool_types", "starknet_sierra_compile", + "starknet_state_reader", "thiserror", "tokio", "tracing", @@ -5592,6 +5593,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "starknet_state_reader" +version = "0.0.0" +dependencies = [ + "blockifier 0.8.0-rc.0 (git+https://github.com/starkware-libs/blockifier.git?rev=32191d41)", + "mempool_test_utils", + "starknet-types-core", + "starknet_api", +] + [[package]] name = "starknet_task_executor" version = "0.0.0" @@ -5602,10 +5613,6 @@ dependencies = [ "tokio-test", ] -[[package]] -name = "state_reader" -version = "0.0.0" - [[package]] name = "static_assertions" version = "1.1.0" diff --git a/crates/gateway/Cargo.toml b/crates/gateway/Cargo.toml index 0d93cbfdb..5f99737d6 100644 --- a/crates/gateway/Cargo.toml +++ b/crates/gateway/Cargo.toml @@ -14,22 +14,23 @@ testing = [] [dependencies] async-trait.workspace = true axum.workspace = true -blockifier= { workspace = true, features = ["testing"] } +blockifier = { workspace = true, features = ["testing"] } cairo-lang-starknet-classes.workspace = true cairo-vm.workspace = true hyper.workspace = true +mempool_test_utils = { path = "../mempool_test_utils", version = "0.0" } num-traits.workspace = true papyrus_config.workspace = true papyrus_rpc.workspace = true reqwest.workspace = true serde.workspace = true serde_json.workspace = true +starknet-types-core.workspace = true starknet_api.workspace = true starknet_mempool_infra = { path = "../mempool_infra", version = "0.0" } starknet_mempool_types = { path = "../mempool_types", version = "0.0" } starknet_sierra_compile = { path = "../starknet_sierra_compile", version = "0.0" } -starknet-types-core.workspace = true -mempool_test_utils = { path = "../mempool_test_utils", version = "0.0"} +starknet_state_reader = { path = "../state_reader", version = "0.0", features = ["testing"] } thiserror.workspace = true tokio.workspace = true tracing.workspace = true diff --git a/crates/gateway/src/gateway.rs b/crates/gateway/src/gateway.rs index 9d1a53fdb..0d971413a 100644 --- a/crates/gateway/src/gateway.rs +++ b/crates/gateway/src/gateway.rs @@ -11,13 +11,13 @@ use starknet_api::transaction::TransactionHash; use starknet_mempool_infra::component_runner::{ComponentStartError, ComponentStarter}; use starknet_mempool_types::communication::SharedMempoolClient; use starknet_mempool_types::mempool_types::{Account, MempoolInput}; +use starknet_state_reader::state_reader::StateReaderFactory; use tracing::{info, instrument}; use crate::compilation::GatewayCompiler; use crate::config::{GatewayConfig, GatewayNetworkConfig, RpcStateReaderConfig}; use crate::errors::{GatewayError, GatewayResult, GatewayRunError}; use crate::rpc_state_reader::RpcStateReaderFactory; -use crate::state_reader::StateReaderFactory; use crate::stateful_transaction_validator::StatefulTransactionValidator; use crate::stateless_transaction_validator::StatelessTransactionValidator; use crate::utils::{external_tx_to_thin_tx, get_sender_address}; diff --git a/crates/gateway/src/gateway_test.rs b/crates/gateway/src/gateway_test.rs index d88d55cbb..4f5c03ef3 100644 --- a/crates/gateway/src/gateway_test.rs +++ b/crates/gateway/src/gateway_test.rs @@ -13,13 +13,15 @@ use starknet_api::rpc_transaction::RPCTransaction; use starknet_api::transaction::TransactionHash; use starknet_mempool_types::communication::MockMempoolClient; use starknet_mempool_types::mempool_types::{Account, AccountState, MempoolInput, ThinTransaction}; +use starknet_state_reader::state_reader_test_utils::{ + local_test_state_reader_factory, TestStateReaderFactory, +}; use crate::compilation::GatewayCompiler; use crate::config::{ GatewayCompilerConfig, StatefulTransactionValidatorConfig, StatelessTransactionValidatorConfig, }; use crate::gateway::{add_tx, AppState, SharedMempoolClient}; -use crate::state_reader_test_utils::{local_test_state_reader_factory, TestStateReaderFactory}; use crate::stateful_transaction_validator::StatefulTransactionValidator; use crate::stateless_transaction_validator::StatelessTransactionValidator; use crate::utils::{external_tx_to_account_tx, get_tx_hash}; diff --git a/crates/gateway/src/lib.rs b/crates/gateway/src/lib.rs index bb9ff7c55..4a724b5b9 100644 --- a/crates/gateway/src/lib.rs +++ b/crates/gateway/src/lib.rs @@ -8,9 +8,7 @@ mod rpc_objects; mod rpc_state_reader; #[cfg(test)] mod rpc_state_reader_test; -mod state_reader; -#[cfg(test)] -mod state_reader_test_utils; + mod stateful_transaction_validator; mod stateless_transaction_validator; #[cfg(test)] diff --git a/crates/gateway/src/rpc_state_reader.rs b/crates/gateway/src/rpc_state_reader.rs index a5af4fe6d..d83431a65 100644 --- a/crates/gateway/src/rpc_state_reader.rs +++ b/crates/gateway/src/rpc_state_reader.rs @@ -9,6 +9,7 @@ use serde_json::{json, Value}; use starknet_api::block::BlockNumber; use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use starknet_api::state::StorageKey; +use starknet_state_reader::state_reader::{MempoolStateReader, StateReaderFactory}; use starknet_types_core::felt::Felt; use crate::config::RpcStateReaderConfig; @@ -18,7 +19,6 @@ use crate::rpc_objects::{ GetCompiledContractClassParams, GetNonceParams, GetStorageAtParams, RpcResponse, RPC_CLASS_HASH_NOT_FOUND, RPC_ERROR_BLOCK_NOT_FOUND, RPC_ERROR_CONTRACT_ADDRESS_NOT_FOUND, }; -use crate::state_reader::{MempoolStateReader, StateReaderFactory}; pub struct RpcStateReader { pub config: RpcStateReaderConfig, diff --git a/crates/gateway/src/rpc_state_reader_test.rs b/crates/gateway/src/rpc_state_reader_test.rs index 3596d484d..4d8144cbc 100644 --- a/crates/gateway/src/rpc_state_reader_test.rs +++ b/crates/gateway/src/rpc_state_reader_test.rs @@ -7,6 +7,7 @@ use serde_json::json; use starknet_api::block::{BlockNumber, GasPrice}; use starknet_api::core::{ClassHash, ContractAddress, Nonce, PatriciaKey}; use starknet_api::{class_hash, contract_address, felt, patricia_key}; +use starknet_state_reader::state_reader::MempoolStateReader; use crate::config::RpcStateReaderConfig; use crate::rpc_objects::{ @@ -15,7 +16,6 @@ use crate::rpc_objects::{ RpcSuccessResponse, }; use crate::rpc_state_reader::RpcStateReader; -use crate::state_reader::MempoolStateReader; async fn run_rpc_server() -> mockito::ServerGuard { mockito::Server::new_async().await diff --git a/crates/gateway/src/stateful_transaction_validator.rs b/crates/gateway/src/stateful_transaction_validator.rs index a14018664..549b9d07d 100644 --- a/crates/gateway/src/stateful_transaction_validator.rs +++ b/crates/gateway/src/stateful_transaction_validator.rs @@ -8,11 +8,11 @@ use blockifier::versioned_constants::VersionedConstants; use starknet_api::core::Nonce; use starknet_api::rpc_transaction::{RPCInvokeTransaction, RPCTransaction}; use starknet_api::transaction::TransactionHash; +use starknet_state_reader::state_reader::{MempoolStateReader, StateReaderFactory}; use starknet_types_core::felt::Felt; use crate::config::StatefulTransactionValidatorConfig; use crate::errors::{StatefulTransactionValidatorError, StatefulTransactionValidatorResult}; -use crate::state_reader::{MempoolStateReader, StateReaderFactory}; use crate::utils::{external_tx_to_account_tx, get_sender_address, get_tx_hash}; #[cfg(test)] diff --git a/crates/gateway/src/stateful_transaction_validator_test.rs b/crates/gateway/src/stateful_transaction_validator_test.rs index 6a27fd350..b29fc2541 100644 --- a/crates/gateway/src/stateful_transaction_validator_test.rs +++ b/crates/gateway/src/stateful_transaction_validator_test.rs @@ -16,15 +16,15 @@ use starknet_api::core::{ContractAddress, Nonce}; use starknet_api::felt; use starknet_api::rpc_transaction::RPCTransaction; use starknet_api::transaction::TransactionHash; +use starknet_state_reader::state_reader_test_utils::{ + local_test_state_reader_factory, local_test_state_reader_factory_for_deploy_account, + TestStateReader, TestStateReaderFactory, +}; use starknet_types_core::felt::Felt; use crate::compilation::GatewayCompiler; use crate::config::{GatewayCompilerConfig, StatefulTransactionValidatorConfig}; use crate::errors::{StatefulTransactionValidatorError, StatefulTransactionValidatorResult}; -use crate::state_reader_test_utils::{ - local_test_state_reader_factory, local_test_state_reader_factory_for_deploy_account, - TestStateReader, TestStateReaderFactory, -}; use crate::stateful_transaction_validator::StatefulTransactionValidator; #[fixture] diff --git a/crates/state_reader/Cargo.toml b/crates/state_reader/Cargo.toml index 04bd50691..90f2236bc 100644 --- a/crates/state_reader/Cargo.toml +++ b/crates/state_reader/Cargo.toml @@ -1,11 +1,18 @@ [package] -name = "state_reader" +name = "starknet_state_reader" version.workspace = true edition.workspace = true repository.workspace = true license.workspace = true -[dependencies] - [lints] workspace = true + +[features] +testing = [] + +[dependencies] +blockifier = { workspace = true, features = ["testing"] } +mempool_test_utils = { path = "../mempool_test_utils", version = "0.0" } +starknet-types-core.workspace = true +starknet_api.workspace = true diff --git a/crates/state_reader/src/lib.rs b/crates/state_reader/src/lib.rs index 8b1378917..96990f690 100644 --- a/crates/state_reader/src/lib.rs +++ b/crates/state_reader/src/lib.rs @@ -1 +1,4 @@ +pub mod state_reader; +#[cfg(any(feature = "testing", test))] +pub mod state_reader_test_utils; diff --git a/crates/gateway/src/state_reader.rs b/crates/state_reader/src/state_reader.rs similarity index 100% rename from crates/gateway/src/state_reader.rs rename to crates/state_reader/src/state_reader.rs diff --git a/crates/gateway/src/state_reader_test_utils.rs b/crates/state_reader/src/state_reader_test_utils.rs similarity index 100% rename from crates/gateway/src/state_reader_test_utils.rs rename to crates/state_reader/src/state_reader_test_utils.rs