feat: generic data primitives block builder test framework (#13522)

This commit is contained in:
Hoa Nguyen
2024-12-27 16:41:29 +07:00
committed by GitHub
parent df294e424b
commit 0933e1b07d
5 changed files with 30 additions and 27 deletions

View File

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

View File

@ -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.
@ -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();
@ -295,6 +295,13 @@ impl TestBlockBuilder {
execution_outcome.with_receipts(Receipts::from(receipts))
}
}
impl TestBlockBuilder {
/// Creates a `TestBlockBuilder` configured for Ethereum primitives.
pub fn eth() -> Self {
Self::default()
}
}
/// A test `ChainEventSubscriptions`
#[derive(Clone, Debug, Default)]
pub struct TestCanonStateSubscriptions<N: NodePrimitives = reth_primitives::EthPrimitives> {