add a new unit test for extrinsic pool (#611)

This commit is contained in:
Guanqun Lu
2018-08-28 17:53:59 +08:00
committed by Gav Wood
parent 98f3f80e70
commit 3a58595a85
@@ -164,4 +164,39 @@ mod tests {
// then
assert!(!rotator.is_banned(&hash));
}
#[test]
fn should_garbage_collect() {
// given
fn tx_with(i: u64, time: Instant) -> Verified<u64, VerifiedTransaction> {
let hash = i.into();
Verified {
original: i,
verified: VerifiedTransaction {
hash,
sender: Default::default(),
nonce: Default::default(),
},
valid_till: time,
}
}
let rotator = rotator();
let now = Instant::now();
let past = now - Duration::from_secs(1);
// when
for i in 0..2*EXPECTED_SIZE {
let tx = tx_with(i as u64, past);
assert!(rotator.ban_if_stale(&now, &tx));
}
assert_eq!(rotator.banned_until.read().len(), 2*EXPECTED_SIZE);
// then
let tx = tx_with(2*EXPECTED_SIZE as u64, past);
// trigger a garbage collection
assert!(rotator.ban_if_stale(&now, &tx));
assert_eq!(rotator.banned_until.read().len(), EXPECTED_SIZE);
}
}