Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests
  • Loading branch information
NikVolf committed Mar 12, 2020
commit 31ea82ef75f83048c41b97b48c838bc1e797a45a
52 changes: 52 additions & 0 deletions client/transaction-pool/src/testing/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use substrate_test_runtime_client::{
};
use substrate_test_runtime_transaction_pool::{TestApi, uxt};
use crate::revalidation::BACKGROUND_REVALIDATION_INTERVAL;
use futures::task::Poll;

fn pool() -> Pool<TestApi> {
Pool::new(Default::default(), TestApi::with_alice_nonce(209).into())
Expand Down Expand Up @@ -600,5 +601,56 @@ fn fork_aware_finalization() {
assert_eq!(stream.next(), Some(TransactionStatus::Finalized(e1.clone())));
assert_eq!(stream.next(), None);
}
}

#[test]
fn ready_set_should_not_resolve_before_block_update() {
let (pool, _guard) = maintained_pool();
let xt1 = uxt(Alice, 209);
block_on(pool.submit_one(&BlockId::number(1), xt1.clone())).expect("1. Imported");

assert!(pool.ready_at(Some(1)).now_or_never().is_none());
}

#[test]
fn ready_set_should_resolve_after_block_update() {
let (pool, _guard) = maintained_pool();
pool.api.push_block(1, vec![]);

let xt1 = uxt(Alice, 209);

block_on(pool.submit_one(&BlockId::number(1), xt1.clone())).expect("1. Imported");
block_on(pool.maintain(block_event(1)));

assert!(pool.ready_at(Some(1)).now_or_never().is_some());
}

#[test]
fn ready_set_should_eventually_resolve_when_block_update_arrives() {
let (pool, _guard) = maintained_pool();
pool.api.push_block(1, vec![]);

let xt1 = uxt(Alice, 209);

block_on(pool.submit_one(&BlockId::number(1), xt1.clone())).expect("1. Imported");

let noop_waker = futures::task::noop_waker();
let mut context = futures::task::Context::from_waker(&noop_waker);

let mut ready_set_future = pool.ready_at(Some(1));
if let Poll::Ready(_) = ready_set_future.poll_unpin(&mut context) {
panic!("Ready set should not be ready before block update!");
}

block_on(pool.maintain(block_event(1)));

match ready_set_future.poll_unpin(&mut context) {
Poll::Pending => {
panic!("Ready set should become ready after block update!");
},
Poll::Ready(iterator) => {
let data = iterator.collect::<Vec<_>>();
assert_eq!(data.len(), 1);
}
}
}