diff --git a/json/src/bytes.rs b/json/src/bytes.rs index 812b109f7..18dc73844 100644 --- a/json/src/bytes.rs +++ b/json/src/bytes.rs @@ -19,6 +19,7 @@ use rustc_serialize::hex::FromHex; use serde::{Deserialize, Deserializer, Error}; use serde::de::Visitor; +use std::ops::Deref; /// Lenient bytes json deserialization for test json files. #[derive(Default, Debug, PartialEq, Clone)] @@ -30,6 +31,14 @@ impl Into> for Bytes { } } +impl Deref for Bytes { + type Target = Vec; + + fn deref(&self) -> &Vec { + &self.0 + } +} + impl Deserialize for Bytes { fn deserialize(deserializer: &mut D) -> Result where D: Deserializer { diff --git a/json/src/vm/call.rs b/json/src/vm/call.rs index 2fe6265aa..1947fd25c 100644 --- a/json/src/vm/call.rs +++ b/json/src/vm/call.rs @@ -39,16 +39,47 @@ pub struct Call { mod tests { use serde_json; use vm::Call; + use util::numbers::U256; + use uint::Uint; + use util::hash::Address as Hash160; + use hash::Address; + use maybe::MaybeEmpty; + use std::str::FromStr; #[test] - fn call_deserialization() { + fn call_deserialization_empty_dest() { let s = r#"{ "data" : "0x1111222233334444555566667777888899990000aaaabbbbccccddddeeeeffff", "destination" : "", "gasLimit" : "0x1748766aa5", "value" : "0x00" }"#; - let _deserialized: Call = serde_json::from_str(s).unwrap(); - // TODO: validate all fields + let call: Call = serde_json::from_str(s).unwrap(); + + assert_eq!(&call.data[..], + &[0x11, 0x11, 0x22, 0x22, 0x33, 0x33, 0x44, 0x44, 0x55, 0x55, 0x66, 0x66, 0x77, 0x77, + 0x88, 0x88, 0x99, 0x99, 0x00, 0x00, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, + 0xee, 0xee, 0xff, 0xff]); + + assert_eq!(call.destination, MaybeEmpty::None); + assert_eq!(call.gas_limit, Uint(U256::from(0x1748766aa5u64))); + assert_eq!(call.value, Uint(U256::from(0))); + } + + #[test] + fn call_deserialization_full_dest() { + let s = r#"{ + "data" : "0x1234", + "destination" : "5a39ed1020c04d4d84539975b893a4e7c53eab6c", + "gasLimit" : "0x1748766aa5", + "value" : "0x00" + }"#; + + let call: Call = serde_json::from_str(s).unwrap(); + + assert_eq!(&call.data[..], &[0x12, 0x34]); + assert_eq!(call.destination, MaybeEmpty::Some(Address(Hash160::from_str("5a39ed1020c04d4d84539975b893a4e7c53eab6c").unwrap()))); + assert_eq!(call.gas_limit, Uint(U256::from(0x1748766aa5u64))); + assert_eq!(call.value, Uint(U256::from(0))); } } diff --git a/rpc/src/v1/impls/ethcore.rs b/rpc/src/v1/impls/ethcore.rs index de458a53f..f5d6f1fda 100644 --- a/rpc/src/v1/impls/ethcore.rs +++ b/rpc/src/v1/impls/ethcore.rs @@ -22,7 +22,7 @@ use std::sync::{Arc, Weak}; use std::ops::Deref; use std::collections::BTreeMap; use jsonrpc_core::*; -use ethminer::{MinerService}; +use ethminer::MinerService; use v1::traits::Ethcore; use v1::types::Bytes;