Skip to content

Commit

Permalink
chore: remove network-api test-utils feature (paradigmxyz#3622)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 6, 2023
1 parent c4f0242 commit 73bfb2c
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 26 deletions.
1 change: 0 additions & 1 deletion crates/net/network-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ tokio = { workspace = true, features = ["sync"] }
[features]
default = ["serde"]
serde = ["dep:serde"]
test-utils = []
5 changes: 2 additions & 3 deletions crates/net/network-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ pub mod error;
/// Reputation score
pub mod reputation;

#[cfg(feature = "test-utils")]
/// Implementation of network traits for testing purposes.
pub mod test_utils;
/// Implementation of network traits for that does nothing.
pub mod noop;

/// Provides general purpose information about the network.
#[async_trait]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! A network implementation that does nothing.
//!
//! This is useful for wiring components together that don't require network but still need to be
//! generic over it.
use crate::{
NetworkError, NetworkInfo, PeerKind, Peers, PeersInfo, Reputation, ReputationChangeKind,
};
Expand All @@ -11,6 +16,7 @@ use std::net::{IpAddr, SocketAddr};
///
/// Intended for testing purposes where network is not used.
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct NoopNetwork;

#[async_trait]
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ reth-tracing = { path = "../../tracing" }
reth-rpc-api = { path = "../rpc-api", features = ["client"] }
reth-transaction-pool = { workspace = true, features = ["test-utils"] }
reth-provider = { workspace = true, features = ["test-utils"] }
reth-network-api = { workspace = true, features = ["test-utils"] }
reth-network-api = { workspace = true }
reth-interfaces = { workspace = true, features = ["test-utils"] }
reth-beacon-consensus = { path = "../../consensus/beacon" }
reth-payload-builder = { workspace = true, features = ["test-utils"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-builder/tests/it/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use reth_beacon_consensus::BeaconConsensusEngineHandle;
use reth_network_api::test_utils::NoopNetwork;
use reth_network_api::noop::NoopNetwork;
use reth_payload_builder::test_utils::spawn_test_payload_service;
use reth_primitives::MAINNET;
use reth_provider::test_utils::{NoopProvider, TestCanonStateSubscriptions};
Expand Down Expand Up @@ -101,7 +101,7 @@ pub fn test_rpc_builder() -> RpcModuleBuilder<
RpcModuleBuilder::default()
.with_provider(NoopProvider::default())
.with_pool(testing_pool())
.with_network(NoopNetwork)
.with_network(NoopNetwork::default())
.with_executor(TokioTaskExecutor::default())
.with_events(TestCanonStateSubscriptions::default())
}
2 changes: 1 addition & 1 deletion crates/rpc/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ reth-rlp = { workspace = true }
reth-rpc-types = { workspace = true }
reth-provider = { workspace = true, features = ["test-utils"] }
reth-transaction-pool = { workspace = true, features = ["test-utils"] }
reth-network-api = { workspace = true, features = ["test-utils"] }
reth-network-api = { workspace = true }
reth-rpc-engine-api = { path = "../rpc-engine-api" }
reth-revm = { path = "../../revm" }
reth-tasks = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc/src/eth/api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ mod tests {
};
use jsonrpsee::types::error::INVALID_PARAMS_CODE;
use reth_interfaces::test_utils::{generators, generators::Rng};
use reth_network_api::test_utils::NoopNetwork;
use reth_network_api::noop::NoopNetwork;
use reth_primitives::{
basefee::calculate_next_block_base_fee, Block, BlockNumberOrTag, Header, TransactionSigned,
H256, U256,
Expand Down Expand Up @@ -424,7 +424,7 @@ mod tests {
EthApi::new(
provider.clone(),
testing_pool(),
NoopNetwork,
NoopNetwork::default(),
cache.clone(),
GasPriceOracle::new(provider, Default::default(), cache),
)
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc/src/eth/api/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,15 +892,15 @@ mod tests {
eth::{cache::EthStateCache, gas_oracle::GasPriceOracle},
EthApi,
};
use reth_network_api::test_utils::NoopNetwork;
use reth_network_api::noop::NoopNetwork;
use reth_primitives::{hex_literal::hex, Bytes};
use reth_provider::test_utils::NoopProvider;
use reth_transaction_pool::{test_utils::testing_pool, TransactionPool};

#[tokio::test]
async fn send_raw_transaction() {
let noop_provider = NoopProvider::default();
let noop_network_provider = NoopNetwork;
let noop_network_provider = NoopNetwork::default();

let pool = testing_pool();

Expand Down
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ reth-rpc-types = { workspace = true }
reth-revm = { workspace = true }
reth-blockchain-tree = { workspace = true }
reth-beacon-consensus = { workspace = true }
reth-network-api = { workspace = true, features = ["test-utils"] }
reth-transaction-pool = { workspace = true, features = ["test-utils"] }
reth-network-api = { workspace = true }
reth-transaction-pool = { workspace = true }
reth-tasks = { workspace = true }


Expand Down
4 changes: 2 additions & 2 deletions examples/db-access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() -> eyre::Result<()> {
// Opens a RO handle to the database file.
// TODO: Should be able to do `ProviderFactory::new_with_db_path_ro(...)` instead of
// doing in 2 steps.
let db = open_db_read_only(&Path::new(&std::env::var("RETH_DB_PATH")?), None)?;
let db = open_db_read_only(Path::new(&std::env::var("RETH_DB_PATH")?), None)?;

// Instantiate a provider factory for Ethereum mainnet using the provided DB.
// TODO: Should the DB version include the spec so that you do not need to specify it here?
Expand Down Expand Up @@ -197,7 +197,7 @@ fn receipts_provider_example<T: ReceiptProvider + TransactionsProvider + HeaderP
{
let receipts = provider.receipt(header_num)?.ok_or(eyre::eyre!("receipt not found"))?;
for log in &receipts.logs {
if filter_params.filter_address(log) && filter_params.filter_topics(&log) {
if filter_params.filter_address(log) && filter_params.filter_topics(log) {
// Do something with the log e.g. decode it.
println!("Matching log found! {log:?}")
}
Expand Down
17 changes: 7 additions & 10 deletions examples/rpc-db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ use reth_blockchain_tree::{
};
use reth_revm::Factory as ExecutionFactory;
// Configuring the network parts, ideally also wouldn't ned to think about this.
use reth_network_api::test_utils::NoopNetwork;
use reth_network_api::noop::NoopNetwork;
use reth_provider::test_utils::TestCanonStateSubscriptions;
use reth_tasks::TokioTaskExecutor;
use reth_transaction_pool::test_utils::testing_pool;

use reth_transaction_pool::noop::NoopTransactionPool;
use std::{path::Path, sync::Arc};

// Example illustrating how to run the ETH JSON RPC API as standalone over a DB file.
Expand All @@ -30,7 +29,7 @@ use std::{path::Path, sync::Arc};
#[tokio::main]
async fn main() -> eyre::Result<()> {
// 1. Setup the DB
let db = Arc::new(open_db_read_only(&Path::new(&std::env::var("RETH_DB_PATH")?), None)?);
let db = Arc::new(open_db_read_only(Path::new(&std::env::var("RETH_DB_PATH")?), None)?);
let spec = Arc::new(ChainSpecBuilder::mainnet().build());
let factory = ProviderFactory::new(db.clone(), spec.clone());

Expand All @@ -47,20 +46,18 @@ async fn main() -> eyre::Result<()> {

let tree = ShareableBlockchainTree::new(BlockchainTree::new(
externals,
canon_state_notification_sender.clone(),
canon_state_notification_sender,
tree_config,
)?);

BlockchainProvider::new(factory, tree)?
};

let noop_pool = testing_pool();
let rpc_builder = RpcModuleBuilder::default()
.with_provider(provider)
// Rest is just defaults
// TODO: How do we make this easier to configure?
.with_pool(noop_pool)
.with_network(NoopNetwork)
// Rest is just noops that do nothing
.with_pool(NoopTransactionPool::default())
.with_network(NoopNetwork::default())
.with_executor(TokioTaskExecutor::default())
.with_events(TestCanonStateSubscriptions::default());

Expand Down

0 comments on commit 73bfb2c

Please sign in to comment.