Merge rust-bitcoin/rust-bitcoin#4666: Kill new mutants

f0562504b7 Exclude deprecated fn from mutation testing (Jamil Lambert, PhD)
4d31b141a8 Improve is_too_precise test (Jamil Lambert, PhD)
a2bae3bb0b Add test for impl Display for Script (Jamil Lambert, PhD)

Pull request description:

  Weekly mutation testing found new mutants. There are also some untested mutants in match statements that will be included in future mutation testing once #4654 goes in.
  
  - Add a regression test for the mutants in the `Display` impl for `Script`.
  - Improve the existing test for `is_too_precise` to check all four cases.
  - Exclude the two deprecated functions that have untested mutants.
  
  Closes #4646


ACKs for top commit:
  benalleng:
    **tACK** no missed mutants on f056250 I ran with 63b61e9497 rebased in to make sure the match arm and match guard mutations were included
  tcharding:
    ACK f0562504b7


Tree-SHA512: d109e30be91da2ab243a152b9ef17147337328282ac418fa9d2eebd17c2e2d9b6f7ee095d91ccf58e287c9620cb71a090b0d929c9bf35011feb26e6f28457dd3
This commit is contained in:
Andrew Poelstra 2025-07-04 15:12:39 +00:00
commit ca5d136667
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 25 additions and 2 deletions

View File

@ -24,6 +24,8 @@ exclude_re = [
"SignedAmount::checked_abs", # Deprecated "SignedAmount::checked_abs", # Deprecated
"NumberOfBlocks::value", # Deprecated "NumberOfBlocks::value", # Deprecated
"NumberOf512Seconds::to_consensus_u32", # Deprecated "NumberOf512Seconds::to_consensus_u32", # Deprecated
"MedianTimePast::to_consensus_u32", # Deprecated
"Height::to_consensus_u32", # Deprecated
# primitives # 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 "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

View File

@ -802,6 +802,21 @@ mod tests {
assert!(!format!("{:?}", script).is_empty()); assert!(!format!("{:?}", script).is_empty());
} }
#[test]
fn script_display_pushdata() {
// OP_PUSHDATA1
let script = Script::from_bytes(&[0x4c, 0x02, 0xab, 0xcd]);
assert_eq!(format!("{}", script), "OP_PUSHDATA1 abcd");
// OP_PUSHDATA2
let script = Script::from_bytes(&[0x4d, 0x02, 0x00, 0x12, 0x34]);
assert_eq!(format!("{}", script), "OP_PUSHDATA2 1234");
// OP_PUSHDATA4
let script = Script::from_bytes(&[0x4e, 0x02, 0x00, 0x00, 0x00, 0x56, 0x78]);
assert_eq!(format!("{}", script), "OP_PUSHDATA4 5678");
}
#[test] #[test]
fn scriptbuf_display() { fn scriptbuf_display() {
let script_buf = ScriptBuf::from(vec![0x00, 0xa1, 0xb2]); let script_buf = ScriptBuf::from(vec![0x00, 0xa1, 0xb2]);

View File

@ -52,8 +52,14 @@ fn sanity_check() {
#[test] #[test]
fn check_if_num_is_too_precise() { fn check_if_num_is_too_precise() {
assert_eq!(is_too_precise("1234", 3).unwrap(), 3); // Has decimal, not too precise
assert_eq!(is_too_precise("1234.1234", 3).unwrap(), 3); assert_eq!(is_too_precise("1234.5678", 4), Some(0));
// Has decimal, is too precise
assert_eq!(is_too_precise("1234.5678", 3), Some(3));
// No decimal, not too precise
assert_eq!(is_too_precise("1234", 4), Some(0));
// No decimal, is too precise
assert_eq!(is_too_precise("1234", 2), Some(3));
} }
#[test] #[test]