Skip to content
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
15 changes: 14 additions & 1 deletion crates/transaction-pool/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use reth_primitives::{
hex, Address, FromRecoveredPooledTransaction, FromRecoveredTransaction,
IntoRecoveredTransaction, PooledTransactionsElementEcRecovered, Signature, Transaction,
TransactionKind, TransactionSigned, TransactionSignedEcRecovered, TxEip1559, TxEip2930,
TxEip4844, TxHash, TxLegacy, TxType, H256, U128, U256,
TxEip4844, TxHash, TxLegacy, TxType, EIP1559_TX_TYPE_ID, EIP4844_TX_TYPE_ID, H256,
LEGACY_TX_TYPE_ID, U128, U256,
};
use std::{ops::Range, sync::Arc, time::Instant};

Expand Down Expand Up @@ -351,6 +352,14 @@ impl MockTransaction {
next.with_gas_limit(gas)
}

pub fn tx_type(&self) -> u8 {
match self {
Self::Legacy { .. } => LEGACY_TX_TYPE_ID,
Self::Eip1559 { .. } => EIP1559_TX_TYPE_ID,
Self::Eip4844 { .. } => EIP4844_TX_TYPE_ID,
}
}

pub fn is_legacy(&self) -> bool {
matches!(self, MockTransaction::Legacy { .. })
}
Expand Down Expand Up @@ -715,6 +724,10 @@ impl MockTransactionFactory {
pub fn create_eip1559(&mut self) -> MockValidTx {
self.validated(MockTransaction::eip1559())
}

pub fn create_eip4844(&mut self) -> MockValidTx {
self.validated(MockTransaction::eip4844())
}
}

#[derive(Clone, Default)]
Expand Down
40 changes: 40 additions & 0 deletions crates/transaction-pool/tests/it/blobs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Blob transaction tests

use reth_transaction_pool::{
error::PoolError,
test_utils::{testing_pool, MockTransaction, MockTransactionFactory},
TransactionOrigin, TransactionPool,
};

#[tokio::test(flavor = "multi_thread")]
async fn blobs_exclusive() {
let txpool = testing_pool();
let mut mock_tx_factory = MockTransactionFactory::default();
let blob_tx = mock_tx_factory.create_eip4844();

let hash = txpool
.add_transaction(TransactionOrigin::External, blob_tx.transaction.clone())
.await
.unwrap();
assert_eq!(hash, blob_tx.transaction.get_hash());

let mut best_txns = txpool.best_transactions();
assert_eq!(best_txns.next().unwrap().transaction.get_hash(), blob_tx.transaction.get_hash());
assert!(best_txns.next().is_none());

let eip1559_tx = MockTransaction::eip1559()
.set_sender(blob_tx.transaction.get_sender())
.inc_price_by(10_000);

let res =
txpool.add_transaction(TransactionOrigin::External, eip1559_tx.clone()).await.unwrap_err();

match res {
PoolError::ExistingConflictingTransactionType(addr, hash, tx_type) => {
assert_eq!(addr, eip1559_tx.get_sender());
assert_eq!(hash, eip1559_tx.get_hash());
assert_eq!(tx_type, eip1559_tx.tx_type());
}
_ => unreachable!(),
}
}
2 changes: 2 additions & 0 deletions crates/transaction-pool/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! transaction-pool integration tests

#[cfg(feature = "test-utils")]
mod blobs;
#[cfg(feature = "test-utils")]
mod listeners;
#[cfg(feature = "test-utils")]
Expand Down