Skip to content

Commit

Permalink
Make ExpandedDifficulty Debug byte order match Hash
Browse files Browse the repository at this point in the history
Bugfix on PR ZcashFoundation#1171.
  • Loading branch information
teor2345 committed Nov 10, 2020
1 parent a0bbca4 commit 070db09
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion zebra-chain/src/work/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl fmt::Debug for ExpandedDifficulty {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut buf = [0; 32];
// Use the same byte order as block::Hash
self.0.to_little_endian(&mut buf);
self.0.to_big_endian(&mut buf);
f.debug_tuple("ExpandedDifficulty")
.field(&hex::encode(&buf))
.finish()
Expand Down
3 changes: 2 additions & 1 deletion zebra-chain/src/work/difficulty/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ fn debug_format() {
);
assert_eq!(
format!("{:?}", ExpandedDifficulty(U256::one())),
"ExpandedDifficulty(\"0100000000000000000000000000000000000000000000000000000000000000\")"
"ExpandedDifficulty(\"0000000000000000000000000000000000000000000000000000000000000001\")"
);
assert_eq!(
format!("{:?}", ExpandedDifficulty(U256::MAX)),
"ExpandedDifficulty(\"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\")"
);

assert_eq!(format!("{:?}", Work(0)), "Work(0x0, 0, -inf)");
assert_eq!(format!("{:?}", Work(1)), "Work(0x1, 1, 0.00000)");
assert_eq!(
format!("{:?}", Work(u8::MAX as u128)),
"Work(0xff, 255, 7.99435)"
Expand Down

0 comments on commit 070db09

Please sign in to comment.