From 1d0e70b1da7037bb997c376f009217c4cd859c29 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 12 Jul 2024 14:00:46 +1000 Subject: [PATCH] Add regression test for Midstate debug output In preparation for patching the `Debug` implementation of `Midstate` and a regression test. --- hashes/src/sha256.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hashes/src/sha256.rs b/hashes/src/sha256.rs index 00c4d66e0..bbc2d27a9 100644 --- a/hashes/src/sha256.rs +++ b/hashes/src/sha256.rs @@ -1008,15 +1008,20 @@ mod tests { } } + // The midstate of an empty hash engine tagged with "TapLeaf". + const TAP_LEAF_MIDSTATE: Midstate = Midstate([ + 156, 224, 228, 230, 124, 17, 108, 57, 56, 179, 202, 242, 195, 15, 80, 137, 211, 243, 147, + 108, 71, 99, 110, 96, 125, 179, 62, 234, 221, 198, 240, 201, + ]); + #[test] - fn const_midstate() { - assert_eq!( - Midstate::hash_tag(b"TapLeaf"), - Midstate([ - 156, 224, 228, 230, 124, 17, 108, 57, 56, 179, 202, 242, 195, 15, 80, 137, 211, - 243, 147, 108, 71, 99, 110, 96, 125, 179, 62, 234, 221, 198, 240, 201, - ]) - ) + fn const_midstate() { assert_eq!(Midstate::hash_tag(b"TapLeaf"), TAP_LEAF_MIDSTATE,) } + + #[test] + fn regression_midstate_debug_format() { + let want = "0xc9f0c6ddea3eb37d606e63476c93f3d389500fc3f2cab338396c117ce6e4e09c"; + let got = format!("{:?}", TAP_LEAF_MIDSTATE); + assert_eq!(got, want); } #[test]