From a116c201be8d4498f08226e2d6b01fcf0cae5c2f Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:42:32 +0100 Subject: [PATCH] test: prios tests --- .../transaction-pool/tests/fatp_prios.rs | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/substrate/client/transaction-pool/tests/fatp_prios.rs b/substrate/client/transaction-pool/tests/fatp_prios.rs index 9c70bb4b371c..e254a3d8171d 100644 --- a/substrate/client/transaction-pool/tests/fatp_prios.rs +++ b/substrate/client/transaction-pool/tests/fatp_prios.rs @@ -107,7 +107,10 @@ fn fatp_prio_watcher_ready_higher_evicts_lower() { block_on(pool.submit_and_watch(header01.hash(), SOURCE, xt1.clone())).unwrap(); let xt0_status = futures::executor::block_on_stream(xt0_watcher).take(2).collect::>(); - assert_eq!(xt0_status, vec![TransactionStatus::Ready, TransactionStatus::Dropped]); + assert_eq!( + xt0_status, + vec![TransactionStatus::Ready, TransactionStatus::Usurped(api.hash_and_length(&xt1).0)] + ); let xt1_status = futures::executor::block_on_stream(xt1_watcher).take(1).collect::>(); assert_eq!(xt1_status, vec![TransactionStatus::Ready]); @@ -115,26 +118,46 @@ fn fatp_prio_watcher_ready_higher_evicts_lower() { log::info!("len: {:?}", pool.status_all()[&header01.hash()]); assert_ready_iterator!(header01.hash(), pool, [xt1]); assert_pool_status!(header01.hash(), &pool, 1, 0); +} - // let results = block_on(futures::future::join_all(submissions)); - // assert!(results.iter().all(Result::is_ok)); - // //charlie was not included into view: - // assert_pool_status!(header01.hash(), &pool, 2, 0); +#[test] +fn fatp_prio_watcher_future_higher_evicts_lower() { + sp_tracing::try_init_simple(); - // //branch with alice transactions: - // let header02b = api.push_block(2, vec![xt1.clone(), xt2.clone()], true); - // let event = new_best_block_event(&pool, Some(header01.hash()), header02b.hash()); - // block_on(pool.maintain(event)); - // assert_eq!(pool.mempool_len().0, 2); - // assert_pool_status!(header02b.hash(), &pool, 0, 0); - // assert_ready_iterator!(header02b.hash(), pool, []); - // - // //branch with alice/charlie transactions shall also work: - // let header02a = api.push_block(2, vec![xt0.clone(), xt1.clone()], true); - // api.set_nonce(header02a.hash(), Alice.into(), 201); - // let event = new_best_block_event(&pool, Some(header02b.hash()), header02a.hash()); - // block_on(pool.maintain(event)); - // assert_eq!(pool.mempool_len().0, 2); - // // assert_pool_status!(header02a.hash(), &pool, 1, 0); - // assert_ready_iterator!(header02a.hash(), pool, [xt2]); + let builder = TestPoolBuilder::new(); + let (pool, api, _) = builder.with_mempool_count_limit(3).with_ready_count(3).build(); + + let header01 = api.push_block(1, vec![], true); + + let event = new_best_block_event(&pool, None, header01.hash()); + block_on(pool.maintain(event)); + + let xt0 = uxt(Alice, 201); + let xt1 = uxt(Alice, 201); + let xt2 = uxt(Alice, 200); + + api.set_priority(&xt0, 2); + api.set_priority(&xt1, 3); + + let xt0_watcher = + block_on(pool.submit_and_watch(header01.hash(), SOURCE, xt0.clone())).unwrap(); + let xt1_watcher = + block_on(pool.submit_and_watch(header01.hash(), SOURCE, xt1.clone())).unwrap(); + let xt2_watcher = + block_on(pool.submit_and_watch(header01.hash(), SOURCE, xt2.clone())).unwrap(); + + let xt0_status = futures::executor::block_on_stream(xt0_watcher).take(2).collect::>(); + + assert_eq!( + xt0_status, + vec![TransactionStatus::Future, TransactionStatus::Usurped(api.hash_and_length(&xt2).0)] + ); + let xt1_status = futures::executor::block_on_stream(xt1_watcher).take(2).collect::>(); + assert_eq!(xt1_status, vec![TransactionStatus::Future, TransactionStatus::Ready]); + let xt2_status = futures::executor::block_on_stream(xt2_watcher).take(1).collect::>(); + assert_eq!(xt2_status, vec![TransactionStatus::Ready]); + + assert_eq!(pool.mempool_len().1, 2); + assert_ready_iterator!(header01.hash(), pool, [xt2, xt1]); + assert_pool_status!(header01.hash(), &pool, 2, 0); }