Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generic data primitives block builder test framework #13522

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/chain-state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ mod tests {
#[test]
fn test_canonical_in_memory_state_canonical_chain_multiple_blocks() {
let mut parent_hash = B256::random();
let mut block_builder = TestBlockBuilder::default();
let mut block_builder = TestBlockBuilder::<EthPrimitives>::default();
let state: CanonicalInMemoryState = CanonicalInMemoryState::empty();

for i in 1..=3 {
Expand All @@ -1430,7 +1430,7 @@ mod tests {
#[test]
fn test_canonical_in_memory_state_canonical_chain_with_pending_block() {
let mut parent_hash = B256::random();
let mut block_builder = TestBlockBuilder::default();
let mut block_builder = TestBlockBuilder::<EthPrimitives>::default();
let state: CanonicalInMemoryState = CanonicalInMemoryState::empty();

for i in 1..=2 {
Expand Down
4 changes: 2 additions & 2 deletions crates/chain-state/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use tokio::sync::broadcast::{self, Sender};
/// Functionality to build blocks for tests and help with assertions about
/// their execution.
#[derive(Debug)]
pub struct TestBlockBuilder<N: NodePrimitives = reth_primitives::EthPrimitives> {
pub struct TestBlockBuilder<N: NodePrimitives = EthPrimitives> {
/// The account that signs all the block's transactions.
pub signer: Address,
/// Private key for signing.
Expand Down Expand Up @@ -66,7 +66,7 @@ impl<N: NodePrimitives> Default for TestBlockBuilder<N> {
}
}

impl TestBlockBuilder {
impl<N: NodePrimitives> TestBlockBuilder<N> {
/// Signer pk setter.
pub fn with_signer_pk(mut self, signer_pk: PrivateKeySigner) -> Self {
self.signer = signer_pk.address();
Expand Down
6 changes: 3 additions & 3 deletions crates/engine/tree/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ mod tests {
reth_tracing::init_test_tracing();
let persistence_handle = default_persistence_handle();
let block_number = 0;
let mut test_block_builder = TestBlockBuilder::default();
let mut test_block_builder = TestBlockBuilder::<EthPrimitives>::default();
let executed =
test_block_builder.get_executed_block_with_number(block_number, B256::random());
let block_hash = executed.block().hash();
Expand All @@ -361,7 +361,7 @@ mod tests {
reth_tracing::init_test_tracing();
let persistence_handle = default_persistence_handle();

let mut test_block_builder = TestBlockBuilder::default();
let mut test_block_builder = TestBlockBuilder::<EthPrimitives>::default();
let blocks = test_block_builder.get_executed_blocks(0..5).collect::<Vec<_>>();
let last_hash = blocks.last().unwrap().block().hash();
let (tx, rx) = oneshot::channel();
Expand All @@ -377,7 +377,7 @@ mod tests {
let persistence_handle = default_persistence_handle();

let ranges = [0..1, 1..2, 2..4, 4..5];
let mut test_block_builder = TestBlockBuilder::default();
let mut test_block_builder = TestBlockBuilder::<EthPrimitives>::default();
for range in ranges {
let blocks = test_block_builder.get_executed_blocks(range).collect::<Vec<_>>();
let last_hash = blocks.last().unwrap().block().hash();
Expand Down
31 changes: 18 additions & 13 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3106,7 +3106,7 @@ mod tests {
let tree_config = TreeConfig::default();
let chain_spec = MAINNET.clone();
let mut test_block_builder =
TestBlockBuilder::default().with_chain_spec((*chain_spec).clone());
TestBlockBuilder::<EthPrimitives>::default().with_chain_spec((*chain_spec).clone());

// we need more than tree_config.persistence_threshold() +1 blocks to
// trigger the persistence task.
Expand Down Expand Up @@ -3141,7 +3141,7 @@ mod tests {
let tree_config = TreeConfig::default();
let chain_spec = MAINNET.clone();
let mut test_block_builder =
TestBlockBuilder::default().with_chain_spec((*chain_spec).clone());
TestBlockBuilder::<EthPrimitives>::default().with_chain_spec((*chain_spec).clone());

// we need more than tree_config.persistence_threshold() +1 blocks to
// trigger the persistence task.
Expand Down Expand Up @@ -3173,7 +3173,8 @@ mod tests {

#[tokio::test]
async fn test_in_memory_state_trait_impl() {
let blocks: Vec<_> = TestBlockBuilder::default().get_executed_blocks(0..10).collect();
let blocks: Vec<_> =
TestBlockBuilder::<EthPrimitives>::default().get_executed_blocks(0..10).collect();
let test_harness = TestHarness::new(MAINNET.clone()).with_blocks(blocks.clone());

for executed_block in blocks {
Expand All @@ -3200,7 +3201,7 @@ mod tests {
#[tokio::test]
async fn test_engine_request_during_backfill() {
let tree_config = TreeConfig::default();
let blocks: Vec<_> = TestBlockBuilder::default()
let blocks: Vec<_> = TestBlockBuilder::<EthPrimitives>::default()
.get_executed_blocks(0..tree_config.persistence_threshold())
.collect();
let mut test_harness = TestHarness::new(MAINNET.clone())
Expand Down Expand Up @@ -3301,7 +3302,8 @@ mod tests {
#[tokio::test]
async fn test_tree_state_insert_executed() {
let mut tree_state = TreeState::new(BlockNumHash::default());
let blocks: Vec<_> = TestBlockBuilder::default().get_executed_blocks(1..4).collect();
let blocks: Vec<_> =
TestBlockBuilder::<EthPrimitives>::default().get_executed_blocks(1..4).collect();

tree_state.insert_executed(blocks[0].clone());
tree_state.insert_executed(blocks[1].clone());
Expand All @@ -3327,7 +3329,7 @@ mod tests {
#[tokio::test]
async fn test_tree_state_insert_executed_with_reorg() {
let mut tree_state = TreeState::new(BlockNumHash::default());
let mut test_block_builder = TestBlockBuilder::default();
let mut test_block_builder = TestBlockBuilder::<EthPrimitives>::default();
let blocks: Vec<_> = test_block_builder.get_executed_blocks(1..6).collect();

for block in &blocks {
Expand Down Expand Up @@ -3367,7 +3369,8 @@ mod tests {
async fn test_tree_state_remove_before() {
let start_num_hash = BlockNumHash::default();
let mut tree_state = TreeState::new(start_num_hash);
let blocks: Vec<_> = TestBlockBuilder::default().get_executed_blocks(1..6).collect();
let blocks: Vec<_> =
TestBlockBuilder::<EthPrimitives>::default().get_executed_blocks(1..6).collect();

for block in &blocks {
tree_state.insert_executed(block.clone());
Expand Down Expand Up @@ -3417,7 +3420,8 @@ mod tests {
async fn test_tree_state_remove_before_finalized() {
let start_num_hash = BlockNumHash::default();
let mut tree_state = TreeState::new(start_num_hash);
let blocks: Vec<_> = TestBlockBuilder::default().get_executed_blocks(1..6).collect();
let blocks: Vec<_> =
TestBlockBuilder::<EthPrimitives>::default().get_executed_blocks(1..6).collect();

for block in &blocks {
tree_state.insert_executed(block.clone());
Expand Down Expand Up @@ -3467,7 +3471,8 @@ mod tests {
async fn test_tree_state_remove_before_lower_finalized() {
let start_num_hash = BlockNumHash::default();
let mut tree_state = TreeState::new(start_num_hash);
let blocks: Vec<_> = TestBlockBuilder::default().get_executed_blocks(1..6).collect();
let blocks: Vec<_> =
TestBlockBuilder::<EthPrimitives>::default().get_executed_blocks(1..6).collect();

for block in &blocks {
tree_state.insert_executed(block.clone());
Expand Down Expand Up @@ -3517,7 +3522,7 @@ mod tests {
async fn test_tree_state_on_new_head() {
let chain_spec = MAINNET.clone();
let mut test_harness = TestHarness::new(chain_spec);
let mut test_block_builder = TestBlockBuilder::default();
let mut test_block_builder = TestBlockBuilder::<EthPrimitives>::default();

let blocks: Vec<_> = test_block_builder.get_executed_blocks(1..6).collect();

Expand Down Expand Up @@ -3569,7 +3574,7 @@ mod tests {

let chain_spec = MAINNET.clone();
let mut test_harness = TestHarness::new(chain_spec);
let mut test_block_builder = TestBlockBuilder::default();
let mut test_block_builder = TestBlockBuilder::<EthPrimitives>::default();

let blocks: Vec<_> = test_block_builder.get_executed_blocks(0..5).collect();

Expand Down Expand Up @@ -3636,7 +3641,7 @@ mod tests {
async fn test_get_canonical_blocks_to_persist() {
let chain_spec = MAINNET.clone();
let mut test_harness = TestHarness::new(chain_spec);
let mut test_block_builder = TestBlockBuilder::default();
let mut test_block_builder = TestBlockBuilder::<EthPrimitives>::default();

let canonical_head_number = 9;
let blocks: Vec<_> =
Expand Down Expand Up @@ -3692,7 +3697,7 @@ mod tests {
let mut test_harness = TestHarness::new(chain_spec.clone());

let mut test_block_builder =
TestBlockBuilder::default().with_chain_spec((*chain_spec).clone());
TestBlockBuilder::<EthPrimitives>::default().with_chain_spec((*chain_spec).clone());

let blocks: Vec<_> = test_block_builder.get_executed_blocks(0..5).collect();
test_harness = test_harness.with_blocks(blocks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ mod tests {
use reth_db_api::{cursor::DbCursorRO, transaction::DbTx};
use reth_errors::ProviderError;
use reth_execution_types::{Chain, ExecutionOutcome};
use reth_primitives::{BlockExt, Receipt, SealedBlock, StaticFileSegment};
use reth_primitives::{BlockExt, EthPrimitives, Receipt, SealedBlock, StaticFileSegment};
use reth_primitives_traits::{BlockBody as _, SignedTransaction};
use reth_storage_api::{
BlockBodyIndicesProvider, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader,
Expand Down Expand Up @@ -1408,7 +1408,7 @@ mod tests {
let factory = create_test_provider_factory();

// Generate a random block to initialise the blockchain provider.
let mut test_block_builder = TestBlockBuilder::default();
let mut test_block_builder = TestBlockBuilder::<EthPrimitives>::default();
let block_1 = test_block_builder.generate_random_block(0, B256::ZERO);
let block_hash_1 = block_1.hash();

Expand Down
Loading