Skip to content

Commit a1be2fd

Browse files
committed
Merge rust-bitcoin#4593: units: Add is_satisfied_by locktime tests
2fa5c06 Add is_satisfied_by locktime tests (Jamil Lambert, PhD) Pull request description: Weekly mutation testing found new mutants in both `Height::is_satisfied_by` and `MedianTimePast::is_satisfied_by` functions. Test these two functions and kill the mutants. Closes rust-bitcoin#4587 ACKs for top commit: tcharding: ACK 2fa5c06 apoelstra: ACK 2fa5c06; successfully ran local tests Tree-SHA512: 28d69cdf575bb17eff6d685b1fee05e3f9a821c8796c82655b2d2eda6ee1d9dc79043853fbe0475f6bdb548cef52ac710b3c632f7784788035392e29e70ce48e
2 parents 9d586a9 + 2fa5c06 commit a1be2fd

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
@@ -547,4 +547,34 @@ mod tests {
547547
timestamps.reverse();
548548
assert_eq!(MedianTimePast::new(timestamps).unwrap().to_u32(), 500_000_005);
549549
}
550+
551+
#[test]
552+
fn height_is_satisfied_by() {
553+
let chain_tip = Height::from_u32(100).unwrap();
554+
555+
// lock is satisfied if transaction can go in the next block (height <= chain_tip + 1).
556+
let locktime = Height::from_u32(100).unwrap();
557+
assert!(locktime.is_satisfied_by(chain_tip));
558+
let locktime = Height::from_u32(101).unwrap();
559+
assert!(locktime.is_satisfied_by(chain_tip));
560+
561+
// It is not satisfied if the lock height is after the next block.
562+
let locktime = Height::from_u32(102).unwrap();
563+
assert!(!locktime.is_satisfied_by(chain_tip));
564+
}
565+
566+
#[test]
567+
fn median_time_past_is_satisfied_by() {
568+
let mtp = MedianTimePast::from_u32(500_000_001).unwrap();
569+
570+
// lock is satisfied if transaction can go in the next block (locktime <= mtp).
571+
let locktime = MedianTimePast::from_u32(500_000_000).unwrap();
572+
assert!(locktime.is_satisfied_by(mtp));
573+
let locktime = MedianTimePast::from_u32(500_000_001).unwrap();
574+
assert!(locktime.is_satisfied_by(mtp));
575+
576+
// It is not satisfied if the lock time is after the median time past.
577+
let locktime = MedianTimePast::from_u32(500_000_002).unwrap();
578+
assert!(!locktime.is_satisfied_by(mtp));
579+
}
550580
}

0 commit comments

Comments
 (0)