Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Dec 25, 2024
1 parent 36ec3ef commit 0f079bf
Show file tree
Hide file tree
Showing 22 changed files with 194 additions and 230 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.

10 changes: 6 additions & 4 deletions crates/e2e-test-utils/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use jsonrpsee::{
http_client::{transport::HttpBackend, HttpClient},
};
use reth_chainspec::EthereumHardforks;
use reth_node_api::EngineTypes;
use reth_node_api::{EngineTypes, NodePrimitives};
use reth_node_builder::BuiltPayload;
use reth_payload_builder::PayloadId;
use reth_payload_primitives::PayloadBuilderAttributes;
Expand All @@ -17,14 +17,16 @@ use std::{marker::PhantomData, sync::Arc};

/// Helper for engine api operations
#[derive(Debug)]
pub struct EngineApiTestContext<E, ChainSpec> {
pub struct EngineApiTestContext<E, ChainSpec, N: NodePrimitives> {
pub chain_spec: Arc<ChainSpec>,
pub canonical_stream: CanonStateNotificationStream,
pub canonical_stream: CanonStateNotificationStream<N>,
pub engine_api_client: HttpClient<AuthClientService<HttpBackend>>,
pub _marker: PhantomData<E>,
}

impl<E: EngineTypes, ChainSpec: EthereumHardforks> EngineApiTestContext<E, ChainSpec> {
impl<E: EngineTypes, ChainSpec: EthereumHardforks, N: NodePrimitives>
EngineApiTestContext<E, ChainSpec, N>
{
/// Retrieves a v3 payload from the engine api
pub async fn get_payload_v3(
&self,
Expand Down
9 changes: 2 additions & 7 deletions crates/e2e-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use reth_chainspec::EthChainSpec;
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
use reth_engine_local::LocalPayloadAttributesBuilder;
use reth_network_api::test_utils::PeersHandleProvider;
use reth_node_api::EngineValidator;
use reth_node_builder::{
components::NodeComponentsBuilder,
rpc::{EngineValidatorAddOn, RethRpcAddOns},
Expand All @@ -14,7 +13,6 @@ use reth_node_builder::{
PayloadTypes,
};
use reth_node_core::args::{DiscoveryArgs, NetworkArgs, RpcServerArgs};
use reth_primitives::EthPrimitives;
use reth_provider::providers::{
BlockchainProvider, BlockchainProvider2, NodeTypesForProvider, NodeTypesForTree,
};
Expand Down Expand Up @@ -122,7 +120,7 @@ pub async fn setup_engine<N>(
where
N: Default
+ Node<TmpNodeAdapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>>
+ NodeTypesWithEngine<Primitives = EthPrimitives>
+ NodeTypesWithEngine
+ NodeTypesForProvider,
N::ComponentsBuilder: NodeComponentsBuilder<
TmpNodeAdapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>,
Expand All @@ -132,10 +130,7 @@ where
>,
>,
N::AddOns: RethRpcAddOns<Adapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>>
+ EngineValidatorAddOn<
Adapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>,
Validator: EngineValidator<N::Engine, Block = reth_primitives::Block>,
>,
+ EngineValidatorAddOn<Adapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>>,
LocalPayloadAttributesBuilder<N::ChainSpec>: PayloadAttributesBuilder<
<<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadAttributes,
>,
Expand Down
19 changes: 8 additions & 11 deletions crates/e2e-test-utils/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use crate::{
};
use alloy_consensus::BlockHeader;
use alloy_eips::BlockId;
use alloy_primitives::{BlockHash, BlockNumber, Bytes, B256};
use alloy_primitives::{BlockHash, BlockNumber, Bytes, Sealable, B256};
use alloy_rpc_types_engine::PayloadStatusEnum;
use alloy_rpc_types_eth::BlockNumberOrTag;
use eyre::Ok;
use futures_util::Future;
use reth_chainspec::EthereumHardforks;
use reth_network_api::test_utils::PeersHandleProvider;
use reth_node_api::{Block, EngineTypes, FullNodeComponents};
use reth_node_api::{Block, BlockTy, EngineTypes, FullNodeComponents};
use reth_node_builder::{rpc::RethRpcAddOns, FullNode, NodeTypes, NodeTypesWithEngine};
use reth_node_core::primitives::SignedTransaction;
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
use reth_primitives::EthPrimitives;
use reth_provider::{
BlockReader, BlockReaderIdExt, CanonStateSubscriptions, StageCheckpointReader,
};
Expand All @@ -25,7 +25,7 @@ use tokio_stream::StreamExt;
use url::Url;

/// An helper struct to handle node actions
#[allow(missing_debug_implementations)]
#[expect(missing_debug_implementations, clippy::complexity)]
pub struct NodeTestContext<Node, AddOns>
where
Node: FullNodeComponents,
Expand All @@ -41,6 +41,7 @@ where
pub engine_api: EngineApiTestContext<
<Node::Types as NodeTypesWithEngine>::Engine,
<Node::Types as NodeTypes>::ChainSpec,
<Node::Types as NodeTypes>::Primitives,
>,
/// Context for testing RPC features.
pub rpc: RpcTestContext<Node, AddOns::EthApi>,
Expand All @@ -50,11 +51,7 @@ impl<Node, Engine, AddOns> NodeTestContext<Node, AddOns>
where
Engine: EngineTypes,
Node: FullNodeComponents,
Node::Types: NodeTypesWithEngine<
ChainSpec: EthereumHardforks,
Engine = Engine,
Primitives = EthPrimitives,
>,
Node::Types: NodeTypesWithEngine<ChainSpec: EthereumHardforks, Engine = Engine>,
Node::Network: PeersHandleProvider,
AddOns: RethRpcAddOns<Node>,
{
Expand Down Expand Up @@ -97,7 +94,7 @@ where
where
Engine::ExecutionPayloadEnvelopeV3: From<Engine::BuiltPayload> + PayloadEnvelopeExt,
Engine::ExecutionPayloadEnvelopeV4: From<Engine::BuiltPayload> + PayloadEnvelopeExt,
AddOns::EthApi: EthApiSpec<Provider: BlockReader<Block = reth_primitives::Block>>
AddOns::EthApi: EthApiSpec<Provider: BlockReader<Block = BlockTy<Node::Types>>>
+ EthTransactions
+ TraceExt,
{
Expand Down Expand Up @@ -236,7 +233,7 @@ where
// pool is actually present in the canonical block
let head = self.engine_api.canonical_stream.next().await.unwrap();
let tx = head.tip().transactions().first();
assert_eq!(tx.unwrap().hash().as_slice(), tip_tx_hash.as_slice());
assert_eq!(tx.unwrap().tx_hash().as_slice(), tip_tx_hash.as_slice());

loop {
// wait for the block to commit
Expand Down
14 changes: 3 additions & 11 deletions crates/e2e-test-utils/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloy_consensus::TxEnvelope;
use alloy_network::eip2718::Decodable2718;
use alloy_primitives::{Bytes, B256};
use reth_chainspec::EthereumHardforks;
use reth_node_api::{FullNodeComponents, NodePrimitives};
use reth_node_api::{BlockTy, FullNodeComponents};
use reth_node_builder::{rpc::RpcRegistry, NodeTypes};
use reth_provider::BlockReader;
use reth_rpc_api::DebugApiServer;
Expand All @@ -18,16 +18,8 @@ pub struct RpcTestContext<Node: FullNodeComponents, EthApi: EthApiTypes> {

impl<Node, EthApi> RpcTestContext<Node, EthApi>
where
Node: FullNodeComponents<
Types: NodeTypes<
ChainSpec: EthereumHardforks,
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
>,
>,
EthApi: EthApiSpec<Provider: BlockReader<Block = reth_primitives::Block>>
Node: FullNodeComponents<Types: NodeTypes<ChainSpec: EthereumHardforks>>,
EthApi: EthApiSpec<Provider: BlockReader<Block = BlockTy<Node::Types>>>
+ EthTransactions
+ TraceExt,
{
Expand Down
7 changes: 7 additions & 0 deletions crates/node/builder/src/launch/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ where
let consensus_engine_stream = UnboundedReceiverStream::from(consensus_engine_rx)
.maybe_skip_fcu(node_config.debug.skip_fcu)
.maybe_skip_new_payload(node_config.debug.skip_new_payload)
// .maybe_reorg(
// ctx.blockchain_db().clone(),
// ctx.components().evm_config().clone(),
// reth_payload_validator::ExecutionPayloadValidator::new(ctx.chain_spec()),
// node_config.debug.reorg_frequency,
// node_config.debug.reorg_depth,
// )
// Store messages _after_ skipping so that `replay-engine` command
// would replay only the messages that were observed by the engine
// during this run.
Expand Down
51 changes: 20 additions & 31 deletions crates/optimism/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,26 @@ fn main() {

if let Err(err) =
Cli::<OpChainSpecParser, RollupArgs>::parse().run(|builder, rollup_args| async move {
if rollup_args.experimental {
tracing::warn!(target: "reth::cli", "Experimental engine is default now, and the --engine.experimental flag is deprecated. To enable the legacy functionality, use --engine.legacy.");
}
let use_legacy_engine = rollup_args.legacy;
match use_legacy_engine {
false => {
let engine_tree_config = TreeConfig::default()
.with_persistence_threshold(rollup_args.persistence_threshold)
.with_memory_block_buffer_target(rollup_args.memory_block_buffer_target);

let op_node = OpNode::new(rollup_args.clone());
let handle = builder
.with_types_and_provider::<OpNode, BlockchainProvider2<_>>()
.with_components(op_node.components())
.with_add_ons(op_node.add_ons())
.launch_with_fn(|builder| {
let launcher = EngineNodeLauncher::new(
builder.task_executor().clone(),
builder.config().datadir(),
engine_tree_config,
);
builder.launch_with(launcher)
})
.await?;

handle.node_exit_future.await
}
true => {
Ok(())
}
}
let engine_tree_config = TreeConfig::default()
.with_persistence_threshold(rollup_args.persistence_threshold)
.with_memory_block_buffer_target(rollup_args.memory_block_buffer_target);

let op_node = OpNode::new(rollup_args.clone());
let handle = builder
.with_types_and_provider::<OpNode, BlockchainProvider2<_>>()
.with_components(op_node.components())
.with_add_ons(op_node.add_ons())
.launch_with_fn(|builder| {
let launcher = EngineNodeLauncher::new(
builder.task_executor().clone(),
builder.config().datadir(),
engine_tree_config,
);
builder.launch_with(launcher)
})
.await?;

handle.node_exit_future.await
})
{
eprintln!("Error: {err:?}");
Expand Down
10 changes: 6 additions & 4 deletions crates/optimism/cli/src/commands/import_receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ pub struct ImportReceiptsResult {
mod test {
use alloy_primitives::hex;
use reth_db_common::init::init_genesis;
use reth_optimism_chainspec::OP_MAINNET;
use reth_optimism_node::OpNode;
use reth_provider::test_utils::create_test_provider_factory_with_node_types;
use reth_stages::test_utils::TestStageDB;
use tempfile::tempfile;
use tokio::{
Expand Down Expand Up @@ -299,11 +302,10 @@ mod test {
init_genesis(&db.factory).unwrap();

// todo: where does import command init receipts ? probably somewhere in pipeline

let provider_factory =
create_test_provider_factory_with_node_types::<OpNode>(OP_MAINNET.clone());
let ImportReceiptsResult { total_decoded_receipts, total_filtered_out_dup_txns } =
import_receipts_from_reader(&TestStageDB::default().factory, reader, |_, _| 0)
.await
.unwrap();
import_receipts_from_reader(&provider_factory, reader, |_, _| 0).await.unwrap();

assert_eq!(total_decoded_receipts, 3);
assert_eq!(total_filtered_out_dup_txns, 0);
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ tracing.workspace = true

[dev-dependencies]
alloy-primitives.workspace = true
op-alloy-consensus.workspace = true
reth-optimism-chainspec.workspace = true

[features]
Expand Down
Loading

0 comments on commit 0f079bf

Please sign in to comment.