Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianBland committed Jun 10, 2024
1 parent fa4c614 commit ce4fff7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,8 @@ mod tests {

fn setup_externals(
exec_res: Vec<BundleStateWithReceipts>,
) -> TreeExternals<Arc<TempDatabase<DatabaseEnv>>, TestConsensus, MockExecutorProvider> {
) -> TreeExternals<Arc<TempDatabase<DatabaseEnv>>, Arc<TestConsensus>, MockExecutorProvider>
{
let chain_spec = Arc::new(
ChainSpecBuilder::default()
.chain(MAINNET.chain)
Expand All @@ -1409,7 +1410,7 @@ mod tests {
.build(),
);
let provider_factory = create_test_provider_factory_with_chain_spec(chain_spec);
let consensus = TestConsensus::default();
let consensus = Arc::new(TestConsensus::default());
let executor_factory = MockExecutorProvider::default();
executor_factory.extend(exec_res);

Expand Down
1 change: 1 addition & 0 deletions crates/exex/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ workspace = true
## reth
reth-blockchain-tree.workspace = true
reth-config.workspace = true
reth-consensus.workspace = true
reth-db = { workspace = true, features = ["test-utils"] }
reth-db-common.workspace = true
reth-evm = { workspace = true, features = ["test-utils"] }
Expand Down
32 changes: 30 additions & 2 deletions crates/exex/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use futures_util::FutureExt;
use reth_blockchain_tree::noop::NoopBlockchainTree;
use reth_consensus::test_utils::TestConsensus;
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
use reth_db_common::init::init_genesis;
use reth_evm::test_utils::MockExecutorProvider;
Expand All @@ -18,7 +19,8 @@ use reth_network::{config::SecretKey, NetworkConfigBuilder, NetworkManager};
use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeTypes};
use reth_node_builder::{
components::{
Components, ComponentsBuilder, ExecutorBuilder, NodeComponentsBuilder, PoolBuilder,
Components, ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NodeComponentsBuilder,
PoolBuilder,
},
BuilderContext, Node, NodeAdapter, RethFullAdapter,
};
Expand Down Expand Up @@ -83,6 +85,22 @@ where
}
}

/// A test [`ConsensusBuilder`] that builds a [`TestConsensus`].
#[derive(Debug, Default, Clone, Copy)]
#[non_exhaustive]
pub struct TestConsensusBuilder;

impl<Node> ConsensusBuilder<Node> for TestConsensusBuilder
where
Node: FullNodeTypes,
{
type Consensus = Arc<TestConsensus>;

async fn build_consensus(self, _ctx: &BuilderContext<Node>) -> eyre::Result<Self::Consensus> {
Ok(Arc::new(TestConsensus::default()))
}
}

/// A test [`Node`].
#[derive(Debug, Default, Clone, Copy)]
#[non_exhaustive]
Expand All @@ -103,6 +121,7 @@ where
EthereumPayloadBuilder,
EthereumNetworkBuilder,
TestExecutorBuilder,
TestConsensusBuilder,
>;

fn components_builder(self) -> Self::ComponentsBuilder {
Expand All @@ -112,6 +131,7 @@ where
.payload(EthereumPayloadBuilder::default())
.network(EthereumNetworkBuilder::default())
.executor(TestExecutorBuilder::default())
.consensus(TestConsensusBuilder::default())
}
}

Expand Down Expand Up @@ -198,6 +218,7 @@ pub async fn test_exex_context_with_chain_spec(
let transaction_pool = testing_pool();
let evm_config = EthEvmConfig::default();
let executor = MockExecutorProvider::default();
let consensus = Arc::new(TestConsensus::default());

let provider_factory = create_test_provider_factory_with_chain_spec(chain_spec);
let genesis_hash = init_genesis(provider_factory.clone())?;
Expand All @@ -217,7 +238,14 @@ pub async fn test_exex_context_with_chain_spec(
let task_executor = tasks.executor();

let components = NodeAdapter::<FullNodeTypesAdapter<TestNode, _, _>, _> {
components: Components { transaction_pool, evm_config, executor, network, payload_builder },
components: Components {
transaction_pool,
evm_config,
executor,
consensus,
network,
payload_builder,
},
task_executor,
provider,
};
Expand Down

0 comments on commit ce4fff7

Please sign in to comment.