Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Dec 28, 2023
1 parent 4cc9237 commit 7fdad48
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions crates/primitives/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,23 @@ mod tests {

#[test]
fn keccak256_hasher() {
let expected = b256!("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad");
assert_eq!(keccak256("hello world"), expected);

let mut hasher = Keccak256::new();
hasher.update(b"hello");
hasher.update(b" world");

let mut hash = [0u8; 32];
hasher.clone().finalize_into(&mut hash);
assert_eq!(hash, expected);

let mut hash = [0u8; 32];
hasher.clone().finalize_into_array(&mut hash);
assert_eq!(hash, expected);

let mut hash = [0u8; 32];
hasher.finalize_into(&mut hash);
assert_eq!(hash, b256!("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"));
assert_eq!(hash, keccak256("hello world"));
unsafe { hasher.finalize_into_raw(hash.as_mut_ptr()) };
assert_eq!(hash, expected);
}
}

0 comments on commit 7fdad48

Please sign in to comment.