From b547857d9edc27afb860cef46e459f9496f725f3 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 25 Oct 2026 23:20:36 +0100 Subject: add heads summary test --- src/transport/mod.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src') diff --git a/src/transport/mod.rs b/src/transport/mod.rs index c3db962..35e3499 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -328,3 +328,40 @@ pub trait Transport: Send + Sync { /// Asynchronously monitors for fatal network client or sub-process failures. async fn wait_for_exit(&self) -> std::io::Result; } + +#[cfg(test)] +mod tests { + use super::*; + use crate::testrand::for_seeds; + + /// Two summaries are equal exactly when the heads are, in any order, whichever form + /// (listed or digest) each took. + #[test] + fn heads_summary_equality_is_set_equality() { + for_seeds(300, |rng| { + let n = rng.between(0, 2 * MAX_LISTED_HEADS + 2); + let heads: Vec = (0..n).map(|_| ChangeHash(rng.bytes32())).collect(); + let summary = HeadsSummary::of(heads.clone()); + assert_eq!(summary.heads().is_some(), n <= MAX_LISTED_HEADS); + + let mut shuffled = heads.clone(); + rng.shuffle(&mut shuffled); + assert_eq!(summary, HeadsSummary::of(shuffled)); + assert_eq!(summary, HeadsSummary::Digest(summary.digest())); + + let mut other = heads.clone(); + match rng.below(3) { + 1 if !other.is_empty() => { + let i = rng.below(other.len()); + other.remove(i); + } + 2 if !other.is_empty() => { + let i = rng.below(other.len()); + other[i] = ChangeHash(rng.bytes32()); + } + _ => other.push(ChangeHash(rng.bytes32())), + } + assert_ne!(summary, HeadsSummary::of(other)); + }); + } +} -- cgit v1.3.1