Skip to content

Commit 7af15ab

Browse files
committed
Merge rust-bitcoin#4631: Add tests to kill mutants
ef56baa Improve fee_rate test to kill a mutant (Jamil Lambert, PhD) 5edcc5d Remove repeated fee_rate test (Jamil Lambert, PhD) bd50943 Add a roundtrip test to kill a mutant (Jamil Lambert, PhD) 0b4b173 Test SignedAmount edge case to kill mutant (Jamil Lambert, PhD) f333865 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 rust-bitcoin#4601, Closes rust-bitcoin#4622 ACKs for top commit: tcharding: ACK ef56baa apoelstra: ACK ef56baa; successfully ran local tests Tree-SHA512: b5301ae76e6b1d94831054d348d7eb544ab052178a1ce362cff2e6876fd4eb243c842d158e7d174b7ec4700083367ed0e3c6f6d8e1f6c0a4c888d5bb3205f72f
2 parents 51f78bb + ef56baa commit 7af15ab

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

primitives/src/transaction.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,20 @@ mod tests {
729729
// Check the number of bytes OutPoint contributes to the transaction is equal to SIZE
730730
let outpoint_size = outpoint.txid.as_byte_array().len() + outpoint.vout.to_le_bytes().len();
731731
assert_eq!(outpoint_size, OutPoint::SIZE);
732+
}
732733

733-
// Check TooLong error
734-
outpoint_str.push_str("0000000000");
734+
#[test]
735+
#[cfg(feature = "hex")]
736+
fn outpoint_from_str_too_long() {
737+
// Check edge case: length exactly 75
738+
let mut outpoint_str = "0".repeat(64);
739+
outpoint_str.push_str(":1234567890");
740+
assert_eq!(outpoint_str.len(), 75);
741+
assert!(outpoint_str.parse::<OutPoint>().is_ok());
742+
743+
// Check TooLong error (length 76)
744+
outpoint_str.push('0');
745+
assert_eq!(outpoint_str.len(), 76);
735746
let outpoint: Result<OutPoint, ParseOutPointError> = outpoint_str.parse();
736747
assert_eq!(outpoint, Err(ParseOutPointError::TooLong));
737748
}

units/src/amount/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ fn checked_arithmetic() {
256256
#[test]
257257
fn positive_sub() {
258258
assert_eq!(ssat(10).positive_sub(ssat(7)).unwrap(), ssat(3));
259+
assert_eq!(ssat(10).positive_sub(ssat(10)).unwrap(), ssat(0));
259260
assert!(ssat(-10).positive_sub(ssat(7)).is_none());
260261
assert!(ssat(10).positive_sub(ssat(-7)).is_none());
261262
assert!(ssat(10).positive_sub(ssat(11)).is_none());

units/src/fee_rate/mod.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,17 +384,20 @@ mod tests {
384384
}
385385

386386
#[test]
387-
fn from_sat_per_vb() {
388-
let fee_rate = FeeRate::from_sat_per_vb(10);
389-
assert_eq!(fee_rate, FeeRate::from_sat_per_kwu(2500));
390-
}
387+
fn fee_rate_to_sat_per_x() {
388+
let fee_rate = FeeRate::from_sat_per_mvb(2_000_400);
391389

392-
#[test]
393-
fn raw_feerate() {
394-
let fee_rate = FeeRate::from_sat_per_kwu(749);
395-
assert_eq!(fee_rate.to_sat_per_kwu_floor(), 749);
390+
// sat/kwu: 2_000_400 / 4_000 = 500.1
391+
assert_eq!(fee_rate.to_sat_per_kwu_floor(), 500);
392+
assert_eq!(fee_rate.to_sat_per_kwu_ceil(), 501);
393+
394+
// sat/vB: 2_000_400 / 1_000_000 = 2.0004
396395
assert_eq!(fee_rate.to_sat_per_vb_floor(), 2);
397396
assert_eq!(fee_rate.to_sat_per_vb_ceil(), 3);
397+
398+
// sat/kvb: 2_000_400 / 1_000 = 2_000.4
399+
assert_eq!(fee_rate.to_sat_per_kvb_floor(), 2_000);
400+
assert_eq!(fee_rate.to_sat_per_kvb_ceil(), 2_001);
398401
}
399402

400403
#[test]

units/src/locktime/relative.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ mod tests {
307307
assert_eq!(NumberOf512Seconds::from_512_second_intervals(1).to_seconds(), 512);
308308
}
309309

310+
#[test]
311+
fn from_512_second_intervals_roundtrip() {
312+
let intervals = 100_u16;
313+
let locktime = NumberOf512Seconds::from_512_second_intervals(intervals);
314+
assert_eq!(locktime.to_512_second_intervals(), intervals);
315+
}
316+
310317
#[test]
311318
fn from_seconds_ceil_success() {
312319
let actual = NumberOf512Seconds::from_seconds_ceil(100).unwrap();

0 commit comments

Comments
 (0)