From 04862a6a15aa04c4d0e36e900fd0fb8c49b84329 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:54:14 +0200 Subject: [PATCH 01/10] add test-utils to builder and rm from other crates --- crates/node/builder/Cargo.toml | 6 ++++- crates/node/builder/src/builder/mod.rs | 24 +++++++++---------- crates/rpc/rpc/Cargo.toml | 4 ++-- .../src/providers/database/provider.rs | 5 ++-- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/crates/node/builder/Cargo.toml b/crates/node/builder/Cargo.toml index f15ec8774611..06875036fe1c 100644 --- a/crates/node/builder/Cargo.toml +++ b/crates/node/builder/Cargo.toml @@ -21,7 +21,7 @@ reth-db-common.workspace = true reth-exex.workspace = true reth-evm.workspace = true reth-provider.workspace = true -reth-db = { workspace = true, features = ["mdbx"] } +reth-db = { workspace = true, features = ["mdbx"], optional = true } reth-db-api.workspace = true reth-rpc-engine-api.workspace = true reth-rpc.workspace = true @@ -78,3 +78,7 @@ tracing.workspace = true [dev-dependencies] tempfile.workspace = true + +[features] +default = [] +test-utils = ["reth-db/test-utils"] \ No newline at end of file diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index 23a18ee309fe..d46b73d76872 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -12,10 +12,6 @@ use crate::{ use futures::Future; use reth_chainspec::ChainSpec; use reth_cli_util::get_secret_key; -use reth_db::{ - test_utils::{create_test_rw_db_with_path, tempdir_path, TempDatabase}, - DatabaseEnv, -}; use reth_db_api::{ database::Database, database_metrics::{DatabaseMetadata, DatabaseMetrics}, @@ -26,9 +22,8 @@ use reth_network::{ }; use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeTypes}; use reth_node_core::{ - args::DatadirArgs, cli::config::{PayloadBuilderConfig, RethTransactionPoolConfig}, - dirs::{ChainPath, DataDirPath, MaybePlatformPath}, + dirs::{ChainPath, DataDirPath}, node_config::NodeConfig, primitives::Head, }; @@ -176,19 +171,24 @@ impl NodeBuilder { } /// Creates an _ephemeral_ preconfigured node for testing purposes. + #[cfg(feature = "test-utils")] pub fn testing_node( mut self, task_executor: TaskExecutor, - ) -> WithLaunchContext>>> { - let path = MaybePlatformPath::::from(tempdir_path()); - self.config = self - .config - .with_datadir_args(DatadirArgs { datadir: path.clone(), ..Default::default() }); + ) -> WithLaunchContext>>> + { + let path = reth_node_core::dirs::MaybePlatformPath::::from( + reth_db::test_utils::tempdir_path(), + ); + self.config = self.config.with_datadir_args(reth_node_core::args::DatadirArgs { + datadir: path.clone(), + ..Default::default() + }); let data_dir = path.unwrap_or_chain_default(self.config.chain.chain, self.config.datadir.clone()); - let db = create_test_rw_db_with_path(data_dir.db()); + let db = reth_db::test_utils::create_test_rw_db_with_path(data_dir.db()); WithLaunchContext { builder: self.with_database(db), task_executor } } diff --git a/crates/rpc/rpc/Cargo.toml b/crates/rpc/rpc/Cargo.toml index df6787199ce3..256fc156bad4 100644 --- a/crates/rpc/rpc/Cargo.toml +++ b/crates/rpc/rpc/Cargo.toml @@ -19,8 +19,8 @@ reth-rpc-api.workspace = true reth-rpc-eth-api.workspace = true reth-rpc-types.workspace = true reth-errors.workspace = true -reth-provider = { workspace = true, features = ["test-utils"] } -reth-transaction-pool = { workspace = true, features = ["test-utils"] } +reth-provider.workspace = true +reth-transaction-pool.workspace = true reth-network-api.workspace = true reth-rpc-engine-api.workspace = true reth-revm.workspace = true diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 83d9da3c648f..970c77b39997 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -172,8 +172,9 @@ impl DatabaseProvider { } impl DatabaseProvider { - #[cfg(any(test, feature = "test-utils"))] - /// Inserts an historical block. Used for setting up test environments + // TODO: uncomment below, once `reth debug_cmd` has been feature gated with dev. + // #[cfg(any(test, feature = "test-utils"))] + /// Inserts an historical block. **Used for setting up test environments** pub fn insert_historical_block( &self, block: SealedBlockWithSenders, From c1d1e63c3ab950f9c3121abdae96b36ada924cf5 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:01:37 +0200 Subject: [PATCH 02/10] add ci job --- .github/workflows/lint.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d0329aefc89f..5ac9ac6db415 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -179,3 +179,13 @@ jobs: uses: re-actors/alls-green@release/v1 with: jobs: ${{ toJSON(needs) }} + + no-test-deps: + name: no-test-deps + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: Ensure no arbitrary or proptest dependency on default build + run: cargo tree --package reth -e=features,no-dev | grep -Eq "arbitrary|proptest" && exit 1 || exit 0 \ No newline at end of file From 55d8307578d6d820bb0f3b512cc636352a7824ce Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:40:43 +0200 Subject: [PATCH 03/10] set more test-utils features --- crates/e2e-test-utils/Cargo.toml | 4 ++-- crates/ethereum/node/Cargo.toml | 4 ++++ crates/optimism/node/Cargo.toml | 5 ++++- examples/custom-dev-node/Cargo.toml | 2 +- examples/custom-engine-types/Cargo.toml | 2 +- examples/custom-evm/Cargo.toml | 2 +- examples/stateful-precompile/Cargo.toml | 2 +- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/e2e-test-utils/Cargo.toml b/crates/e2e-test-utils/Cargo.toml index a610d5569684..f472da06bc12 100644 --- a/crates/e2e-test-utils/Cargo.toml +++ b/crates/e2e-test-utils/Cargo.toml @@ -13,12 +13,12 @@ reth.workspace = true reth-chainspec.workspace = true reth-primitives.workspace = true reth-tracing.workspace = true -reth-db.workspace = true +reth-db = { workspace = true, features = ["test-utils"] } reth-rpc.workspace = true reth-rpc-layer.workspace = true reth-payload-builder = { workspace = true, features = ["test-utils"] } reth-provider.workspace = true -reth-node-builder.workspace = true +reth-node-builder = { workspace = true, features = ["test-utils"] } reth-tokio-util.workspace = true reth-stages-types.workspace = true reth-network-peers.workspace = true diff --git a/crates/ethereum/node/Cargo.toml b/crates/ethereum/node/Cargo.toml index 54e54a0ebb76..aa1e793b7348 100644 --- a/crates/ethereum/node/Cargo.toml +++ b/crates/ethereum/node/Cargo.toml @@ -43,3 +43,7 @@ futures.workspace = true tokio.workspace = true futures-util.workspace = true serde_json.workspace = true + +[features] +default = [] +test-utils = ["reth-node-builder/test-utils"] \ No newline at end of file diff --git a/crates/optimism/node/Cargo.toml b/crates/optimism/node/Cargo.toml index 5d172ec93b73..9544dcb69664 100644 --- a/crates/optimism/node/Cargo.toml +++ b/crates/optimism/node/Cargo.toml @@ -58,8 +58,10 @@ serde_json.workspace = true [dev-dependencies] reth.workspace = true reth-db.workspace = true -reth-revm = { workspace = true, features = ["test-utils"] } reth-e2e-test-utils.workspace = true +reth-node-builder = { workspace = true, features = ["test-utils"] } +reth-provider = { workspace = true, features = ["test-utils"] } +reth-revm = { workspace = true, features = ["test-utils"] } tokio.workspace = true alloy-primitives.workspace = true alloy-genesis.workspace = true @@ -78,3 +80,4 @@ optimism = [ "reth-auto-seal-consensus/optimism", "reth-rpc-eth-types/optimism" ] +test-utils = ["reth-node-builder/test-utils"] \ No newline at end of file diff --git a/examples/custom-dev-node/Cargo.toml b/examples/custom-dev-node/Cargo.toml index cc21c97d2a80..d40c97ca658d 100644 --- a/examples/custom-dev-node/Cargo.toml +++ b/examples/custom-dev-node/Cargo.toml @@ -11,7 +11,7 @@ reth.workspace = true reth-chainspec.workspace = true reth-node-core.workspace = true reth-primitives.workspace = true -reth-node-ethereum.workspace = true +reth-node-ethereum = { workspace = true, features = ["test-utils"] } futures-util.workspace = true eyre.workspace = true diff --git a/examples/custom-engine-types/Cargo.toml b/examples/custom-engine-types/Cargo.toml index 3b6a796ba0ad..c00863147f9b 100644 --- a/examples/custom-engine-types/Cargo.toml +++ b/examples/custom-engine-types/Cargo.toml @@ -15,7 +15,7 @@ reth-primitives.workspace = true reth-payload-builder.workspace = true reth-basic-payload-builder.workspace = true reth-ethereum-payload-builder.workspace = true -reth-node-ethereum.workspace = true +reth-node-ethereum = { workspace = true, features = ["test-utils"] } reth-tracing.workspace = true alloy-genesis.workspace = true diff --git a/examples/custom-evm/Cargo.toml b/examples/custom-evm/Cargo.toml index a85b6ce8aadb..7642dc80cf2f 100644 --- a/examples/custom-evm/Cargo.toml +++ b/examples/custom-evm/Cargo.toml @@ -12,7 +12,7 @@ reth-evm-ethereum.workspace = true reth-node-api.workspace = true reth-node-core.workspace = true reth-primitives.workspace = true -reth-node-ethereum.workspace = true +reth-node-ethereum = { workspace = true, features = ["test-utils"] } reth-tracing.workspace = true alloy-genesis.workspace = true diff --git a/examples/stateful-precompile/Cargo.toml b/examples/stateful-precompile/Cargo.toml index c983ef80d95e..2ae4656eee86 100644 --- a/examples/stateful-precompile/Cargo.toml +++ b/examples/stateful-precompile/Cargo.toml @@ -11,7 +11,7 @@ reth-chainspec.workspace = true reth-node-api.workspace = true reth-node-core.workspace = true reth-primitives.workspace = true -reth-node-ethereum.workspace = true +reth-node-ethereum = { workspace = true, features = ["test-utils"] } reth-tracing.workspace = true alloy-genesis.workspace = true From d3173a7e2268a1514a3af77c6917850e7550514c Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:52:01 +0200 Subject: [PATCH 04/10] add missing test-utils --- crates/exex/test-utils/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/exex/test-utils/Cargo.toml b/crates/exex/test-utils/Cargo.toml index b7db9a98f02c..a623236a0665 100644 --- a/crates/exex/test-utils/Cargo.toml +++ b/crates/exex/test-utils/Cargo.toml @@ -24,7 +24,7 @@ reth-exex.workspace = true reth-network.workspace = true reth-node-api.workspace = true reth-node-core.workspace = true -reth-node-builder.workspace = true +reth-node-builder = { workspace = true, features = ["test-utils"] } reth-node-ethereum.workspace = true reth-payload-builder.workspace = true reth-primitives.workspace = true From f9a2148f03a36b0bfbccaad803caacf16a15a2ac Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 5 Jul 2024 19:27:25 +0200 Subject: [PATCH 05/10] newline eof --- crates/ethereum/node/Cargo.toml | 2 +- crates/node/builder/Cargo.toml | 2 +- crates/optimism/node/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ethereum/node/Cargo.toml b/crates/ethereum/node/Cargo.toml index aa1e793b7348..f053b35b911c 100644 --- a/crates/ethereum/node/Cargo.toml +++ b/crates/ethereum/node/Cargo.toml @@ -46,4 +46,4 @@ serde_json.workspace = true [features] default = [] -test-utils = ["reth-node-builder/test-utils"] \ No newline at end of file +test-utils = ["reth-node-builder/test-utils"] diff --git a/crates/node/builder/Cargo.toml b/crates/node/builder/Cargo.toml index 06875036fe1c..5a29b6e778a4 100644 --- a/crates/node/builder/Cargo.toml +++ b/crates/node/builder/Cargo.toml @@ -81,4 +81,4 @@ tempfile.workspace = true [features] default = [] -test-utils = ["reth-db/test-utils"] \ No newline at end of file +test-utils = ["reth-db/test-utils"] diff --git a/crates/optimism/node/Cargo.toml b/crates/optimism/node/Cargo.toml index 9544dcb69664..1a32bcad6ec4 100644 --- a/crates/optimism/node/Cargo.toml +++ b/crates/optimism/node/Cargo.toml @@ -80,4 +80,4 @@ optimism = [ "reth-auto-seal-consensus/optimism", "reth-rpc-eth-types/optimism" ] -test-utils = ["reth-node-builder/test-utils"] \ No newline at end of file +test-utils = ["reth-node-builder/test-utils"] From 7a4f38692c7ca48671aad936fabcc5d6aa256f3b Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 5 Jul 2024 19:28:48 +0200 Subject: [PATCH 06/10] fix lint.yml --- .github/workflows/lint.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5ac9ac6db415..3aefc21c8389 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -160,6 +160,15 @@ jobs: with: cmd: jq empty etc/grafana/dashboards/overview.json + no-test-deps: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: Ensure no arbitrary or proptest dependency on default build + run: cargo tree --package reth -e=features,no-dev | grep -Eq "arbitrary|proptest" && exit 1 || exit 0 + lint-success: name: lint success runs-on: ubuntu-latest @@ -173,19 +182,10 @@ jobs: - book - codespell - grafana + - no-test-deps timeout-minutes: 30 steps: - name: Decide whether the needed jobs succeeded or failed uses: re-actors/alls-green@release/v1 with: jobs: ${{ toJSON(needs) }} - - no-test-deps: - name: no-test-deps - runs-on: ubuntu-latest - timeout-minutes: 30 - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - name: Ensure no arbitrary or proptest dependency on default build - run: cargo tree --package reth -e=features,no-dev | grep -Eq "arbitrary|proptest" && exit 1 || exit 0 \ No newline at end of file From d32b0f94182b67ca6abf4b0d9f0d28dc2ac48ef3 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 5 Jul 2024 19:32:56 +0200 Subject: [PATCH 07/10] another test-utils --- crates/exex/test-utils/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/exex/test-utils/Cargo.toml b/crates/exex/test-utils/Cargo.toml index a623236a0665..b5b62471b6f7 100644 --- a/crates/exex/test-utils/Cargo.toml +++ b/crates/exex/test-utils/Cargo.toml @@ -28,7 +28,7 @@ reth-node-builder = { workspace = true, features = ["test-utils"] } reth-node-ethereum.workspace = true reth-payload-builder.workspace = true reth-primitives.workspace = true -reth-provider.workspace = true +reth-provider = { workspace = true, features = ["test-utils"] } reth-tasks.workspace = true reth-transaction-pool = { workspace = true, features = ["test-utils"] } From ee4f2d172ee6922943c58a4ef6e5338d8b677a89 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 5 Jul 2024 19:51:48 +0200 Subject: [PATCH 08/10] more test-utils --- Cargo.lock | 1 + examples/custom-rlpx-subprotocol/Cargo.toml | 2 +- examples/rpc-db/Cargo.toml | 1 + examples/rpc-db/src/main.rs | 3 ++- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f4b8d4ee9e0..8e872701fad4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3056,6 +3056,7 @@ dependencies = [ "reth-db", "reth-db-api", "reth-node-ethereum", + "reth-provider", "tokio", ] diff --git a/examples/custom-rlpx-subprotocol/Cargo.toml b/examples/custom-rlpx-subprotocol/Cargo.toml index ae3a7c088c04..d2d1caab6355 100644 --- a/examples/custom-rlpx-subprotocol/Cargo.toml +++ b/examples/custom-rlpx-subprotocol/Cargo.toml @@ -13,7 +13,7 @@ reth-eth-wire.workspace = true reth-network.workspace = true reth-network-api.workspace = true reth-node-ethereum.workspace = true -reth-provider.workspace = true +reth-provider = { workspace = true, features = ["test-utils"] } reth-primitives.workspace = true reth-rpc-types.workspace = true reth.workspace = true diff --git a/examples/rpc-db/Cargo.toml b/examples/rpc-db/Cargo.toml index 8bcab0e2be52..007a488b8174 100644 --- a/examples/rpc-db/Cargo.toml +++ b/examples/rpc-db/Cargo.toml @@ -13,5 +13,6 @@ reth-chainspec.workspace = true reth-db.workspace = true reth-db-api.workspace = true reth-node-ethereum.workspace = true +reth-provider = { workspace = true, features = ["test-utils"] } tokio = { workspace = true, features = ["full"] } eyre.workspace = true diff --git a/examples/rpc-db/src/main.rs b/examples/rpc-db/src/main.rs index 6d18640f7f96..26a0f7a20db1 100644 --- a/examples/rpc-db/src/main.rs +++ b/examples/rpc-db/src/main.rs @@ -32,9 +32,10 @@ use reth::rpc::builder::{ // Configuring the network parts, ideally also wouldn't need to think about this. use myrpc_ext::{MyRpcExt, MyRpcExtApiServer}; use reth::{ - blockchain_tree::noop::NoopBlockchainTree, providers::test_utils::TestCanonStateSubscriptions, + blockchain_tree::noop::NoopBlockchainTree, tasks::TokioTaskExecutor, }; +use reth_provider::providers::test_utils::TestCanonStateSubscriptions; use reth_node_ethereum::EthEvmConfig; // Custom rpc extension From 6f22892501ec129f780f967f4fdbba7c9fd457d1 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 5 Jul 2024 19:57:57 +0200 Subject: [PATCH 09/10] fmt --- examples/rpc-db/src/main.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/rpc-db/src/main.rs b/examples/rpc-db/src/main.rs index 26a0f7a20db1..6e037387ce84 100644 --- a/examples/rpc-db/src/main.rs +++ b/examples/rpc-db/src/main.rs @@ -31,12 +31,9 @@ use reth::rpc::builder::{ }; // Configuring the network parts, ideally also wouldn't need to think about this. use myrpc_ext::{MyRpcExt, MyRpcExtApiServer}; -use reth::{ - blockchain_tree::noop::NoopBlockchainTree, - tasks::TokioTaskExecutor, -}; -use reth_provider::providers::test_utils::TestCanonStateSubscriptions; +use reth::{blockchain_tree::noop::NoopBlockchainTree, tasks::TokioTaskExecutor}; use reth_node_ethereum::EthEvmConfig; +use reth_provider::providers::test_utils::TestCanonStateSubscriptions; // Custom rpc extension pub mod myrpc_ext; From ee7a349616ff157f7111e2238daa0f102b73834a Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 5 Jul 2024 20:08:00 +0200 Subject: [PATCH 10/10] fix --- examples/rpc-db/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rpc-db/src/main.rs b/examples/rpc-db/src/main.rs index 6e037387ce84..85ad28d6a051 100644 --- a/examples/rpc-db/src/main.rs +++ b/examples/rpc-db/src/main.rs @@ -33,7 +33,7 @@ use reth::rpc::builder::{ use myrpc_ext::{MyRpcExt, MyRpcExtApiServer}; use reth::{blockchain_tree::noop::NoopBlockchainTree, tasks::TokioTaskExecutor}; use reth_node_ethereum::EthEvmConfig; -use reth_provider::providers::test_utils::TestCanonStateSubscriptions; +use reth_provider::test_utils::TestCanonStateSubscriptions; // Custom rpc extension pub mod myrpc_ext;