diff --git a/Cargo.lock b/Cargo.lock index 583a1b73..d32f960d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -337,6 +337,7 @@ name = "ethers-utils" version = "0.1.0" dependencies = [ "ethereum-types 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/crates/ethers-utils/Cargo.toml b/crates/ethers-utils/Cargo.toml index bd2c2ee3..7ce132a6 100644 --- a/crates/ethers-utils/Cargo.toml +++ b/crates/ethers-utils/Cargo.toml @@ -9,3 +9,6 @@ ethereum-types = { version = "0.9.2", default-features = false, features = ["ser tiny-keccak = { version = "2.0.2", default-features = false } serde = { version = "1.0.110", default-features = false } serde_json = { version = "1.0.53", default-features = false, features = ["alloc"] } + +[dev-dependencies] +rustc-hex = "2.1.0" diff --git a/crates/ethers-utils/src/lib.rs b/crates/ethers-utils/src/lib.rs index 8af024f1..479c85d7 100644 --- a/crates/ethers-utils/src/lib.rs +++ b/crates/ethers-utils/src/lib.rs @@ -52,6 +52,16 @@ pub fn serialize(t: &T) -> serde_json::Value { #[cfg(test)] mod tests { use super::*; + use rustc_hex::ToHex; + + #[test] + // from https://emn178.github.io/online-tools/keccak_256.html + fn test_keccak256() { + assert_eq!( + keccak256("hello".as_bytes()).to_hex::(), + "1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8" + ); + } // test vector taken from: // https://web3js.readthedocs.io/en/v1.2.2/web3-eth-accounts.html#hashmessage