Skip to content

Commit

Permalink
Merge rust-bitcoin#4020: primitives: Add tests to CompactTarget
Browse files Browse the repository at this point in the history
b2d0737 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:
    ACK b2d0737
  apoelstra:
    ACK b2d0737; successfully ran local tests

Tree-SHA512: 8245b2342fabb7142cc0369cc53f4213f8f685dd0ed9d357214b2f692237b3484236462a96315d2c9409625fcf59484fc505674859542311893c23e50da6ffdf
  • Loading branch information
apoelstra committed Feb 7, 2025
2 parents 9aef27a + b2d0737 commit 9aaf6ae
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions primitives/src/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 9aaf6ae

Please sign in to comment.