Skip to content

Commit

Permalink
test: prios tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkucharczyk committed Nov 12, 2024
1 parent 322774c commit a116c20
Showing 1 changed file with 44 additions and 21 deletions.
65 changes: 44 additions & 21 deletions substrate/client/transaction-pool/tests/fatp_prios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,34 +107,57 @@ 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::<Vec<_>>();
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::<Vec<_>>();
assert_eq!(xt1_status, vec![TransactionStatus::Ready]);

log::info!("len: {:?}", pool.mempool_len());
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::<Vec<_>>();

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::<Vec<_>>();
assert_eq!(xt1_status, vec![TransactionStatus::Future, TransactionStatus::Ready]);
let xt2_status = futures::executor::block_on_stream(xt2_watcher).take(1).collect::<Vec<_>>();
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);
}

0 comments on commit a116c20

Please sign in to comment.