From df93e7515b757a75e2dc24d393daa6e3e50625ef Mon Sep 17 00:00:00 2001 From: Jennifer Date: Tue, 3 Sep 2024 16:31:32 +0100 Subject: [PATCH] test (provider): receiptProvider impl of BlockchainProvider2 (#10651) --- .../src/providers/blockchain_provider.rs | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 190e5c44efd7..52b24471526b 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -1484,7 +1484,7 @@ mod tests { }; use reth_storage_api::{ BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, BlockSource, - ChangeSetReader, HeaderProvider, ReceiptProviderIdExt, RequestsProvider, + ChangeSetReader, HeaderProvider, ReceiptProvider, ReceiptProviderIdExt, RequestsProvider, TransactionVariant, TransactionsProvider, WithdrawalsProvider, }; use reth_testing_utils::generators::{ @@ -3063,6 +3063,37 @@ mod tests { Ok(()) } + #[test] + fn test_receipt_provider() -> eyre::Result<()> { + let mut rng = generators::rng(); + let (provider, database_blocks, in_memory_blocks, receipts) = provider_with_random_blocks( + &mut rng, + TEST_BLOCKS_COUNT, + TEST_BLOCKS_COUNT, + BlockRangeParams { tx_count: 1..3, ..Default::default() }, + )?; + + let blocks = [database_blocks, in_memory_blocks].concat(); + + for block in blocks { + let block_number = block.number as usize; + for (txn_number, _) in block.body.iter().enumerate() { + let txn_hash = block.body.get(txn_number).unwrap().hash(); + let txn_id = provider.transaction_id(txn_hash)?.unwrap(); + assert_eq!( + provider.receipt(txn_id)?.unwrap(), + receipts.get(block_number).unwrap().clone().get(txn_number).unwrap().clone() + ); + assert_eq!( + provider.receipt_by_hash(txn_hash)?.unwrap(), + receipts.get(block_number).unwrap().clone().get(txn_number).unwrap().clone() + ); + } + } + + Ok(()) + } + #[test] fn test_receipt_provider_id_ext_receipts_by_block_id() -> eyre::Result<()> { let mut rng = generators::rng();