mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-19 03:04:27 -05:00
integration test: txpool listener could get replaced event (#15318)
This commit is contained in:
@@ -28,6 +28,43 @@ async fn txpool_listener_by_hash() {
|
||||
assert_matches!(events.next().await, Some(TransactionEvent::Discarded));
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn txpool_listener_replace_event() {
|
||||
let txpool = TestPoolBuilder::default();
|
||||
let mut mock_tx_factory = MockTransactionFactory::default();
|
||||
let transaction = mock_tx_factory.create_eip1559();
|
||||
|
||||
let mut all_tx_events = txpool.all_transactions_event_listener();
|
||||
|
||||
let old_transaction = transaction.transaction.clone();
|
||||
let mut result = txpool
|
||||
.add_transaction_and_subscribe(TransactionOrigin::External, old_transaction.clone())
|
||||
.await;
|
||||
assert_matches!(result, Ok(_));
|
||||
|
||||
let mut events = result.unwrap();
|
||||
assert_matches!(events.next().await, Some(TransactionEvent::Pending));
|
||||
assert_matches!(all_tx_events.next().await, Some(FullTransactionEvent::Pending(hash)) if hash == *old_transaction.get_hash());
|
||||
|
||||
// add replace tx.
|
||||
let replace_transaction = transaction.transaction.clone().rng_hash().inc_price();
|
||||
result = txpool
|
||||
.add_transaction_and_subscribe(TransactionOrigin::External, replace_transaction.clone())
|
||||
.await;
|
||||
assert_matches!(result, Ok(_));
|
||||
|
||||
let mut new_events = result.unwrap();
|
||||
assert_matches!(new_events.next().await, Some(TransactionEvent::Pending));
|
||||
|
||||
// The listener of old transaction should receive replaced event.
|
||||
assert_matches!(events.next().await, Some(TransactionEvent::Replaced(hash)) if hash == *replace_transaction.get_hash());
|
||||
|
||||
// The listener of all should receive one pending event of new transaction and one replaced
|
||||
// event of old transaction.
|
||||
assert_matches!(all_tx_events.next().await, Some(FullTransactionEvent::Pending(hash)) if hash == *replace_transaction.get_hash());
|
||||
assert_matches!(all_tx_events.next().await, Some(FullTransactionEvent::Replaced { transaction, replaced_by }) if *transaction.transaction.get_hash() == *old_transaction.get_hash() && replaced_by == *replace_transaction.get_hash());
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn txpool_listener_all() {
|
||||
let txpool = TestPoolBuilder::default();
|
||||
|
||||
Reference in New Issue
Block a user