Skip to content
Merged
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
34 changes: 33 additions & 1 deletion crates/storage/provider/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use alloy_primitives::B256;
use reth_chainspec::{ChainSpec, MAINNET};
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
use reth_db::{mdbx::DatabaseArguments, test_utils::TempDatabase, DatabaseEnv};
use reth_errors::ProviderResult;
use reth_ethereum_engine_primitives::EthEngineTypes;
use reth_node_types::NodeTypesWithDBAdapter;
Expand Down Expand Up @@ -82,6 +82,38 @@ pub fn create_test_provider_factory_with_node_types<N: NodeTypesForProvider>(
.expect("failed to create test provider factory")
}

/// Creates test provider factory with provided chain spec and custom database arguments.
///
/// Same as [`create_test_provider_factory_with_chain_spec`] but allows overriding the default
/// test database arguments (e.g. to increase the MDBX geometry for heavy benchmarks).
pub fn create_test_provider_factory_with_chain_spec_and_db_args(
chain_spec: Arc<ChainSpec>,
db_args: DatabaseArguments,
) -> ProviderFactory<MockNodeTypesWithDB> {
let datadir_path = reth_db::test_utils::tempdir_path();

let db_path = datadir_path.join("db");
let static_files_path = datadir_path.join("static_files");
let rocksdb_path = datadir_path.join("rocksdb");

std::fs::create_dir_all(&static_files_path).expect("failed to create static_files dir");

let db = reth_db::init_db(&db_path, db_args).expect("failed to init db");
let db = Arc::new(TempDatabase::new(db, datadir_path));

ProviderFactory::new(
db,
chain_spec,
StaticFileProvider::read_write(static_files_path).expect("static file provider"),
RocksDBBuilder::new(&rocksdb_path)
.with_default_tables()
.build()
.expect("failed to create test RocksDB provider"),
reth_tasks::Runtime::test(),
)
.expect("failed to create test provider factory")
}

/// Inserts the genesis alloc from the provided chain spec into the trie.
pub fn insert_genesis<N: ProviderNodeTypes<ChainSpec = ChainSpec>>(
provider_factory: &ProviderFactory<N>,
Expand Down
Loading