mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
add a new unit test for extrinsic pool (#611)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user