Skip to content

Commit

Permalink
bet
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed Dec 26, 2024
1 parent 300c03a commit c8c0584
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
7 changes: 3 additions & 4 deletions crates/chain-state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,8 +1389,7 @@ mod tests {

#[test]
fn test_canonical_in_memory_state_canonical_chain_single_block() {
let block = TestBlockBuilder::<EthPrimitives>::default()
.get_executed_block_with_number(1, B256::random());
let block = TestBlockBuilder::eth().get_executed_block_with_number(1, B256::random());
let hash = block.block().hash();
let mut blocks = HashMap::default();
blocks.insert(hash, Arc::new(BlockState::new(block)));
Expand All @@ -1408,7 +1407,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::<EthPrimitives>::default();
let mut block_builder = TestBlockBuilder::eth();
let state: CanonicalInMemoryState = CanonicalInMemoryState::empty();

for i in 1..=3 {
Expand All @@ -1430,7 +1429,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::<EthPrimitives>::default();
let mut block_builder = TestBlockBuilder::eth();
let state: CanonicalInMemoryState = CanonicalInMemoryState::empty();

for i in 1..=2 {
Expand Down
5 changes: 5 additions & 0 deletions crates/chain-state/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {

execution_outcome.with_receipts(Receipts::from(receipts))
}

/// Creates a TestBlockBuilder configured for Ethereum primitives.
pub fn eth() -> TestBlockBuilder<EthPrimitives> {
TestBlockBuilder::eth()
}
}
/// A test `ChainEventSubscriptions`
#[derive(Clone, Debug, Default)]
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::<EthPrimitives>::default();
let mut test_block_builder = TestBlockBuilder::eth();
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::<EthPrimitives>::default();
let mut test_block_builder = TestBlockBuilder::eth();
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::<EthPrimitives>::default();
let mut test_block_builder = TestBlockBuilder::eth();
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
34 changes: 13 additions & 21 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3105,8 +3105,7 @@ mod tests {
fn test_tree_persist_block_batch() {
let tree_config = TreeConfig::default();
let chain_spec = MAINNET.clone();
let mut test_block_builder =
TestBlockBuilder::<EthPrimitives>::default().with_chain_spec((*chain_spec).clone());
let mut test_block_builder = TestBlockBuilder::eth().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 @@ -3140,8 +3139,7 @@ mod tests {
async fn test_tree_persist_blocks() {
let tree_config = TreeConfig::default();
let chain_spec = MAINNET.clone();
let mut test_block_builder =
TestBlockBuilder::<EthPrimitives>::default().with_chain_spec((*chain_spec).clone());
let mut test_block_builder = TestBlockBuilder::eth().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,8 +3171,7 @@ mod tests {

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

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

tree_state.insert_executed(blocks[0].clone());
tree_state.insert_executed(blocks[1].clone());
Expand All @@ -3329,7 +3325,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::<EthPrimitives>::default();
let mut test_block_builder = TestBlockBuilder::eth();
let blocks: Vec<_> = test_block_builder.get_executed_blocks(1..6).collect();

for block in &blocks {
Expand Down Expand Up @@ -3369,8 +3365,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::<EthPrimitives>::default().get_executed_blocks(1..6).collect();
let blocks: Vec<_> = TestBlockBuilder::eth().get_executed_blocks(1..6).collect();

for block in &blocks {
tree_state.insert_executed(block.clone());
Expand Down Expand Up @@ -3420,8 +3415,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::<EthPrimitives>::default().get_executed_blocks(1..6).collect();
let blocks: Vec<_> = TestBlockBuilder::eth().get_executed_blocks(1..6).collect();

for block in &blocks {
tree_state.insert_executed(block.clone());
Expand Down Expand Up @@ -3471,8 +3465,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::<EthPrimitives>::default().get_executed_blocks(1..6).collect();
let blocks: Vec<_> = TestBlockBuilder::eth().get_executed_blocks(1..6).collect();

for block in &blocks {
tree_state.insert_executed(block.clone());
Expand Down Expand Up @@ -3522,7 +3515,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::<EthPrimitives>::default();
let mut test_block_builder = TestBlockBuilder::eth();

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

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

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

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

Expand Down Expand Up @@ -3641,7 +3634,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::<EthPrimitives>::default();
let mut test_block_builder = TestBlockBuilder::eth();

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

let mut test_block_builder =
TestBlockBuilder::<EthPrimitives>::default().with_chain_spec((*chain_spec).clone());
let mut test_block_builder = TestBlockBuilder::eth().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 @@ -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::<EthPrimitives>::default();
let mut test_block_builder = TestBlockBuilder::eth();
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 c8c0584

Please sign in to comment.