test(generators): add topics_count parameter to random_receipt (#17718)

This commit is contained in:
Skanda Bhat
2025-08-05 21:53:32 +01:00
committed by GitHub
parent ac83c27531
commit 4d96ea0343
6 changed files with 13 additions and 8 deletions

View File

@@ -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();

View File

@@ -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),

View File

@@ -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));

View File

@@ -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");

View File

@@ -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);

View File

@@ -453,6 +453,7 @@ pub fn random_receipt<R: Rng>(
rng: &mut R,
transaction: &TransactionSigned,
logs_count: Option<u8>,
topics_count: Option<u8>,
) -> Receipt {
let success = rng.random::<bool>();
let logs_count = logs_count.unwrap_or_else(|| rng.random::<u8>());
@@ -462,7 +463,7 @@ pub fn random_receipt<R: Rng>(
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![]
},