Skip to content

Commit

Permalink
feat: generic data primitives block builder test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed Dec 23, 2024
1 parent 6e14010 commit 033b986
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
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
26 changes: 13 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,7 @@ 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 +3200,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 +3301,7 @@ 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 +3327,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 +3367,7 @@ 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 +3417,7 @@ 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 +3467,7 @@ 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 +3517,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 +3569,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 +3636,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 +3692,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
4 changes: 2 additions & 2 deletions crates/storage/provider/src/providers/blockchain_provider.rs
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

0 comments on commit 033b986

Please sign in to comment.