Skip to content

Commit

Permalink
feat: use new engine in e2e tests for OP
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Dec 25, 2024
1 parent 3fbb230 commit 2c82290
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
11 changes: 8 additions & 3 deletions crates/optimism/node/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ use crate::{OpBuiltPayload, OpNode as OtherOpNode, OpPayloadBuilderAttributes};
use alloy_genesis::Genesis;
use alloy_primitives::{Address, B256};
use alloy_rpc_types_engine::PayloadAttributes;
use reth_e2e_test_utils::{transaction::TransactionTestContext, wallet::Wallet, NodeHelperType};
use reth_e2e_test_utils::{
transaction::TransactionTestContext, wallet::Wallet, NodeHelperType, TmpDB,
};
use reth_node_api::NodeTypesWithDBAdapter;
use reth_optimism_chainspec::OpChainSpecBuilder;
use reth_payload_builder::EthPayloadBuilderAttributes;
use reth_provider::providers::BlockchainProvider2;
use reth_tasks::TaskManager;
use std::sync::Arc;
use tokio::sync::Mutex;

/// Optimism Node Helper type
pub(crate) type OpNode = NodeHelperType<OtherOpNode>;
pub(crate) type OpNode =
NodeHelperType<OtherOpNode, BlockchainProvider2<NodeTypesWithDBAdapter<OtherOpNode, TmpDB>>>;

/// Creates the initial setup with `num_nodes` of the node config, started and connected.
pub async fn setup(num_nodes: usize) -> eyre::Result<(Vec<OpNode>, TaskManager, Wallet)> {
let genesis: Genesis =
serde_json::from_str(include_str!("../tests/assets/genesis.json")).unwrap();
reth_e2e_test_utils::setup(
reth_e2e_test_utils::setup_engine(
num_nodes,
Arc::new(OpChainSpecBuilder::base_mainnet().genesis(genesis).ecotone_activated().build()),
false,
Expand Down
30 changes: 10 additions & 20 deletions crates/optimism/node/tests/e2e/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ async fn can_sync() -> eyre::Result<()> {
.update_optimistic_forkchoice(canonical_chain[tip_index - reorg_depth])
.await?;
second_node
.wait_block((tip - reorg_depth) as u64, canonical_chain[tip_index - reorg_depth], true)
.wait_block((tip - reorg_depth) as u64, canonical_chain[tip_index - reorg_depth], false)
.await?;
second_node.engine_api.canonical_stream.next().await.unwrap();

// On third node, sync optimistically up to block number 90a
// Trigger backfil sync until block 80
third_node
.engine_api
.update_forkchoice(canonical_chain[tip_index - 10], canonical_chain[tip_index - 10])
.await?;
third_node.wait_block((tip - 10) as u64, canonical_chain[tip_index - 10], true).await?;
// Trigger live sync to block 90
third_node.engine_api.update_optimistic_forkchoice(canonical_chain[tip_index]).await?;
third_node.wait_block(tip as u64, canonical_chain[tip_index], true).await?;
third_node.wait_block(tip as u64, canonical_chain[tip_index], false).await?;

// On second node, create a side chain: 88a -> 89b -> 90b
wallet.lock().await.inner_nonce -= reorg_depth as u64;
Expand Down Expand Up @@ -77,25 +83,9 @@ async fn can_sync() -> eyre::Result<()> {
.wait_block(
side_payload_chain[0].0.block().number,
side_payload_chain[0].0.block().hash(),
true,
false,
)
.await?;

// Make sure that trying to submit 89a again will result in an invalid payload status, since 89b
// has been set as finalized.
let _ = third_node
.engine_api
.submit_payload(
canonical_payload_chain[tip_index - reorg_depth + 1].0.clone(),
canonical_payload_chain[tip_index - reorg_depth + 1].1.clone(),
PayloadStatusEnum::Invalid {
validation_error: format!(
"block number is lower than the last finalized block number {}",
(tip - reorg_depth) as u64 + 1
),
},
)
.await;

Ok(())
}

0 comments on commit 2c82290

Please sign in to comment.