integration test: txpool listener could get replaced event (#15318)

This commit is contained in:
int88
2025-03-27 19:45:30 +08:00
committed by GitHub
parent 9bcd37f2a0
commit 963d8b95a4

View File

@@ -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();