Merge rust-bitcoin/rust-bitcoin#4631: Add tests to kill mutants

ef56baa696 Improve fee_rate test to kill a mutant (Jamil Lambert, PhD)
5edcc5dad4 Remove repeated fee_rate test (Jamil Lambert, PhD)
bd50943234 Add a roundtrip test to kill a mutant (Jamil Lambert, PhD)
0b4b17307d Test SignedAmount edge case to kill mutant (Jamil Lambert, PhD)
f3338655f1 Test OutPoint edge case to kill mutant (Jamil Lambert, PhD)

Pull request description:

  Weekly mutation testing found new mutants in units and primitives.
  
  - Add tests or improve existing tests to kill all of the mutants. 
  - Remove a duplicate test in `fee_rate`
  
  Closes #4601, Closes #4622


ACKs for top commit:
  tcharding:
    ACK ef56baa696
  apoelstra:
    ACK ef56baa69670f9c2e453cb981d6f3488247d000c; successfully ran local tests


Tree-SHA512: b5301ae76e6b1d94831054d348d7eb544ab052178a1ce362cff2e6876fd4eb243c842d158e7d174b7ec4700083367ed0e3c6f6d8e1f6c0a4c888d5bb3205f72f
This commit is contained in:
Andrew Poelstra 2025-06-22 13:23:06 +00:00
commit 7af15ab676
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
4 changed files with 32 additions and 10 deletions

View File

@ -729,9 +729,20 @@ mod tests {
// Check the number of bytes OutPoint contributes to the transaction is equal to SIZE
let outpoint_size = outpoint.txid.as_byte_array().len() + outpoint.vout.to_le_bytes().len();
assert_eq!(outpoint_size, OutPoint::SIZE);
}
// Check TooLong error
outpoint_str.push_str("0000000000");
#[test]
#[cfg(feature = "hex")]
fn outpoint_from_str_too_long() {
// Check edge case: length exactly 75
let mut outpoint_str = "0".repeat(64);
outpoint_str.push_str(":1234567890");
assert_eq!(outpoint_str.len(), 75);
assert!(outpoint_str.parse::<OutPoint>().is_ok());
// Check TooLong error (length 76)
outpoint_str.push('0');
assert_eq!(outpoint_str.len(), 76);
let outpoint: Result<OutPoint, ParseOutPointError> = outpoint_str.parse();
assert_eq!(outpoint, Err(ParseOutPointError::TooLong));
}

View File

@ -256,6 +256,7 @@ fn checked_arithmetic() {
#[test]
fn positive_sub() {
assert_eq!(ssat(10).positive_sub(ssat(7)).unwrap(), ssat(3));
assert_eq!(ssat(10).positive_sub(ssat(10)).unwrap(), ssat(0));
assert!(ssat(-10).positive_sub(ssat(7)).is_none());
assert!(ssat(10).positive_sub(ssat(-7)).is_none());
assert!(ssat(10).positive_sub(ssat(11)).is_none());

View File

@ -384,17 +384,20 @@ mod tests {
}
#[test]
fn from_sat_per_vb() {
let fee_rate = FeeRate::from_sat_per_vb(10);
assert_eq!(fee_rate, FeeRate::from_sat_per_kwu(2500));
}
fn fee_rate_to_sat_per_x() {
let fee_rate = FeeRate::from_sat_per_mvb(2_000_400);
#[test]
fn raw_feerate() {
let fee_rate = FeeRate::from_sat_per_kwu(749);
assert_eq!(fee_rate.to_sat_per_kwu_floor(), 749);
// sat/kwu: 2_000_400 / 4_000 = 500.1
assert_eq!(fee_rate.to_sat_per_kwu_floor(), 500);
assert_eq!(fee_rate.to_sat_per_kwu_ceil(), 501);
// sat/vB: 2_000_400 / 1_000_000 = 2.0004
assert_eq!(fee_rate.to_sat_per_vb_floor(), 2);
assert_eq!(fee_rate.to_sat_per_vb_ceil(), 3);
// sat/kvb: 2_000_400 / 1_000 = 2_000.4
assert_eq!(fee_rate.to_sat_per_kvb_floor(), 2_000);
assert_eq!(fee_rate.to_sat_per_kvb_ceil(), 2_001);
}
#[test]

View File

@ -307,6 +307,13 @@ mod tests {
assert_eq!(NumberOf512Seconds::from_512_second_intervals(1).to_seconds(), 512);
}
#[test]
fn from_512_second_intervals_roundtrip() {
let intervals = 100_u16;
let locktime = NumberOf512Seconds::from_512_second_intervals(intervals);
assert_eq!(locktime.to_512_second_intervals(), intervals);
}
#[test]
fn from_seconds_ceil_success() {
let actual = NumberOf512Seconds::from_seconds_ceil(100).unwrap();