From b32562f4eab15bf2fc16a62d8636b3ab8284ce77 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Mon, 4 Sep 2023 13:20:19 +0100 Subject: [PATCH] test(storage): recover senders if not found in database (#4470) --- crates/storage/provider/Cargo.toml | 1 + .../provider/src/providers/database/mod.rs | 31 +++++++++++++++++++ .../src/providers/database/provider.rs | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/storage/provider/Cargo.toml b/crates/storage/provider/Cargo.toml index bcff000a09d3..45382391b567 100644 --- a/crates/storage/provider/Cargo.toml +++ b/crates/storage/provider/Cargo.toml @@ -38,6 +38,7 @@ reth-db = { path = "../db", features = ["test-utils"] } reth-primitives = { workspace = true, features = ["arbitrary", "test-utils"] } reth-rlp.workspace = true reth-trie = { path = "../../trie", features = ["test-utils"] } +reth-interfaces = { workspace = true, features = ["test-utils"] } parking_lot.workspace = true tempfile = "3.3" assert_matches.workspace = true diff --git a/crates/storage/provider/src/providers/database/mod.rs b/crates/storage/provider/src/providers/database/mod.rs index 45529c9f0490..4273964c136e 100644 --- a/crates/storage/provider/src/providers/database/mod.rs +++ b/crates/storage/provider/src/providers/database/mod.rs @@ -396,9 +396,11 @@ mod tests { use crate::{BlockHashReader, BlockNumReader, BlockWriter, TransactionsProvider}; use assert_matches::assert_matches; use reth_db::{ + tables, test_utils::{create_test_rw_db, ERROR_TEMPDIR}, DatabaseEnv, }; + use reth_interfaces::test_utils::{generators, generators::random_block}; use reth_primitives::{ hex_literal::hex, ChainSpecBuilder, PruneMode, PruneModes, SealedBlock, H256, }; @@ -485,4 +487,33 @@ mod tests { assert_matches!(provider.transaction_id(block.body[0].hash), Ok(None)); } } + + #[test] + fn get_take_block_transaction_range_recover_senders() { + let chain_spec = ChainSpecBuilder::mainnet().build(); + let db = create_test_rw_db(); + let factory = ProviderFactory::new(db, Arc::new(chain_spec)); + + let mut rng = generators::rng(); + let block = random_block(&mut rng, 0, None, Some(3), None); + + { + let provider = factory.provider_rw().unwrap(); + + assert_matches!(provider.insert_block(block.clone(), None, None), Ok(_)); + + let senders = provider.get_or_take::(0..=0); + assert_eq!(senders, Ok(vec![(0, block.body[0].recover_signer().unwrap())])); + assert_eq!(provider.transaction_sender(0), Ok(None)); + + let result = provider.get_take_block_transaction_range::(0..=0); + assert_eq!( + result, + Ok(vec![( + 0, + block.body.iter().cloned().map(|tx| tx.into_ecrecovered().unwrap()).collect() + )]) + ) + } + } } diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 9b30cbafbb72..ae8d87cabcdc 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -404,7 +404,7 @@ impl<'this, TX: DbTxMut<'this> + DbTx<'this>> DatabaseProvider<'this, TX> { } /// Get requested blocks transaction with signer - fn get_take_block_transaction_range( + pub(crate) fn get_take_block_transaction_range( &self, range: impl RangeBounds + Clone, ) -> Result)>> {