Merge rust-bitcoin/rust-bitcoin#4593: units: Add `is_satisfied_by` locktime tests

2fa5c062d5 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 #4587

ACKs for top commit:
  tcharding:
    ACK 2fa5c062d5
  apoelstra:
    ACK 2fa5c062d5e07580bdb7ea5e4c58e4607c716ecc; successfully ran local tests

Tree-SHA512: 28d69cdf575bb17eff6d685b1fee05e3f9a821c8796c82655b2d2eda6ee1d9dc79043853fbe0475f6bdb548cef52ac710b3c632f7784788035392e29e70ce48e
This commit is contained in:
merge-script 2025-06-06 18:25:58 +00:00
commit a1be2fdf73
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 30 additions and 0 deletions

View File

@ -547,4 +547,34 @@ mod tests {
timestamps.reverse(); timestamps.reverse();
assert_eq!(MedianTimePast::new(timestamps).unwrap().to_u32(), 500_000_005); 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));
}
} }