Skip to content

Commit

Permalink
test: BlockIdReader implementation of BlockchainProvider2<DB> (#1…
Browse files Browse the repository at this point in the history
…0362)

Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: Alexey Shekhirin <[email protected]>
  • Loading branch information
3 people authored Aug 22, 2024
1 parent f686e0b commit 7fb9a04
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 71 deletions.
100 changes: 31 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 49 additions & 2 deletions crates/storage/provider/src/providers/blockchain_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,10 +1503,11 @@ mod tests {
use reth_db::{models::AccountBeforeTx, test_utils::TempDatabase, DatabaseEnv};
use reth_execution_types::{Chain, ExecutionOutcome};
use reth_primitives::{
BlockHashOrNumber, BlockNumberOrTag, Receipt, SealedBlock, StaticFileSegment, B256,
BlockHashOrNumber, BlockNumHash, BlockNumberOrTag, Receipt, SealedBlock, StaticFileSegment,
B256,
};
use reth_storage_api::{
BlockHashReader, BlockNumReader, BlockReader, BlockReaderIdExt, BlockSource,
BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, BlockSource,
ChangeSetReader, HeaderProvider, ReceiptProviderIdExt, RequestsProvider,
};
use reth_testing_utils::generators::{
Expand Down Expand Up @@ -2430,4 +2431,50 @@ mod tests {

Ok(())
}

#[test]
fn test_block_id_reader() -> eyre::Result<()> {
// Create a new provider
let mut rng = generators::rng();
let (provider, _, in_memory_blocks, _) =
provider_with_random_blocks(&mut rng, TEST_BLOCKS_COUNT, TEST_BLOCKS_COUNT, None)?;

// Set the pending block in memory
let pending_block = in_memory_blocks.last().unwrap();
provider.canonical_in_memory_state.set_pending_block(ExecutedBlock {
block: Arc::new(pending_block.clone()),
senders: Default::default(),
execution_output: Default::default(),
hashed_state: Default::default(),
trie: Default::default(),
});

// Set the safe block in memory
let safe_block = in_memory_blocks[in_memory_blocks.len() - 2].clone();
provider.canonical_in_memory_state.set_safe(safe_block.header.clone());

// Set the finalized block in memory
let finalized_block = in_memory_blocks[in_memory_blocks.len() - 3].clone();
provider.canonical_in_memory_state.set_finalized(finalized_block.header.clone());

// Verify the pending block number and hash
assert_eq!(
provider.pending_block_num_hash()?,
Some(BlockNumHash { number: pending_block.number, hash: pending_block.hash() })
);

// Verify the safe block number and hash
assert_eq!(
provider.safe_block_num_hash()?,
Some(BlockNumHash { number: safe_block.number, hash: safe_block.hash() })
);

// Verify the finalized block number and hash
assert_eq!(
provider.finalized_block_num_hash()?,
Some(BlockNumHash { number: finalized_block.number, hash: finalized_block.hash() })
);

Ok(())
}
}

0 comments on commit 7fb9a04

Please sign in to comment.