Merge rust-bitcoin/rust-bitcoin#4020: primitives: Add tests to CompactTarget
b2d0737acc
Add tests to CompactTarget (Jamil Lambert, PhD) Pull request description: Add tests to pow.rs to kill the mutants found in CompactTarget. ACKs for top commit: tcharding: ACKb2d0737acc
apoelstra: ACK b2d0737accb998071e0f19cda6f988956b6c097a; successfully ran local tests Tree-SHA512: 8245b2342fabb7142cc0369cc53f4213f8f685dd0ed9d357214b2f692237b3484236462a96315d2c9409625fcf59484fc505674859542311893c23e50da6ffdf
This commit is contained in:
commit
9aaf6ae358
|
@ -43,3 +43,26 @@ impl fmt::UpperHex for CompactTarget {
|
|||
#[inline]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::UpperHex::fmt(&self.0, f) }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn compact_target_ordering() {
|
||||
let lower = CompactTarget::from_consensus(0x1d00fffe);
|
||||
let lower_copy = CompactTarget::from_consensus(0x1d00fffe);
|
||||
let higher = CompactTarget::from_consensus(0x1d00ffff);
|
||||
|
||||
assert!(lower < higher);
|
||||
assert!(lower == lower_copy);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compact_target_formatting() {
|
||||
let compact_target = CompactTarget::from_consensus(0x1d00ffff);
|
||||
assert_eq!(format!("{:x}", compact_target), "1d00ffff");
|
||||
assert_eq!(format!("{:X}", compact_target), "1D00FFFF");
|
||||
assert_eq!(compact_target.to_consensus(), 0x1d00ffff);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue