Skip to content

Commit

Permalink
transaction-pool: add unit test for BlobStoreCanonTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Oct 18, 2024
1 parent 9c8f5d8 commit b45d21d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,7 @@ reth-trie-db = { path = "crates/trie/db" }
reth-trie-parallel = { path = "crates/trie/parallel" }

# revm
revm = { version = "14.0.3", features = [
"std",
], default-features = false }
revm = { version = "14.0.3", features = ["std"], default-features = false }
revm-inspectors = "0.8.1"
revm-primitives = { version = "10.0.0", features = [
"std",
Expand Down
6 changes: 5 additions & 1 deletion crates/transaction-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
88 changes: 88 additions & 0 deletions crates/transaction-pool/src/blobstore/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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());
}
}

0 comments on commit b45d21d

Please sign in to comment.