Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(storage): recover senders if not found in database #4470

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
)])
)
}
}
}
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
Loading