add test for utils
This commit is contained in:
parent
3186673a2e
commit
453579e347
|
@ -337,6 +337,7 @@ name = "ethers-utils"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ethereum-types 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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 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)",
|
"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)",
|
"tiny-keccak 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -9,3 +9,6 @@ ethereum-types = { version = "0.9.2", default-features = false, features = ["ser
|
||||||
tiny-keccak = { version = "2.0.2", default-features = false }
|
tiny-keccak = { version = "2.0.2", default-features = false }
|
||||||
serde = { version = "1.0.110", default-features = false }
|
serde = { version = "1.0.110", default-features = false }
|
||||||
serde_json = { version = "1.0.53", default-features = false, features = ["alloc"] }
|
serde_json = { version = "1.0.53", default-features = false, features = ["alloc"] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
rustc-hex = "2.1.0"
|
||||||
|
|
|
@ -52,6 +52,16 @@ pub fn serialize<T: serde::Serialize>(t: &T) -> serde_json::Value {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
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:
|
// test vector taken from:
|
||||||
// https://web3js.readthedocs.io/en/v1.2.2/web3-eth-accounts.html#hashmessage
|
// https://web3js.readthedocs.io/en/v1.2.2/web3-eth-accounts.html#hashmessage
|
||||||
|
|
Loading…
Reference in New Issue