From 1d1cf00b1e8eaff89eba86d4fa6f0dc3e395f2ca Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 26 Mar 2025 09:36:42 +0000 Subject: [PATCH 1/3] Add test to BlockTime to kill mutants Mutants found in weekly mutation testing. Add a test to kill them. --- units/src/time.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/units/src/time.rs b/units/src/time.rs index 41faec706..bd0cdb556 100644 --- a/units/src/time.rs +++ b/units/src/time.rs @@ -56,3 +56,14 @@ impl<'a> Arbitrary<'a> for BlockTime { Ok(BlockTime::from(t)) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn block_time_round_trip() { + let t = BlockTime::from(1_742_979_600); // 26 Mar 2025 9:00 UTC + assert_eq!(u32::from(t), 1_742_979_600); + } +} From 9a2b56f38174ced77ecd139b1c1019dc86f8f062 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 26 Mar 2025 09:48:21 +0000 Subject: [PATCH 2/3] Modify test in Amount to kill mutants Mutants found in weekly mutation testing. Add an assert for both signed and unsigned to an existing test to kill them. --- units/src/amount/tests.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/units/src/amount/tests.rs b/units/src/amount/tests.rs index 127e7566c..f8aba133f 100644 --- a/units/src/amount/tests.rs +++ b/units/src/amount/tests.rs @@ -104,8 +104,13 @@ fn from_str_zero_without_denomination() { fn from_int_btc() { let amt = Amount::from_btc_u16(2); assert_eq!(sat(200_000_000), amt); + let amt = Amount::from_int_btc(2_u16); + assert_eq!(sat(200_000_000), amt); + let amt = SignedAmount::from_btc_i16(-2); assert_eq!(ssat(-200_000_000), amt); + let amt = SignedAmount::from_int_btc(-2_i16); + assert_eq!(ssat(-200_000_000), amt); } #[test] From f15e461baf463da0bf9d89018180c1d5032106c1 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 26 Mar 2025 09:50:50 +0000 Subject: [PATCH 3/3] Add an exclusion for a mutant in a deprecated fn Weekly mutation testing found a mutant in a deprecated function in SignedAmount. Exclude the function from mutation testing. --- .cargo/mutants.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/.cargo/mutants.toml b/.cargo/mutants.toml index 96f373550..f4c71f563 100644 --- a/.cargo/mutants.toml +++ b/.cargo/mutants.toml @@ -21,6 +21,7 @@ exclude_re = [ "Time::to_consensus_u32", # Mutant from replacing | with ^, this returns the same value since the XOR is taken against the u16 with an all-zero bitmask "FeeRate::fee_vb", # Deprecated "FeeRate::fee_wu", # Deprecated + "SignedAmount::checked_abs", # Deprecated # primitives "Sequence::from_512_second_intervals", # Mutant from replacing | with ^, this returns the same value since the XOR is taken against the u16 with an all-zero bitmask