test(txpool): add unit test for BlobStoreCanonTracker (#11885)

This commit is contained in:
Thomas Coratger
2024-10-19 10:28:42 +02:00
committed by GitHub
parent 2f559c62bf
commit da5079d11f
2 changed files with 93 additions and 1 deletions

View File

@ -74,7 +74,11 @@ serde_json.workspace = true
default = ["serde"]
serde = ["dep:serde"]
test-utils = ["rand", "paste", "serde"]
arbitrary = ["proptest", "reth-primitives/arbitrary", "proptest-arbitrary-interop"]
arbitrary = [
"proptest",
"reth-primitives/arbitrary",
"proptest-arbitrary-interop",
]
[[bench]]
name = "truncate"

View File

@ -81,6 +81,13 @@ pub enum BlobStoreUpdates {
#[cfg(test)]
mod tests {
use alloy_consensus::Header;
use reth_execution_types::Chain;
use reth_primitives::{
BlockBody, SealedBlock, SealedBlockWithSenders, SealedHeader, Transaction,
TransactionSigned,
};
use super::*;
#[test]
@ -101,4 +108,85 @@ mod tests {
BlobStoreUpdates::Finalized(block2.into_iter().chain(block3).collect::<Vec<_>>())
);
}
#[test]
fn test_add_new_chain_blocks() {
let mut tracker = BlobStoreCanonTracker::default();
// Create sample transactions
let tx1_hash = B256::random(); // EIP-4844 transaction
let tx2_hash = B256::random(); // EIP-4844 transaction
let tx3_hash = B256::random(); // Non-EIP-4844 transaction
// Creating a first block with EIP-4844 transactions
let block1 = SealedBlockWithSenders {
block: SealedBlock {
header: SealedHeader::new(
Header { number: 10, ..Default::default() },
B256::random(),
),
body: BlockBody {
transactions: vec![
TransactionSigned {
hash: tx1_hash,
transaction: Transaction::Eip4844(Default::default()),
..Default::default()
},
TransactionSigned {
hash: tx2_hash,
transaction: Transaction::Eip4844(Default::default()),
..Default::default()
},
// Another transaction that is not EIP-4844
TransactionSigned {
hash: B256::random(),
transaction: Transaction::Eip7702(Default::default()),
..Default::default()
},
],
..Default::default()
},
},
..Default::default()
};
// Creating a second block with EIP-1559 and EIP-2930 transactions
// Note: This block does not contain any EIP-4844 transactions
let block2 = SealedBlockWithSenders {
block: SealedBlock {
header: SealedHeader::new(
Header { number: 11, ..Default::default() },
B256::random(),
),
body: BlockBody {
transactions: vec![
TransactionSigned {
hash: tx3_hash,
transaction: Transaction::Eip1559(Default::default()),
..Default::default()
},
TransactionSigned {
hash: tx2_hash,
transaction: Transaction::Eip2930(Default::default()),
..Default::default()
},
],
..Default::default()
},
},
..Default::default()
};
// Extract blocks from the chain
let chain = Chain::new(vec![block1, block2], Default::default(), None);
let blocks = chain.into_inner().0;
// Add new chain blocks to the tracker
tracker.add_new_chain_blocks(&blocks);
// Tx1 and tx2 should be in the block containing EIP-4844 transactions
assert_eq!(tracker.blob_txs_in_blocks.get(&10).unwrap(), &vec![tx1_hash, tx2_hash]);
// No transactions should be in the block containing non-EIP-4844 transactions
assert!(tracker.blob_txs_in_blocks.get(&11).unwrap().is_empty());
}
}