add test for utils

This commit is contained in:
Georgios Konstantopoulos 2020-05-28 00:03:15 +03:00
parent 3186673a2e
commit 453579e347
No known key found for this signature in database
GPG Key ID: FA607837CD26EDBC
3 changed files with 14 additions and 0 deletions

1
Cargo.lock generated
View File

@ -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)",

View File

@ -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"

View File

@ -52,6 +52,16 @@ pub fn serialize<T: serde::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::<String>(),
"1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
);
}
// test vector taken from:
// https://web3js.readthedocs.io/en/v1.2.2/web3-eth-accounts.html#hashmessage