Merge rust-bitcoin/rust-bitcoin#4532: units: Kill mutants found in weekly mutation testing
b538a10956
Add deprecated functions to mutants exclude list (Jamil Lambert, PhD)fd0a756344
Add tests to relative locktime (Jamil Lambert, PhD)24cc059a78
Add tests to result (Jamil Lambert, PhD)c1d2f0386d
Add tests to block (Jamil Lambert, PhD) Pull request description: Weekly mutation testing found new mutants. Add tests to kill the valid mutants. Add deprecated functions to the exclude list so they are not mutated. Closes #4488, Closes #4528 ACKs for top commit: apoelstra: ACK b538a1095652f535aeb15f6e3bbc44969db1ea88; successfully ran local tests tcharding: ACKb538a10956
Tree-SHA512: 8393ded6c073b2580fbb0fde9a8ce702a3d1e8c581c035870c2ba6a12d718cee577e345c9d92d0761552765248a6fb5ae9bbacbc88cac75e7153516de46de4ca
This commit is contained in:
commit
855299ab7e
|
@ -23,6 +23,8 @@ exclude_re = [
|
||||||
"FeeRate::fee_vb", # Deprecated
|
"FeeRate::fee_vb", # Deprecated
|
||||||
"FeeRate::fee_wu", # Deprecated
|
"FeeRate::fee_wu", # Deprecated
|
||||||
"SignedAmount::checked_abs", # Deprecated
|
"SignedAmount::checked_abs", # Deprecated
|
||||||
|
"NumberOfBlocks::value", # Deprecated
|
||||||
|
"NumberOf512Seconds::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
|
||||||
|
|
|
@ -439,6 +439,7 @@ impl<'a> core::iter::Sum<&'a BlockMtpInterval> for BlockMtpInterval {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::locktime::relative::NumberOf512Seconds;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sanity_check() {
|
fn sanity_check() {
|
||||||
|
@ -479,6 +480,7 @@ mod tests {
|
||||||
// interval - interval = interval
|
// interval - interval = interval
|
||||||
assert!(BlockHeightInterval(10) - BlockHeightInterval(7) == BlockHeightInterval(3));
|
assert!(BlockHeightInterval(10) - BlockHeightInterval(7) == BlockHeightInterval(3));
|
||||||
|
|
||||||
|
// Sum for BlockHeightInterval by reference and by value
|
||||||
assert!(
|
assert!(
|
||||||
[BlockHeightInterval(1), BlockHeightInterval(2), BlockHeightInterval(3)]
|
[BlockHeightInterval(1), BlockHeightInterval(2), BlockHeightInterval(3)]
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -492,6 +494,20 @@ mod tests {
|
||||||
== BlockHeightInterval(15)
|
== BlockHeightInterval(15)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Sum for BlockMtpInterval by reference and by value
|
||||||
|
assert!(
|
||||||
|
[BlockMtpInterval(1), BlockMtpInterval(2), BlockMtpInterval(3)]
|
||||||
|
.iter()
|
||||||
|
.sum::<BlockMtpInterval>()
|
||||||
|
== BlockMtpInterval(6)
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
[BlockMtpInterval(4), BlockMtpInterval(5), BlockMtpInterval(6)]
|
||||||
|
.into_iter()
|
||||||
|
.sum::<BlockMtpInterval>()
|
||||||
|
== BlockMtpInterval(15)
|
||||||
|
);
|
||||||
|
|
||||||
// interval += interval
|
// interval += interval
|
||||||
let mut int = BlockHeightInterval(1);
|
let mut int = BlockHeightInterval(1);
|
||||||
int += BlockHeightInterval(2);
|
int += BlockHeightInterval(2);
|
||||||
|
@ -502,4 +518,54 @@ mod tests {
|
||||||
int -= BlockHeightInterval(7);
|
int -= BlockHeightInterval(7);
|
||||||
assert_eq!(int, BlockHeightInterval(3));
|
assert_eq!(int, BlockHeightInterval(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_height_checked() {
|
||||||
|
let a = BlockHeight(10);
|
||||||
|
let b = BlockHeight(5);
|
||||||
|
assert_eq!(a.checked_sub(b), Some(BlockHeightInterval(5)));
|
||||||
|
assert_eq!(a.checked_add(BlockHeightInterval(5)), Some(BlockHeight(15)));
|
||||||
|
assert_eq!(a.checked_sub(BlockHeight(11)), None);
|
||||||
|
assert_eq!(a.checked_add(BlockHeightInterval(u32::MAX - 5)), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_height_interval_checked() {
|
||||||
|
let a = BlockHeightInterval(10);
|
||||||
|
let b = BlockHeightInterval(5);
|
||||||
|
assert_eq!(a.checked_sub(b), Some(BlockHeightInterval(5)));
|
||||||
|
assert_eq!(a.checked_add(b), Some(BlockHeightInterval(15)));
|
||||||
|
assert_eq!(a.checked_sub(BlockHeightInterval(11)), None);
|
||||||
|
assert_eq!(a.checked_add(BlockHeightInterval(u32::MAX - 5)), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_mtp_interval_checked() {
|
||||||
|
let a = BlockMtpInterval(10);
|
||||||
|
let b = BlockMtpInterval(5);
|
||||||
|
assert_eq!(a.checked_sub(b), Some(BlockMtpInterval(5)));
|
||||||
|
assert_eq!(a.checked_add(b), Some(BlockMtpInterval(15)));
|
||||||
|
assert_eq!(a.checked_sub(BlockMtpInterval(11)), None);
|
||||||
|
assert_eq!(a.checked_add(BlockMtpInterval(u32::MAX - 5)), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_mtp_checked() {
|
||||||
|
let a = BlockMtp(10);
|
||||||
|
let b = BlockMtp(5);
|
||||||
|
assert_eq!(a.checked_sub(b), Some(BlockMtpInterval(5)));
|
||||||
|
assert_eq!(a.checked_add(BlockMtpInterval(5)), Some(BlockMtp(15)));
|
||||||
|
assert_eq!(a.checked_sub(BlockMtp(11)), None);
|
||||||
|
assert_eq!(a.checked_add(BlockMtpInterval(u32::MAX - 5)), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_mtp_interval_from_number_of_512seconds() {
|
||||||
|
let n = NumberOf512Seconds::from_seconds_floor(0).unwrap();
|
||||||
|
let interval = BlockMtpInterval::from(n);
|
||||||
|
assert_eq!(interval, BlockMtpInterval(0));
|
||||||
|
let n = NumberOf512Seconds::from_seconds_floor(1024).unwrap();
|
||||||
|
let interval = BlockMtpInterval::from(n);
|
||||||
|
assert_eq!(interval, BlockMtpInterval(1024));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,6 +333,7 @@ mod tests {
|
||||||
NumberOf512Seconds::from_512_second_intervals(100).to_consensus_u32(),
|
NumberOf512Seconds::from_512_second_intervals(100).to_consensus_u32(),
|
||||||
4_194_404u32
|
4_194_404u32
|
||||||
); // 0x400064
|
); // 0x400064
|
||||||
|
assert_eq!(NumberOf512Seconds::from_512_second_intervals(1).to_seconds(), 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -310,3 +310,34 @@ impl fmt::Display for MathOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::MathOp;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mathop_predicates() {
|
||||||
|
assert!(MathOp::Add.is_overflow());
|
||||||
|
assert!(MathOp::Sub.is_overflow());
|
||||||
|
assert!(MathOp::Mul.is_overflow());
|
||||||
|
assert!(MathOp::Neg.is_overflow());
|
||||||
|
assert!(!MathOp::Div.is_overflow());
|
||||||
|
assert!(!MathOp::Rem.is_overflow());
|
||||||
|
|
||||||
|
assert!(MathOp::Div.is_div_by_zero());
|
||||||
|
assert!(MathOp::Rem.is_div_by_zero());
|
||||||
|
assert!(!MathOp::Add.is_div_by_zero());
|
||||||
|
|
||||||
|
assert!(MathOp::Add.is_addition());
|
||||||
|
assert!(!MathOp::Sub.is_addition());
|
||||||
|
|
||||||
|
assert!(MathOp::Sub.is_subtraction());
|
||||||
|
assert!(!MathOp::Add.is_subtraction());
|
||||||
|
|
||||||
|
assert!(MathOp::Mul.is_multiplication());
|
||||||
|
assert!(!MathOp::Div.is_multiplication());
|
||||||
|
|
||||||
|
assert!(MathOp::Neg.is_negation());
|
||||||
|
assert!(!MathOp::Add.is_negation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue