From 4d96ea0343b1f5f716449da5ac2c08335e31edd1 Mon Sep 17 00:00:00 2001 From: Skanda Bhat Date: Tue, 5 Aug 2025 21:53:32 +0100 Subject: [PATCH] test(generators): add topics_count parameter to random_receipt (#17718) --- crates/prune/prune/src/segments/receipts.rs | 6 ++++-- crates/prune/prune/src/segments/user/receipts_by_logs.rs | 2 +- crates/stages/stages/src/stages/mod.rs | 2 +- crates/static-file/static-file/src/static_file_producer.rs | 6 ++++-- .../storage/provider/src/providers/blockchain_provider.rs | 2 +- testing/testing-utils/src/generators.rs | 3 ++- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/prune/prune/src/segments/receipts.rs b/crates/prune/prune/src/segments/receipts.rs index 2c94b5e4a8..393ca638b8 100644 --- a/crates/prune/prune/src/segments/receipts.rs +++ b/crates/prune/prune/src/segments/receipts.rs @@ -115,8 +115,10 @@ mod tests { for block in &blocks { receipts.reserve_exact(block.transaction_count()); for transaction in &block.body().transactions { - receipts - .push((receipts.len() as u64, random_receipt(&mut rng, transaction, Some(0)))); + receipts.push(( + receipts.len() as u64, + random_receipt(&mut rng, transaction, Some(0), None), + )); } } let receipts_len = receipts.len(); diff --git a/crates/prune/prune/src/segments/user/receipts_by_logs.rs b/crates/prune/prune/src/segments/user/receipts_by_logs.rs index b413a70394..bb214ea167 100644 --- a/crates/prune/prune/src/segments/user/receipts_by_logs.rs +++ b/crates/prune/prune/src/segments/user/receipts_by_logs.rs @@ -274,7 +274,7 @@ mod tests { for block in &blocks { receipts.reserve_exact(block.body().size()); for (txi, transaction) in block.body().transactions.iter().enumerate() { - let mut receipt = random_receipt(&mut rng, transaction, Some(1)); + let mut receipt = random_receipt(&mut rng, transaction, Some(1), None); receipt.logs.push(random_log( &mut rng, (txi == (block.transaction_count() - 1)).then_some(deposit_contract_addr), diff --git a/crates/stages/stages/src/stages/mod.rs b/crates/stages/stages/src/stages/mod.rs index b73136d092..e7210f0534 100644 --- a/crates/stages/stages/src/stages/mod.rs +++ b/crates/stages/stages/src/stages/mod.rs @@ -280,7 +280,7 @@ mod tests { for block in &blocks { let mut block_receipts = Vec::with_capacity(block.transaction_count()); for transaction in &block.body().transactions { - block_receipts.push((tx_num, random_receipt(&mut rng, transaction, Some(0)))); + block_receipts.push((tx_num, random_receipt(&mut rng, transaction, Some(0), None))); tx_num += 1; } receipts.push((block.number, block_receipts)); diff --git a/crates/static-file/static-file/src/static_file_producer.rs b/crates/static-file/static-file/src/static_file_producer.rs index 491419ef4b..6e517a461f 100644 --- a/crates/static-file/static-file/src/static_file_producer.rs +++ b/crates/static-file/static-file/src/static_file_producer.rs @@ -304,8 +304,10 @@ mod tests { let mut receipts = Vec::new(); for block in &blocks { for transaction in &block.body().transactions { - receipts - .push((receipts.len() as u64, random_receipt(&mut rng, transaction, Some(0)))); + receipts.push(( + receipts.len() as u64, + random_receipt(&mut rng, transaction, Some(0), None), + )); } } db.insert_receipts(receipts).expect("insert receipts"); diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index f372d0c0c0..af1b4fe91d 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -858,7 +858,7 @@ mod tests { .iter() .chain(in_memory_blocks.iter()) .map(|block| block.body().transactions.iter()) - .map(|tx| tx.map(|tx| random_receipt(rng, tx, Some(2))).collect()) + .map(|tx| tx.map(|tx| random_receipt(rng, tx, Some(2), None)).collect()) .collect(); let factory = create_test_provider_factory_with_chain_spec(chain_spec); diff --git a/testing/testing-utils/src/generators.rs b/testing/testing-utils/src/generators.rs index 793448cdba..b35ae13a81 100644 --- a/testing/testing-utils/src/generators.rs +++ b/testing/testing-utils/src/generators.rs @@ -453,6 +453,7 @@ pub fn random_receipt( rng: &mut R, transaction: &TransactionSigned, logs_count: Option, + topics_count: Option, ) -> Receipt { let success = rng.random::(); let logs_count = logs_count.unwrap_or_else(|| rng.random::()); @@ -462,7 +463,7 @@ pub fn random_receipt( success, cumulative_gas_used: rng.random_range(0..=transaction.gas_limit()), logs: if success { - (0..logs_count).map(|_| random_log(rng, None, None)).collect() + (0..logs_count).map(|_| random_log(rng, None, topics_count)).collect() } else { vec![] },