Skip to content

Commit 2fa5c06

Browse files
committed
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.
1 parent a419fc9 commit 2fa5c06

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

units/src/locktime/absolute.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,4 +607,34 @@ mod tests {
607607
timestamps.reverse();
608608
assert_eq!(MedianTimePast::new(timestamps).unwrap().to_u32(), 500_000_005);
609609
}
610+
611+
#[test]
612+
fn height_is_satisfied_by() {
613+
let chain_tip = Height::from_u32(100).unwrap();
614+
615+
// lock is satisfied if transaction can go in the next block (height <= chain_tip + 1).
616+
let locktime = Height::from_u32(100).unwrap();
617+
assert!(locktime.is_satisfied_by(chain_tip));
618+
let locktime = Height::from_u32(101).unwrap();
619+
assert!(locktime.is_satisfied_by(chain_tip));
620+
621+
// It is not satisfied if the lock height is after the next block.
622+
let locktime = Height::from_u32(102).unwrap();
623+
assert!(!locktime.is_satisfied_by(chain_tip));
624+
}
625+
626+
#[test]
627+
fn median_time_past_is_satisfied_by() {
628+
let mtp = MedianTimePast::from_u32(500_000_001).unwrap();
629+
630+
// lock is satisfied if transaction can go in the next block (locktime <= mtp).
631+
let locktime = MedianTimePast::from_u32(500_000_000).unwrap();
632+
assert!(locktime.is_satisfied_by(mtp));
633+
let locktime = MedianTimePast::from_u32(500_000_001).unwrap();
634+
assert!(locktime.is_satisfied_by(mtp));
635+
636+
// It is not satisfied if the lock time is after the median time past.
637+
let locktime = MedianTimePast::from_u32(500_000_002).unwrap();
638+
assert!(!locktime.is_satisfied_by(mtp));
639+
}
610640
}

0 commit comments

Comments
 (0)