From 6a2ca885365799f4214d7b64f286240e9b872721 Mon Sep 17 00:00:00 2001 From: Niklas Adofsson Date: Wed, 22 Aug 2018 18:03:06 +0200 Subject: [PATCH 1/3] fix `ethbloom test` by falling back to rustc-hex --- ethbloom/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 5df4aac..81c49b7 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -17,7 +17,7 @@ serde = { version = "1.0", optional = true } [dev-dependencies] rand = { version = "0.4" } -rustc-hex = "2.0" +rustc-hex = "1.0.0" [features] default = ["std", "heapsizeof", "serialize", "fixed-hash/libc"] From 0d1133ef75a1b6271847d25a1af2119a32f35cd0 Mon Sep 17 00:00:00 2001 From: Niklas Adofsson Date: Thu, 23 Aug 2018 11:53:30 +0200 Subject: [PATCH 2/3] Use `rustc-hex v2.0` with explicit types The issue was that the trait `FromHex` has changed and is now using `FromIterator` instead of `FromIterator>` and was `inferred` to `[u8]` instead of `Vec`. Thus, has not compile-time size and won't work! Well, this could be improved to be stack allocated because we know the `size` of the hexstring but in this case I think is sufficient and only used in tests! --- ethbloom/Cargo.toml | 2 +- ethbloom/src/lib.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 81c49b7..5df4aac 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -17,7 +17,7 @@ serde = { version = "1.0", optional = true } [dev-dependencies] rand = { version = "0.4" } -rustc-hex = "1.0.0" +rustc-hex = "2.0" [features] default = ["std", "heapsizeof", "serialize", "fixed-hash/libc"] diff --git a/ethbloom/src/lib.rs b/ethbloom/src/lib.rs index 78a8d77..8c59623 100644 --- a/ethbloom/src/lib.rs +++ b/ethbloom/src/lib.rs @@ -7,8 +7,8 @@ //! //! fn main() { //! let bloom: Bloom = "00000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002020000000000000000000000000000000000000000000008000000001000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into(); -//! let address = "ef2d6d194084c2de36e0dabfce45d046b37d1106".from_hex().unwrap(); -//! let topic = "02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc".from_hex().unwrap(); +//! let address: Vec = "ef2d6d194084c2de36e0dabfce45d046b37d1106".from_hex().unwrap(); +//! let topic: Vec = "02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc".from_hex().unwrap(); //! //! let mut my_bloom = Bloom::default(); //! assert!(!my_bloom.contains_input(Input::Raw(&address))); @@ -261,8 +261,8 @@ mod tests { #[test] fn it_works() { let bloom: Bloom = "00000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002020000000000000000000000000000000000000000000008000000001000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into(); - let address = "ef2d6d194084c2de36e0dabfce45d046b37d1106".from_hex().unwrap(); - let topic = "02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc".from_hex().unwrap(); + let address: Vec = "ef2d6d194084c2de36e0dabfce45d046b37d1106".from_hex().unwrap(); + let topic: Vec = "02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc".from_hex().unwrap(); let mut my_bloom = Bloom::default(); assert!(!my_bloom.contains_input(Input::Raw(&address))); From f84cc4a180c7b22e0c1c6988f77786ccc7b7587d Mon Sep 17 00:00:00 2001 From: Niklas Adofsson Date: Thu, 23 Aug 2018 13:18:42 +0200 Subject: [PATCH 3/3] Replace `rustc-hex` with `hex-literal` in tests --- ethbloom/Cargo.toml | 2 +- ethbloom/src/lib.rs | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 5df4aac..8248869 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -17,7 +17,7 @@ serde = { version = "1.0", optional = true } [dev-dependencies] rand = { version = "0.4" } -rustc-hex = "2.0" +hex-literal = "0.1.1" [features] default = ["std", "heapsizeof", "serialize", "fixed-hash/libc"] diff --git a/ethbloom/src/lib.rs b/ethbloom/src/lib.rs index 8c59623..462551c 100644 --- a/ethbloom/src/lib.rs +++ b/ethbloom/src/lib.rs @@ -1,14 +1,13 @@ //! //! ```rust //! extern crate ethbloom; -//! extern crate rustc_hex; -//! use rustc_hex::FromHex; +//! #[macro_use] extern crate hex_literal; //! use ethbloom::{Bloom, Input}; //! //! fn main() { //! let bloom: Bloom = "00000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002020000000000000000000000000000000000000000000008000000001000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into(); -//! let address: Vec = "ef2d6d194084c2de36e0dabfce45d046b37d1106".from_hex().unwrap(); -//! let topic: Vec = "02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc".from_hex().unwrap(); +//! let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106"); +//! let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc"); //! //! let mut my_bloom = Bloom::default(); //! assert!(!my_bloom.contains_input(Input::Raw(&address))); @@ -44,6 +43,10 @@ extern crate ethereum_types_serialize; #[cfg(feature="serialize")] extern crate serde; +#[cfg(test)] +#[macro_use] +extern crate hex_literal; + #[cfg(feature="serialize")] use serde::{Serialize, Serializer, Deserialize, Deserializer}; @@ -254,15 +257,13 @@ impl<'de> Deserialize<'de> for Bloom { #[cfg(test)] mod tests { - extern crate rustc_hex; - use self::rustc_hex::FromHex; use {Bloom, Input}; #[test] fn it_works() { let bloom: Bloom = "00000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002020000000000000000000000000000000000000000000008000000001000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into(); - let address: Vec = "ef2d6d194084c2de36e0dabfce45d046b37d1106".from_hex().unwrap(); - let topic: Vec = "02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc".from_hex().unwrap(); + let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106"); + let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc"); let mut my_bloom = Bloom::default(); assert!(!my_bloom.contains_input(Input::Raw(&address)));