Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
fix bad merge
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 committed Nov 2, 2019
1 parent 4f64fd2 commit cd6a160
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ethcore/builtin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ parity-bytes = "0.1"
parity-crypto = "0.4.0"

[dev-dependencies]
rustc-hex = "1.0"
hex-literal = "0.2.1"
14 changes: 7 additions & 7 deletions ethcore/builtin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u32>();
let (rounds_bytes, _) = input.split_at(std::mem::size_of::<u32>());
// 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)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
}
}
2 changes: 2 additions & 0 deletions json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"

[dev-dependencies]
macros = { path = "../util/macros" }
3 changes: 3 additions & 0 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion json/src/spec/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cd6a160

Please sign in to comment.