From 2fa5c062d5e07580bdb7ea5e4c58e4607c716ecc Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 4 Jun 2025 17:34:15 +0100 Subject: [PATCH] Add is_satisfied_by locktime tests Weekly mutation testing found new mutants in both height and median time past `is_satisfied_by` functions. Test these two functions and kill the mutants. --- units/src/locktime/absolute.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/units/src/locktime/absolute.rs b/units/src/locktime/absolute.rs index c0e2b8417..0c202c915 100644 --- a/units/src/locktime/absolute.rs +++ b/units/src/locktime/absolute.rs @@ -607,4 +607,34 @@ mod tests { timestamps.reverse(); assert_eq!(MedianTimePast::new(timestamps).unwrap().to_u32(), 500_000_005); } + + #[test] + fn height_is_satisfied_by() { + let chain_tip = Height::from_u32(100).unwrap(); + + // lock is satisfied if transaction can go in the next block (height <= chain_tip + 1). + let locktime = Height::from_u32(100).unwrap(); + assert!(locktime.is_satisfied_by(chain_tip)); + let locktime = Height::from_u32(101).unwrap(); + assert!(locktime.is_satisfied_by(chain_tip)); + + // It is not satisfied if the lock height is after the next block. + let locktime = Height::from_u32(102).unwrap(); + assert!(!locktime.is_satisfied_by(chain_tip)); + } + + #[test] + fn median_time_past_is_satisfied_by() { + let mtp = MedianTimePast::from_u32(500_000_001).unwrap(); + + // lock is satisfied if transaction can go in the next block (locktime <= mtp). + let locktime = MedianTimePast::from_u32(500_000_000).unwrap(); + assert!(locktime.is_satisfied_by(mtp)); + let locktime = MedianTimePast::from_u32(500_000_001).unwrap(); + assert!(locktime.is_satisfied_by(mtp)); + + // It is not satisfied if the lock time is after the median time past. + let locktime = MedianTimePast::from_u32(500_000_002).unwrap(); + assert!(!locktime.is_satisfied_by(mtp)); + } }