diff --git a/Cargo.lock b/Cargo.lock index ff4c277e53f..ff3bd4d4a8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -896,13 +896,13 @@ dependencies = [ "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "ethkey 0.3.0", + "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "macros 0.1.0", "num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-crypto 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1264,6 +1264,7 @@ name = "ethjson" version = "0.1.0" dependencies = [ "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "macros 0.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ethcore/builtin/Cargo.toml b/ethcore/builtin/Cargo.toml index 086ed47bb98..d3ca27a6298 100644 --- a/ethcore/builtin/Cargo.toml +++ b/ethcore/builtin/Cargo.toml @@ -20,4 +20,4 @@ parity-bytes = "0.1" parity-crypto = "0.4.0" [dev-dependencies] -rustc-hex = "1.0" +hex-literal = "0.2.1" diff --git a/ethcore/builtin/src/lib.rs b/ethcore/builtin/src/lib.rs index 1e226be8cf9..3546e7d2453 100644 --- a/ethcore/builtin/src/lib.rs +++ b/ethcore/builtin/src/lib.rs @@ -58,12 +58,12 @@ pub type Blake2FPricer = u64; impl Pricer for Blake2FPricer { fn cost(&self, input: &[u8]) -> U256 { const FOUR: usize = std::mem::size_of::(); - let (rounds_bytes, _) = input.split_at(std::mem::size_of::()); // Returning zero if the conversion fails is fine because `execute()` will check the length // and bail with the appropriate error. if input.len() < FOUR { return U256::zero(); } + let (rounds_bytes, _) = input.split_at(FOUR); let rounds = u32::from_be_bytes(rounds_bytes.try_into().unwrap_or([0u8; 4])); U256::from(*self as u64 * rounds as u64) } @@ -743,6 +743,7 @@ impl Bn128Pairing { #[cfg(test)] mod tests { + use std::convert::TryFrom; use ethereum_types::U256; use ethjson::spec::builtin::{ Builtin as JsonBuiltin, Linear as JsonLinearPricing, @@ -751,7 +752,6 @@ mod tests { use hex_literal::hex; use macros::map; use num::{BigUint, Zero, One}; - use hex_literal::hex; use parity_bytes::BytesRef; use super::{ BTreeMap, Builtin, EthereumBuiltin, FromStr, Implementation, Linear, @@ -793,7 +793,7 @@ mod tests { let result = blake2.execute(&input[..], &mut BytesRef::Fixed(&mut out[..])); assert!(result.is_err()); - assert_eq!(result.unwrap_err(), "input length for Blake2 F precompile should be exactly 213 bytes".into()); + assert_eq!(result.unwrap_err(), "input length for Blake2 F precompile should be exactly 213 bytes"); } #[test] @@ -805,7 +805,7 @@ mod tests { let result = blake2.execute(&input[..], &mut BytesRef::Fixed(&mut out[..])); assert!(result.is_err()); - assert_eq!(result.unwrap_err(), "input length for Blake2 F precompile should be exactly 213 bytes".into()); + assert_eq!(result.unwrap_err(), "input length for Blake2 F precompile should be exactly 213 bytes"); } #[test] @@ -817,7 +817,7 @@ mod tests { let result = blake2.execute(&input[..], &mut BytesRef::Fixed(&mut out[..])); assert!(result.is_err()); - assert_eq!(result.unwrap_err(), "incorrect final block indicator flag".into()); + assert_eq!(result.unwrap_err(), "incorrect final block indicator flag"); } #[test] @@ -1337,7 +1337,7 @@ mod tests { #[test] fn from_json() { - let b = Builtin::from(ethjson::spec::Builtin { + let b = Builtin::try_from(ethjson::spec::Builtin { name: "identity".to_owned(), pricing: map![ 0 => PricingAt { @@ -1505,6 +1505,6 @@ mod tests { }).unwrap(); assert_eq!(b.cost(&[0; 1], 0), U256::from(0), "not activated yet"); - assert_eq!(b.cost(&[0; 1], 1), U256::from(1_337), "use price #3"); + assert_eq!(b.cost(&[0; 1], 1), U256::from(1_337)); } } diff --git a/json/Cargo.toml b/json/Cargo.toml index 164ee6bce46..2ec487209eb 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -11,3 +11,5 @@ serde = "1.0" serde_json = "1.0" serde_derive = "1.0" +[dev-dependencies] +macros = { path = "../util/macros" } diff --git a/json/src/lib.rs b/json/src/lib.rs index af5d93edfa6..d6857d19858 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -20,6 +20,9 @@ extern crate serde_json; extern crate ethereum_types; #[macro_use] extern crate serde_derive; +#[cfg(test)] +extern crate macros; + pub mod hash; pub mod uint; pub mod bytes; diff --git a/json/src/spec/builtin.rs b/json/src/spec/builtin.rs index ec599999908..19ddfc2c635 100644 --- a/json/src/spec/builtin.rs +++ b/json/src/spec/builtin.rs @@ -138,7 +138,6 @@ pub struct PricingAt { #[cfg(test)] mod tests { use serde_json; - use spec::builtin::{Builtin, Pricing, Linear, Modexp}; use uint::Uint; use super::{Builtin, BuiltinCompat, BTreeMap, Pricing, PricingAt, Linear, Modexp, AltBn128ConstOperations}; use macros::map;