From 9eb4575c3345cf2be7d0d743f8dde47652d1f256 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Sun, 5 Jan 2025 14:27:37 +0200 Subject: [PATCH] chore(starknet_gateway): move the bench utils into the bench folder --- crates/starknet_gateway/bench/main.rs | 5 ++++- .../{src/bench_test_utils.rs => bench/utils.rs} | 9 ++++----- crates/starknet_gateway/src/lib.rs | 4 ++-- crates/starknet_gateway/src/state_reader_test_utils.rs | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) rename crates/starknet_gateway/{src/bench_test_utils.rs => bench/utils.rs} (94%) diff --git a/crates/starknet_gateway/bench/main.rs b/crates/starknet_gateway/bench/main.rs index bb57045b8f..b902510afd 100644 --- a/crates/starknet_gateway/bench/main.rs +++ b/crates/starknet_gateway/bench/main.rs @@ -9,8 +9,11 @@ //! //! Run the benchmarks using `cargo bench --bench gateway_bench`. +// import the Gateway test utilities. +mod utils; + use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; -use starknet_gateway::bench_test_utils::{BenchTestSetup, BenchTestSetupConfig}; +use utils::{BenchTestSetup, BenchTestSetupConfig}; fn invoke_benchmark(criterion: &mut Criterion) { let tx_generator_config = BenchTestSetupConfig::default(); diff --git a/crates/starknet_gateway/src/bench_test_utils.rs b/crates/starknet_gateway/bench/utils.rs similarity index 94% rename from crates/starknet_gateway/src/bench_test_utils.rs rename to crates/starknet_gateway/bench/utils.rs index 5da8608821..7bf56b8c54 100644 --- a/crates/starknet_gateway/src/bench_test_utils.rs +++ b/crates/starknet_gateway/bench/utils.rs @@ -9,14 +9,13 @@ use starknet_api::invoke_tx_args; use starknet_api::rpc_transaction::RpcTransaction; use starknet_api::test_utils::invoke::rpc_invoke_tx; use starknet_api::test_utils::NonceManager; +use starknet_gateway::compilation::GatewayCompiler; +use starknet_gateway::config::GatewayConfig; +use starknet_gateway::gateway::Gateway; +use starknet_gateway::state_reader_test_utils::local_test_state_reader_factory; use starknet_mempool_types::communication::MockMempoolClient; use starknet_sierra_compile::config::SierraToCasmCompilationConfig; -use crate::compilation::GatewayCompiler; -use crate::config::GatewayConfig; -use crate::gateway::Gateway; -use crate::state_reader_test_utils::local_test_state_reader_factory; - const N_TXS: usize = 100; // TODO(Arni): Use `AccountTransactionGenerator` from `starknet_api_test_utils`. diff --git a/crates/starknet_gateway/src/lib.rs b/crates/starknet_gateway/src/lib.rs index 9707375e2e..704ca65a9c 100644 --- a/crates/starknet_gateway/src/lib.rs +++ b/crates/starknet_gateway/src/lib.rs @@ -1,4 +1,3 @@ -pub mod bench_test_utils; pub mod communication; pub mod compilation; mod compiler_version; @@ -10,7 +9,8 @@ pub mod rpc_state_reader; #[cfg(test)] mod rpc_state_reader_test; pub mod state_reader; -mod state_reader_test_utils; +#[cfg(any(feature = "testing", test))] +pub mod state_reader_test_utils; mod stateful_transaction_validator; mod stateless_transaction_validator; mod sync_state_reader; diff --git a/crates/starknet_gateway/src/state_reader_test_utils.rs b/crates/starknet_gateway/src/state_reader_test_utils.rs index f81e15a8b0..9b505af103 100644 --- a/crates/starknet_gateway/src/state_reader_test_utils.rs +++ b/crates/starknet_gateway/src/state_reader_test_utils.rs @@ -16,7 +16,7 @@ use starknet_types_core::felt::Felt; use crate::state_reader::{MempoolStateReader, StateReaderFactory}; #[derive(Clone)] -pub(crate) struct TestStateReader { +pub struct TestStateReader { pub block_info: BlockInfo, pub blockifier_state_reader: DictStateReader, } @@ -53,7 +53,7 @@ impl BlockifierStateReader for TestStateReader { } } -pub(crate) struct TestStateReaderFactory { +pub struct TestStateReaderFactory { pub state_reader: TestStateReader, } @@ -69,7 +69,7 @@ impl StateReaderFactory for TestStateReaderFactory { } } -pub(crate) fn local_test_state_reader_factory( +pub fn local_test_state_reader_factory( cairo_version: CairoVersion, zero_balance: bool, ) -> TestStateReaderFactory {