Skip to content

Commit

Permalink
test(storage): recover senders if not found in database (#4470)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin authored Sep 4, 2023
1 parent 03887a2 commit b32562f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/storage/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions crates/storage/provider/src/providers/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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::<tables::TxSenders, true>(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::<true>(0..=0);
assert_eq!(
result,
Ok(vec![(
0,
block.body.iter().cloned().map(|tx| tx.into_ecrecovered().unwrap()).collect()
)])
)
}
}
}
2 changes: 1 addition & 1 deletion crates/storage/provider/src/providers/database/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<const TAKE: bool>(
pub(crate) fn get_take_block_transaction_range<const TAKE: bool>(
&self,
range: impl RangeBounds<BlockNumber> + Clone,
) -> Result<Vec<(BlockNumber, Vec<TransactionSignedEcRecovered>)>> {
Expand Down

0 comments on commit b32562f

Please sign in to comment.