From 35dc72bd03cfde0eefda3c2bbd8db548c1187d7d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 15 Sep 2023 11:44:30 +0200 Subject: [PATCH] test: add blob exclusive test e2e --- .../transaction-pool/src/test_utils/mock.rs | 15 ++++++- crates/transaction-pool/tests/it/blobs.rs | 40 +++++++++++++++++++ crates/transaction-pool/tests/it/main.rs | 2 + 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 crates/transaction-pool/tests/it/blobs.rs diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index d42e45cdb49..62ebb47e57e 100644 --- a/crates/transaction-pool/src/test_utils/mock.rs +++ b/crates/transaction-pool/src/test_utils/mock.rs @@ -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}; @@ -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 { .. }) } @@ -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)] diff --git a/crates/transaction-pool/tests/it/blobs.rs b/crates/transaction-pool/tests/it/blobs.rs new file mode 100644 index 00000000000..cdcce9de3da --- /dev/null +++ b/crates/transaction-pool/tests/it/blobs.rs @@ -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!(), + } +} diff --git a/crates/transaction-pool/tests/it/main.rs b/crates/transaction-pool/tests/it/main.rs index 409be67792d..49a3b058ea9 100644 --- a/crates/transaction-pool/tests/it/main.rs +++ b/crates/transaction-pool/tests/it/main.rs @@ -1,5 +1,7 @@ //! transaction-pool integration tests +#[cfg(feature = "test-utils")] +mod blobs; #[cfg(feature = "test-utils")] mod listeners; #[cfg(feature = "test-utils")]