Show expanded values in CompactDifficulty debug fmt
This commit is contained in:
parent
207ded6889
commit
2014dffd27
|
@ -63,9 +63,13 @@ pub struct CompactDifficulty(pub(crate) u32);
|
||||||
|
|
||||||
impl fmt::Debug for CompactDifficulty {
|
impl fmt::Debug for CompactDifficulty {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
// There isn't a standard way to represent alternate formats for the
|
||||||
|
// same value.
|
||||||
f.debug_tuple("CompactDifficulty")
|
f.debug_tuple("CompactDifficulty")
|
||||||
// Use hex, because it's a float
|
// Use hex, because it's a float
|
||||||
.field(&format_args!("{:#010x}", self.0))
|
.field(&format_args!("{:#010x}", self.0))
|
||||||
|
// Use expanded difficulty, for bitwise difficulty comparisons
|
||||||
|
.field(&format_args!("{:?}", self.to_expanded()))
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,15 +19,29 @@ fn debug_format() {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{:?}", CompactDifficulty(0)),
|
format!("{:?}", CompactDifficulty(0)),
|
||||||
"CompactDifficulty(0x00000000)"
|
"CompactDifficulty(0x00000000, None)"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{:?}", CompactDifficulty(1)),
|
format!("{:?}", CompactDifficulty(1)),
|
||||||
"CompactDifficulty(0x00000001)"
|
"CompactDifficulty(0x00000001, None)"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{:?}", CompactDifficulty(u32::MAX)),
|
format!("{:?}", CompactDifficulty(u32::MAX)),
|
||||||
"CompactDifficulty(0xffffffff)"
|
"CompactDifficulty(0xffffffff, None)"
|
||||||
|
);
|
||||||
|
let one = CompactDifficulty((1 << PRECISION) + (1 << 16));
|
||||||
|
assert_eq!(
|
||||||
|
format!("{:?}", one),
|
||||||
|
"CompactDifficulty(0x01010000, Some(ExpandedDifficulty(\"0000000000000000000000000000000000000000000000000000000000000001\")))");
|
||||||
|
let mant = CompactDifficulty(OFFSET as u32 * (1 << PRECISION) + UNSIGNED_MANTISSA_MASK);
|
||||||
|
assert_eq!(
|
||||||
|
format!("{:?}", mant),
|
||||||
|
"CompactDifficulty(0x037fffff, Some(ExpandedDifficulty(\"00000000000000000000000000000000000000000000000000000000007fffff\")))"
|
||||||
|
);
|
||||||
|
let exp = CompactDifficulty(((31 + OFFSET - 2) as u32) * (1 << PRECISION) + (1 << 16));
|
||||||
|
assert_eq!(
|
||||||
|
format!("{:?}", exp),
|
||||||
|
"CompactDifficulty(0x20010000, Some(ExpandedDifficulty(\"0100000000000000000000000000000000000000000000000000000000000000\")))"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in New Issue