test: add blob exclusive test e2e (#4606)

This commit is contained in:
Matthias Seitz
2023-09-15 16:28:52 +02:00
committed by GitHub
parent 6b8db8ace4
commit ee85fa3d44
3 changed files with 56 additions and 1 deletions

View File

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

View File

@ -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!(),
}
}

View File

@ -1,5 +1,7 @@
//! transaction-pool integration tests
#[cfg(feature = "test-utils")]
mod blobs;
#[cfg(feature = "test-utils")]
mod listeners;
#[cfg(feature = "test-utils")]