Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from all commits
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
35 changes: 35 additions & 0 deletions substrate/extrinsic-pool/src/rotator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,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);
}
}