Refactor tagged hash tests
In the tagged hash unit tests we are testing two separate things in a single test. To improve maintainability separate the test into two. Refactor only, no test coverage change.
This commit is contained in:
parent
216422dffc
commit
9aee65d1ba
|
@ -174,6 +174,10 @@ mod tests {
|
||||||
108, 71, 99, 110, 96, 125, 179, 62, 234, 221, 198, 240, 201,
|
108, 71, 99, 110, 96, 125, 179, 62, 234, 221, 198, 240, 201,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// The digest created by sha256 hashing `&[0]` starting with `TEST_MIDSTATE`.
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
|
const HASH_ZERO: &str = "29589d5122ec666ab5b4695070b6debc63881a4f85d88d93ddc90078038213ed";
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
|
||||||
pub struct TestHashTag;
|
pub struct TestHashTag;
|
||||||
|
|
||||||
|
@ -185,10 +189,17 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A hash tagged with `$name`.
|
// We support manually implementing `Tag` and creating a tagged hash from it.
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
pub type TestHash = sha256t::Hash<TestHashTag>;
|
pub type TestHash = sha256t::Hash<TestHashTag>;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
|
fn manually_created_sha256t_hash_type() {
|
||||||
|
assert_eq!(TestHash::hash(&[0]).to_string(), HASH_ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We also provide a macro to create the tag and the hash type.
|
||||||
sha256t_hash_newtype! {
|
sha256t_hash_newtype! {
|
||||||
/// Test detailed explanation.
|
/// Test detailed explanation.
|
||||||
struct NewTypeTag = raw(TEST_MIDSTATE, 64);
|
struct NewTypeTag = raw(TEST_MIDSTATE, 64);
|
||||||
|
@ -200,14 +211,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
fn test_sha256t() {
|
fn macro_created_sha256t_hash_type() {
|
||||||
assert_eq!(
|
assert_eq!(NewTypeHash::hash(&[0]).to_string(), HASH_ZERO);
|
||||||
TestHash::hash(&[0]).to_string(),
|
|
||||||
"29589d5122ec666ab5b4695070b6debc63881a4f85d88d93ddc90078038213ed"
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
NewTypeHash::hash(&[0]).to_string(),
|
|
||||||
"29589d5122ec666ab5b4695070b6debc63881a4f85d88d93ddc90078038213ed"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue