diff --git a/crates/voelin-core/src/ts/identity.rs b/crates/voelin-core/src/ts/identity.rs index b517a1b..8adbd9f 100644 --- a/crates/voelin-core/src/ts/identity.rs +++ b/crates/voelin-core/src/ts/identity.rs @@ -672,15 +672,19 @@ mod tests { #[test] fn improve_level_keeps_the_key() { let identity = synthetic(); + // A fresh identity stops at the first counter whose level is 8 or more, + // and about one in 32 has 13 or more already, which `improve_level` + // returns as it is: ask for more than this one has, whatever it has. + let target = identity.level() + 3; let levels = std::sync::Mutex::new(Vec::new()); - let better = improve_level(&identity, 13, &AtomicBool::new(false), |l| { + let better = improve_level(&identity, target, &AtomicBool::new(false), |l| { levels.lock().unwrap().push(l); }) .unwrap(); - assert!(better.level() >= 13); + assert!(better.level() >= target); assert_eq!(better.key().to_pub().get_uid(), identity.key().to_pub().get_uid()); assert!(better.counter() > identity.counter()); - assert!(levels.into_inner().unwrap().iter().any(|l| *l >= 13)); + assert!(levels.into_inner().unwrap().iter().any(|l| *l >= target)); // Cancelled: nothing. assert!(improve_level(&identity, 60, &AtomicBool::new(true), |_| {}).is_none()); // Already there: the same identity.