From 58503ee01d64f5958172bd26511ebb7c67d6129f Mon Sep 17 00:00:00 2001 From: Hein Dauven Date: Sat, 10 Oct 2026 14:02:04 +0200 Subject: [PATCH] Add tests for the gaps found by mutation testing Mutation testing of dusk-safe 0.4.0 found code that no test pins. Each test below fails on the mutant it targets: - Test that dropping a sponge wipes its output - Test the IO-pattern call length bound --- src/lib.rs | 17 +++++++++++++++++ src/sponge.rs | 15 +++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 1f4931b..e906aa9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -281,6 +281,23 @@ mod tests { assert!(validate_io_pattern(&iopattern).is_err()); } + #[test] + fn io_pattern_length_bound() { + const MAX: usize = (1 << 31) - 1; + assert!( + validate_io_pattern([Call::Absorb(MAX), Call::Squeeze(MAX)]) + .is_ok() + ); + assert!( + validate_io_pattern([Call::Absorb(MAX + 1), Call::Squeeze(1)]) + .is_err() + ); + assert!( + validate_io_pattern([Call::Absorb(1), Call::Squeeze(MAX + 1)]) + .is_err() + ); + } + #[test] fn test_tag_input() -> Result<(), Error> { let domain_sep = 42; diff --git a/src/sponge.rs b/src/sponge.rs index db4e1f2..d57d91a 100644 --- a/src/sponge.rs +++ b/src/sponge.rs @@ -479,6 +479,21 @@ mod storage_tests { } } #[test] + fn drop_wipes_buffered_output() { + let mut sponge = Sponge::start( + Identity, + vec![Call::Absorb(1), Call::Squeeze(1), Call::Squeeze(1)], + 0, + ) + .unwrap(); + sponge.absorb(1, [99]).unwrap(); + sponge.squeeze(1).unwrap(); + watch(&sponge.output[0]); + // A sponge dropped before `finish` still holds its output. + drop(sponge); + assert!(WIPED.get(), "buffered output must be wiped on drop"); + } + #[test] fn allocation_failure_is_terminal() { for buffered in [false, true] { let mut sponge = Sponge::start(