diff --git a/Cargo.lock b/Cargo.lock index ee93d28f5..94e62f23d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1511,9 +1511,9 @@ name = "ethjson" version = "0.1.0" dependencies = [ "ethereum-types 0.6.0 (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.99 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index a6ff42a91..782af50ba 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -79,7 +79,7 @@ engine = { path = "./engine", features = ["test-helpers"] } env_logger = "0.5" ethash = { path = "../ethash" } ethcore-accounts = { path = "../accounts" } -ethjson = { path = "../json" } +ethjson = { path = "../json", features = ["test-helpers"] } ethkey = { path = "../accounts/ethkey" } fetch = { path = "../util/fetch" } kvdb-memorydb = "0.1" @@ -89,7 +89,6 @@ machine = { path = "./machine", features = ["test-helpers"] } macros = { path = "../util/macros" } null-engine = { path = "./engines/null-engine" } parity-runtime = { path = "../util/runtime" } -pod = { path = "pod" } rlp_compress = { path = "../util/rlp-compress" } rustc-hex = "1" serde_json = "1.0" diff --git a/ethcore/pod/src/account.rs b/ethcore/pod/src/account.rs index 42f5abf74..517adad95 100644 --- a/ethcore/pod/src/account.rs +++ b/ethcore/pod/src/account.rs @@ -85,22 +85,6 @@ impl PodAccount { } } -impl From for PodAccount { - fn from(a: ethjson::blockchain::Account) -> Self { - PodAccount { - balance: a.balance.into(), - nonce: a.nonce.into(), - code: Some(a.code.into()), - storage: a.storage.into_iter().map(|(key, value)| { - let key: U256 = key.into(); - let value: U256 = value.into(); - (BigEndianHash::from_uint(&key), BigEndianHash::from_uint(&value)) - }).collect(), - version: a.version.into(), - } - } -} - impl From for PodAccount { fn from(a: ethjson::spec::Account) -> Self { PodAccount { diff --git a/ethcore/pod/src/state.rs b/ethcore/pod/src/state.rs index f83ecc07c..e626d54b5 100644 --- a/ethcore/pod/src/state.rs +++ b/ethcore/pod/src/state.rs @@ -46,13 +46,6 @@ impl PodState { } } -impl From for PodState { - fn from(s: ethjson::blockchain::State) -> PodState { - let state = s.into_iter().map(|(addr, acc)| (addr.into(), PodAccount::from(acc))).collect(); - PodState(state) - } -} - impl From for PodState { fn from(s: ethjson::spec::State) -> PodState { let state: BTreeMap<_,_> = s.into_iter() diff --git a/ethcore/src/json_tests/chain.rs b/ethcore/src/json_tests/chain.rs index 28e1f5673..352379dea 100644 --- a/ethcore/src/json_tests/chain.rs +++ b/ethcore/src/json_tests/chain.rs @@ -44,7 +44,7 @@ fn skip_test(name: &String) -> bool { pub fn json_chain_test(json_data: &[u8], start_stop_hook: &mut H) -> Vec { let _ = ::env_logger::try_init(); - let tests = ethjson::blockchain::Test::load(json_data).unwrap(); + let tests = ethjson::test_helpers::blockchain::Test::load(json_data).unwrap(); let mut failed = Vec::new(); for (name, blockchain) in tests.into_iter() { @@ -84,7 +84,7 @@ pub fn json_chain_test(json_data: &[u8], start_stop_ho { let db = test_helpers::new_db(); let mut config = ClientConfig::default(); - if ethjson::blockchain::Engine::NoProof == blockchain.engine { + if ethjson::test_helpers::blockchain::Engine::NoProof == blockchain.engine { config.verifier_type = VerifierType::CanonNoSeal; config.check_seal = false; } diff --git a/ethcore/src/json_tests/difficulty.rs b/ethcore/src/json_tests/difficulty.rs index 399803bcb..bc7738db0 100644 --- a/ethcore/src/json_tests/difficulty.rs +++ b/ethcore/src/json_tests/difficulty.rs @@ -14,16 +14,20 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use ethjson; -use types::header::Header; use ethereum_types::U256; +use ethjson::test_helpers::difficulty::DifficultyTest; +use types::header::Header; use spec::Spec; use super::HookType; -pub fn json_difficulty_test(json_data: &[u8], spec: Spec, start_stop_hook: &mut H) -> Vec { - let _ = ::env_logger::try_init(); - let tests = ethjson::test::DifficultyTest::load(json_data).unwrap(); +pub fn json_difficulty_test( + json_data: &[u8], + spec: Spec, + start_stop_hook: &mut H +) -> Vec { + let _ = env_logger::try_init(); + let tests = DifficultyTest::load(json_data).unwrap(); let engine = &spec.engine; for (name, test) in tests.into_iter() { diff --git a/ethcore/src/json_tests/executive.rs b/ethcore/src/json_tests/executive.rs index 2ce13f6f0..2d32de534 100644 --- a/ethcore/src/json_tests/executive.rs +++ b/ethcore/src/json_tests/executive.rs @@ -243,8 +243,12 @@ fn do_json_test(json_data: &[u8], h: &mut H) -> Vec(vm_type: &VMType, json_data: &[u8], start_stop_hook: &mut H) -> Vec { - let tests = ethjson::vm::Test::load(json_data).unwrap(); +fn do_json_test_for( + vm_type: &VMType, + json_data: &[u8], + start_stop_hook: &mut H +) -> Vec { + let tests = ethjson::test_helpers::vm::Test::load(json_data).unwrap(); let mut failed = Vec::new(); for (name, vm) in tests.into_iter() { @@ -336,15 +340,15 @@ fn do_json_test_for(vm_type: &VMType, json_data: &[u8] for (address, account) in vm.post_state.unwrap().into_iter() { let address = address.into(); - let code: Vec = account.code.into(); + let code: Vec = account.code.expect("code is missing from json; test should have code").into(); let found_code = try_fail!(state.code(&address)); let found_balance = try_fail!(state.balance(&address)); let found_nonce = try_fail!(state.nonce(&address)); fail_unless(found_code.as_ref().map_or_else(|| code.is_empty(), |c| &**c == &code), "code is incorrect"); - fail_unless(found_balance == account.balance.into(), "balance is incorrect"); - fail_unless(found_nonce == account.nonce.into(), "nonce is incorrect"); - for (k, v) in account.storage { + fail_unless(account.balance.as_ref().map_or(false, |b| b.0 == found_balance), "balance is incorrect"); + fail_unless(account.nonce.as_ref().map_or(false, |n| n.0 == found_nonce), "nonce is incorrect"); + for (k, v) in account.storage.expect("test should have storage") { let key: U256 = k.into(); let value: U256 = v.into(); let found_storage = try_fail!(state.storage_at(&address, &BigEndianHash::from_uint(&key))); diff --git a/ethcore/src/json_tests/skip.rs b/ethcore/src/json_tests/skip.rs index b6ef9795f..792b9614b 100644 --- a/ethcore/src/json_tests/skip.rs +++ b/ethcore/src/json_tests/skip.rs @@ -16,19 +16,19 @@ //! State tests to skip. -use ethjson; +use ethjson::test_helpers::skip::SkipStates; #[cfg(feature="ci-skip-tests")] -lazy_static!{ - pub static ref SKIP_TEST_STATE: ethjson::test::SkipStates = { +lazy_static! { + pub static ref SKIP_TEST_STATE: SkipStates = { let skip_data = include_bytes!("../../res/ethereum/tests-issues/currents.json"); - ethjson::test::SkipStates::load(&skip_data[..]).expect("No invalid json allowed") + SkipStates::load(&skip_data[..]).expect("No invalid json allowed") }; } #[cfg(not(feature="ci-skip-tests"))] lazy_static!{ - pub static ref SKIP_TEST_STATE: ethjson::test::SkipStates = { - ethjson::test::SkipStates::empty() + pub static ref SKIP_TEST_STATE: SkipStates = { + SkipStates::empty() }; } diff --git a/ethcore/src/json_tests/state.rs b/ethcore/src/json_tests/state.rs index dc2714fba..24a001b8a 100644 --- a/ethcore/src/json_tests/state.rs +++ b/ethcore/src/json_tests/state.rs @@ -49,7 +49,7 @@ fn skip_test(subname: &str, chain: &String, number: usize) -> bool { pub fn json_chain_test(json_data: &[u8], start_stop_hook: &mut H) -> Vec { let _ = ::env_logger::try_init(); - let tests = ethjson::state::test::Test::load(json_data).unwrap(); + let tests = ethjson::test_helpers::state::Test::load(json_data).unwrap(); let mut failed = Vec::new(); for (name, test) in tests.into_iter() { diff --git a/ethcore/src/json_tests/transaction.rs b/ethcore/src/json_tests/transaction.rs index 149aa6786..19bd428e9 100644 --- a/ethcore/src/json_tests/transaction.rs +++ b/ethcore/src/json_tests/transaction.rs @@ -41,7 +41,7 @@ pub fn run_test_file(p: &Path, h: &mut H) { const BLOCK_NUMBER: u64 = 0x6ffffffffffffe; fn do_json_test(json_data: &[u8], start_stop_hook: &mut H) -> Vec { - let tests = ethjson::transaction::Test::load(json_data).unwrap(); + let tests = ethjson::test_helpers::transaction::Test::load(json_data).unwrap(); let mut failed = Vec::new(); for (name, test) in tests.into_iter() { start_stop_hook(&name, HookType::OnStart); diff --git a/ethcore/src/json_tests/trie.rs b/ethcore/src/json_tests/trie.rs index 232cc15fc..899c7c7d7 100644 --- a/ethcore/src/json_tests/trie.rs +++ b/ethcore/src/json_tests/trie.rs @@ -26,7 +26,7 @@ pub use self::secure::run_test_path as run_secure_test_path; pub use self::secure::run_test_file as run_secure_test_file; fn test_trie(json: &[u8], trie: TrieSpec, start_stop_hook: &mut H) -> Vec { - let tests = ethjson::trie::Test::load(json).unwrap(); + let tests = ethjson::test_helpers::trie::Test::load(json).unwrap(); let factory = TrieFactory::new(trie, ethtrie::Layout); let mut result = vec![]; diff --git a/ethcore/types/src/transaction/transaction.rs b/ethcore/types/src/transaction/transaction.rs index e1139dc1f..6e99dc429 100644 --- a/ethcore/types/src/transaction/transaction.rs +++ b/ethcore/types/src/transaction/transaction.rs @@ -134,8 +134,8 @@ impl Transaction { } } -impl From for SignedTransaction { - fn from(t: ethjson::state::Transaction) -> Self { +impl From for SignedTransaction { + fn from(t: ethjson::transaction::Transaction) -> Self { let to: Option = t.to.into(); let secret = t.secret.map(|s| Secret::from(s.0)); let tx = Transaction { diff --git a/evmbin/src/main.rs b/evmbin/src/main.rs index d498b7be6..9295806ba 100644 --- a/evmbin/src/main.rs +++ b/evmbin/src/main.rs @@ -122,7 +122,7 @@ fn main() { } fn run_state_test(args: Args) { - use ethjson::state::test::Test; + use ethjson::test_helpers::state::Test; // Parse the specified state test JSON file provided to the command `state-test `. let file = args.arg_file.expect("PATH to a state test JSON file is required"); @@ -443,8 +443,8 @@ fn die(msg: T) -> ! { mod tests { use common_types::transaction; use docopt::Docopt; - use ethcore::{TrieSpec}; - use ethjson::state::test::{State}; + use ethcore::TrieSpec; + use ethjson::test_helpers::state::State; use serde::Deserialize; use super::{Args, USAGE, Address, run_call}; diff --git a/json/Cargo.toml b/json/Cargo.toml index 175155e9d..4fe094d98 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -3,10 +3,16 @@ description = "Parity Ethereum JSON Deserialization" name = "ethjson" version = "0.1.0" authors = ["Parity Technologies "] +edition = "2018" [dependencies] ethereum-types = "0.6.0" rustc-hex = "1.0" -serde = "1.0" +serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -serde_derive = "1.0" + +[dev-dependencies] +macros = { path = "../util/macros" } + +[features] +test-helpers = [] diff --git a/json/src/blockchain/account.rs b/json/src/blockchain/account.rs deleted file mode 100644 index 535992ae0..000000000 --- a/json/src/blockchain/account.rs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Blockchain test account deserializer. - -use std::collections::BTreeMap; -use uint::Uint; -use bytes::Bytes; - -/// Blockchain test account deserializer. -#[derive(Debug, PartialEq, Deserialize, Clone)] -pub struct Account { - /// Balance. - pub balance: Uint, - /// Code. - pub code: Bytes, - /// Nonce. - pub nonce: Uint, - /// Storage. - pub storage: BTreeMap, - /// Version. - #[serde(default)] - pub version: Uint, -} - -#[cfg(test)] -mod tests { - use serde_json; - use blockchain::account::Account; - - #[test] - fn account_deserialization() { - let s = r#"{ - "balance" : "0x09184e72a078", - "code" : "0x600140600155", - "nonce" : "0x00", - "storage" : { - "0x01" : "0x9a10c2b5bb8f3c602e674006d9b21f09167df57c87a78a5ce96d4159ecb76520" - } - }"#; - let _deserialized: Account = serde_json::from_str(s).unwrap(); - // TODO: validate all fields - } -} diff --git a/json/src/blockchain/state.rs b/json/src/blockchain/state.rs deleted file mode 100644 index e108c937f..000000000 --- a/json/src/blockchain/state.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Blockchain test state deserializer. - -use std::collections::BTreeMap; -use hash::Address; -use blockchain::account::Account; - -/// Blockchain test state deserializer. -#[derive(Debug, PartialEq, Deserialize, Clone)] -pub struct State(BTreeMap); - -impl IntoIterator for State { - type Item = as IntoIterator>::Item; - type IntoIter = as IntoIterator>::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} diff --git a/json/src/blockchain/test.rs b/json/src/blockchain/test.rs deleted file mode 100644 index d773aa3b5..000000000 --- a/json/src/blockchain/test.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Blockchain test deserializer. - -use std::collections::BTreeMap; -use std::io::Read; -use serde_json; -use serde_json::Error; -use blockchain::blockchain::BlockChain; - -/// Blockchain test deserializer. -#[derive(Debug, PartialEq, Deserialize)] -pub struct Test(BTreeMap); - -impl IntoIterator for Test { - type Item = as IntoIterator>::Item; - type IntoIter = as IntoIterator>::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} - -impl Test { - /// Loads test from json. - pub fn load(reader: R) -> Result where R: Read { - serde_json::from_reader(reader) - } -} diff --git a/json/src/blockchain/transaction.rs b/json/src/blockchain/transaction.rs deleted file mode 100644 index 4e519f394..000000000 --- a/json/src/blockchain/transaction.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Blockchain test transaction deserialization. - -use uint::Uint; -use bytes::Bytes; - -/// Blockchain test transaction deserialization. -#[derive(Debug, PartialEq, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Transaction { - data: Bytes, - gas_limit: Uint, - gas_price: Uint, - nonce: Uint, - r: Uint, - s: Uint, - v: Uint, - value: Uint -} diff --git a/json/src/bytes.rs b/json/src/bytes.rs index 5956cd428..8934e9c0e 100644 --- a/json/src/bytes.rs +++ b/json/src/bytes.rs @@ -63,10 +63,10 @@ impl FromStr for Bytes { 2 if value.starts_with("0x") => vec![], _ if value.starts_with("0x") && value.len() % 2 == 1 => { let v = "0".to_owned() + &value[2..]; - FromHex::from_hex(v.as_str()).unwrap_or(vec![]) + FromHex::from_hex(v.as_str()).unwrap_or_default() }, - _ if value.starts_with("0x") => FromHex::from_hex(&value[2..]).unwrap_or(vec![]), - _ => FromHex::from_hex(value).unwrap_or(vec![]), + _ if value.starts_with("0x") => FromHex::from_hex(&value[2..]).unwrap_or_default(), + _ => FromHex::from_hex(value).unwrap_or_default(), }; Ok(Bytes(v)) @@ -100,8 +100,7 @@ impl<'a> Visitor<'a> for BytesVisitor { #[cfg(test)] mod test { - use serde_json; - use bytes::Bytes; + use super::Bytes; #[test] fn bytes_deserialization() { @@ -118,8 +117,7 @@ mod test { #[test] fn bytes_into() { - let bytes = Bytes(vec![0xff, 0x11]); - let v: Vec = bytes.into(); + let v: Vec = Bytes(vec![0xff, 0x11]).into(); assert_eq!(vec![0xff, 0x11], v); } } diff --git a/json/src/hash.rs b/json/src/hash.rs index 3e364b950..d6cef24cb 100644 --- a/json/src/hash.rs +++ b/json/src/hash.rs @@ -94,10 +94,8 @@ impl_hash!(Bloom, Hash2048); #[cfg(test)] mod test { + use super::H256; use std::str::FromStr; - use serde_json; - use ethereum_types; - use hash::H256; #[test] fn hash_deserialization() { diff --git a/json/src/lib.rs b/json/src/lib.rs index af5d93edf..39cf728cb 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -14,20 +14,18 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -extern crate rustc_hex; -extern crate serde; -extern crate serde_json; -extern crate ethereum_types; -#[macro_use] extern crate serde_derive; +//! JSON deserialization library + +#![warn(missing_docs)] -pub mod hash; -pub mod uint; pub mod bytes; -pub mod blockchain; -pub mod spec; -pub mod trie; -pub mod vm; +pub mod hash; pub mod maybe; -pub mod state; +pub mod spec; +pub mod uint; +pub mod vm; pub mod transaction; -pub mod test; +pub mod state; + +#[cfg(any(test, feature = "test-helpers"))] +pub mod test_helpers; diff --git a/json/src/maybe.rs b/json/src/maybe.rs index 4fd2ca60e..2273555b3 100644 --- a/json/src/maybe.rs +++ b/json/src/maybe.rs @@ -61,11 +61,10 @@ impl<'a, T> Visitor<'a> for MaybeEmptyVisitor where T: Deserialize<'a> { } fn visit_string(self, value: String) -> Result where E: Error { - match value.is_empty() { - true => Ok(MaybeEmpty::None), - false => { - T::deserialize(value.into_deserializer()).map(MaybeEmpty::Some) - } + if value.is_empty() { + Ok(MaybeEmpty::None) + } else { + T::deserialize(value.into_deserializer()).map(MaybeEmpty::Some) } } } @@ -82,10 +81,8 @@ impl Into> for MaybeEmpty { #[cfg(test)] mod tests { use std::str::FromStr; - use serde_json; - use ethereum_types; - use hash::H256; - use maybe::MaybeEmpty; + use super::MaybeEmpty; + use crate::hash::H256; #[test] fn maybe_deserialization() { diff --git a/json/src/spec/account.rs b/json/src/spec/account.rs index 7e849a6bc..6d722ea23 100644 --- a/json/src/spec/account.rs +++ b/json/src/spec/account.rs @@ -17,11 +17,12 @@ //! Spec account deserialization. use std::collections::BTreeMap; -use uint::Uint; -use bytes::Bytes; -use spec::builtin::Builtin; + +use crate::{bytes::Bytes, spec::builtin::Builtin, uint::Uint}; +use serde::Deserialize; /// Spec account. +#[cfg_attr(any(test, feature = "test-helpers"), derive(Clone))] #[derive(Debug, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] pub struct Account { @@ -50,12 +51,8 @@ impl Account { #[cfg(test)] mod tests { - use std::collections::BTreeMap; - use serde_json; - use spec::account::Account; + use super::{Account, Bytes, BTreeMap, Uint}; use ethereum_types::U256; - use uint::Uint; - use bytes::Bytes; #[test] fn account_balance_missing_not_empty() { diff --git a/json/src/spec/authority_round.rs b/json/src/spec/authority_round.rs index 615cc4ca5..0a31203f6 100644 --- a/json/src/spec/authority_round.rs +++ b/json/src/spec/authority_round.rs @@ -39,9 +39,8 @@ //! ``` use std::collections::BTreeMap; -use hash::Address; -use uint::Uint; -use bytes::Bytes; +use crate::{bytes::Bytes, hash::Address, uint::Uint}; +use serde::Deserialize; use super::ValidatorSet; /// Authority params deserialization. @@ -108,12 +107,9 @@ pub struct AuthorityRound { #[cfg(test)] mod tests { + use super::{Address, Uint}; use ethereum_types::{U256, H160}; - use uint::Uint; - use serde_json; - use hash::Address; - use spec::validator_set::ValidatorSet; - use spec::authority_round::AuthorityRound; + use crate::spec::{validator_set::ValidatorSet, authority_round::AuthorityRound}; use std::str::FromStr; #[test] diff --git a/json/src/spec/basic_authority.rs b/json/src/spec/basic_authority.rs index c21333a12..2925cbdde 100644 --- a/json/src/spec/basic_authority.rs +++ b/json/src/spec/basic_authority.rs @@ -16,8 +16,9 @@ //! Authority params deserialization. -use uint::Uint; +use crate::uint::Uint; use super::ValidatorSet; +use serde::Deserialize; /// Authority params deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -40,13 +41,10 @@ pub struct BasicAuthority { #[cfg(test)] mod tests { - use serde_json; - use uint::Uint; - use ethereum_types::{U256, H160}; - use hash::Address; - use spec::basic_authority::BasicAuthority; - use spec::validator_set::ValidatorSet; use std::str::FromStr; + use super::{BasicAuthority, Uint}; + use ethereum_types::{U256, H160}; + use crate::{hash::Address, spec::validator_set::ValidatorSet}; #[test] fn basic_authority_deserialization() { diff --git a/json/src/spec/builtin.rs b/json/src/spec/builtin.rs index c4f9f4e1e..f751750dd 100644 --- a/json/src/spec/builtin.rs +++ b/json/src/spec/builtin.rs @@ -16,7 +16,8 @@ //! Spec builtin deserialization. -use uint::Uint; +use crate::uint::Uint; +use serde::Deserialize; /// Linear pricing. @@ -97,9 +98,7 @@ pub struct Builtin { #[cfg(test)] mod tests { - use serde_json; - use spec::builtin::{Builtin, Pricing, Linear, Modexp}; - use uint::Uint; + use super::{Builtin, Modexp, Linear, Pricing, Uint}; #[test] fn builtin_deserialization() { diff --git a/json/src/spec/clique.rs b/json/src/spec/clique.rs index cef0ebfb8..4d2c4a99f 100644 --- a/json/src/spec/clique.rs +++ b/json/src/spec/clique.rs @@ -17,13 +17,14 @@ //! Clique params deserialization. use std::num::NonZeroU64; +use serde::Deserialize; /// Clique params deserialization. #[derive(Debug, PartialEq, Deserialize)] pub struct CliqueParams { - /// period as defined in EIP + /// period as defined in EIP 225 pub period: Option, - /// epoch length as defined in EIP + /// epoch length as defined in EIP 225 pub epoch: Option } @@ -36,8 +37,7 @@ pub struct Clique { #[cfg(test)] mod tests { - use serde_json; - use super::*; + use super::{Clique, NonZeroU64}; #[test] fn clique_deserialization() { diff --git a/json/src/spec/engine.rs b/json/src/spec/engine.rs index cfa1d8caf..1ef517208 100644 --- a/json/src/spec/engine.rs +++ b/json/src/spec/engine.rs @@ -17,6 +17,7 @@ //! Engine deserialization. use super::{Ethash, BasicAuthority, AuthorityRound, NullEngine, InstantSeal, Clique}; +use serde::Deserialize; /// Engine deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -40,8 +41,7 @@ pub enum Engine { #[cfg(test)] mod tests { - use serde_json; - use spec::Engine; + use super::Engine; #[test] fn engine_deserialization() { diff --git a/json/src/spec/ethash.rs b/json/src/spec/ethash.rs index c9748c944..eee44d02b 100644 --- a/json/src/spec/ethash.rs +++ b/json/src/spec/ethash.rs @@ -17,16 +17,21 @@ //! Ethash params deserialization. use std::collections::BTreeMap; -use uint::{self, Uint}; -use bytes::Bytes; -use hash::Address; +use crate::{ + bytes::Bytes, + uint::{self, Uint}, + hash::Address +}; +use serde::Deserialize; /// Deserializable doppelganger of block rewards for EthashParams #[derive(Clone, Debug, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] #[serde(untagged)] pub enum BlockReward { + /// Single block reward Single(Uint), + /// Several block rewards Multi(BTreeMap), } @@ -110,12 +115,9 @@ pub struct Ethash { #[cfg(test)] mod tests { - use serde_json; - use uint::Uint; - use ethereum_types::{H160, U256}; - use hash::Address; - use spec::ethash::{Ethash, EthashParams, BlockReward}; use std::str::FromStr; + use super::{Address, BlockReward, Ethash, EthashParams, Uint}; + use ethereum_types::{H160, U256}; #[test] fn ethash_deserialization() { diff --git a/json/src/spec/genesis.rs b/json/src/spec/genesis.rs index 6c6def199..69ce6597c 100644 --- a/json/src/spec/genesis.rs +++ b/json/src/spec/genesis.rs @@ -16,10 +16,13 @@ //! Spec genesis deserialization. -use uint::{Uint, self}; -use hash::{Address, H256}; -use bytes::Bytes; -use spec::Seal; +use crate::{ + bytes::Bytes, + hash::{Address, H256}, + spec::Seal, + uint::{self, Uint}, +}; +use serde::Deserialize; /// Spec genesis. #[derive(Debug, PartialEq, Deserialize)] @@ -53,14 +56,13 @@ pub struct Genesis { #[cfg(test)] mod tests { - use serde_json; - use bytes::Bytes; - use uint::Uint; - use ethereum_types::{U256, H160, H64 as Eth64, H256 as Eth256}; - use hash::{H64, H256, Address}; - use spec::genesis::Genesis; - use spec::{Ethereum, Seal}; use std::str::FromStr; + use super::{Address, Bytes, Genesis, H256, Uint}; + use crate::{ + hash::H64, + spec::{Ethereum, Seal} + }; + use ethereum_types::{U256, H160, H64 as Eth64, H256 as Eth256}; #[test] fn genesis_deserialization() { diff --git a/json/src/spec/hardcoded_sync.rs b/json/src/spec/hardcoded_sync.rs index eed3dac65..3b53365cb 100644 --- a/json/src/spec/hardcoded_sync.rs +++ b/json/src/spec/hardcoded_sync.rs @@ -16,9 +16,8 @@ //! Spec hardcoded synchronization deserialization for the light client. -use hash::H256; -use uint::Uint; -use bytes::Bytes; +use crate::{bytes::Bytes, hash::H256, uint::Uint}; +use serde::Deserialize; /// Spec hardcoded sync. #[derive(Debug, PartialEq, Deserialize)] @@ -36,12 +35,9 @@ pub struct HardcodedSync { #[cfg(test)] mod tests { - use serde_json; - use uint::Uint; - use ethereum_types::{U256, H256 as Eth256}; - use hash::H256; - use spec::hardcoded_sync::HardcodedSync; use std::str::FromStr; + use super::{H256, HardcodedSync, Uint}; + use ethereum_types::{U256, H256 as Eth256}; #[test] fn hardcoded_sync_deserialization() { diff --git a/json/src/spec/instant_seal.rs b/json/src/spec/instant_seal.rs index 2f1ad33e9..ce0332299 100644 --- a/json/src/spec/instant_seal.rs +++ b/json/src/spec/instant_seal.rs @@ -16,6 +16,8 @@ //! Instant seal engine params deserialization. +use serde::Deserialize; + /// Instant seal engine params deserialization. #[derive(Debug, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] diff --git a/json/src/spec/null_engine.rs b/json/src/spec/null_engine.rs index 37ade4783..2e9b74c48 100644 --- a/json/src/spec/null_engine.rs +++ b/json/src/spec/null_engine.rs @@ -16,7 +16,8 @@ //! Null engine params deserialization. -use uint::Uint; +use crate::uint::Uint; +use serde::Deserialize; /// Authority params deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -39,10 +40,8 @@ pub struct NullEngine { #[cfg(test)] mod tests { - use serde_json; - use uint::Uint; + use super::{NullEngine, Uint}; use ethereum_types::U256; - use super::*; #[test] fn null_engine_deserialization() { diff --git a/json/src/spec/params.rs b/json/src/spec/params.rs index 58adbd6a4..f29076549 100644 --- a/json/src/spec/params.rs +++ b/json/src/spec/params.rs @@ -16,9 +16,12 @@ //! Spec params deserialization. -use uint::{self, Uint}; -use hash::{H256, Address}; -use bytes::Bytes; +use crate::{ + bytes::Bytes, + hash::{H256, Address}, + uint::{self, Uint} +}; +use serde::Deserialize; /// Spec params. #[derive(Debug, PartialEq, Deserialize)] @@ -140,18 +143,16 @@ pub struct Params { #[cfg(test)] mod tests { - use serde_json; - use uint::Uint; + use super::{Params, Uint}; use ethereum_types::U256; - use spec::params::Params; #[test] fn params_deserialization() { let s = r#"{ "maximumExtraDataSize": "0x20", - "networkID" : "0x1", - "chainID" : "0x15", - "subprotocolName" : "exp", + "networkID": "0x1", + "chainID": "0x15", + "subprotocolName": "exp", "minGasLimit": "0x1388", "accountStartNonce": "0x01", "gasLimitBoundDivisor": "0x20", diff --git a/json/src/spec/seal.rs b/json/src/spec/seal.rs index 67238a5f5..04d6c2f5c 100644 --- a/json/src/spec/seal.rs +++ b/json/src/spec/seal.rs @@ -16,9 +16,8 @@ //! Spec seal deserialization. -use hash::*; -use uint::Uint; -use bytes::Bytes; +use crate::{bytes::Bytes, hash::{H64, H256, H520}, uint::Uint}; +use serde::Deserialize; /// Ethereum seal. #[derive(Debug, PartialEq, Deserialize)] @@ -70,13 +69,9 @@ pub enum Seal { #[cfg(test)] mod tests { - use serde_json; - use hash::*; - use bytes::Bytes; - use uint::Uint; - use ethereum_types::{U256, H64 as Eth64, H256 as Eth256, H520 as Eth520}; - use spec::{Ethereum, AuthorityRoundSeal, TendermintSeal, Seal}; use std::str::FromStr; + use super::{AuthorityRoundSeal, Bytes, Ethereum, H64, H256, H520, TendermintSeal, Seal, Uint}; + use ethereum_types::{U256, H64 as Eth64, H256 as Eth256, H520 as Eth520}; #[test] fn seal_deserialization() { diff --git a/json/src/spec/spec.rs b/json/src/spec/spec.rs index 013320c27..e48134270 100644 --- a/json/src/spec/spec.rs +++ b/json/src/spec/spec.rs @@ -17,9 +17,9 @@ //! Spec deserialization. use std::io::Read; -use serde_json; +use crate::spec::{Params, Genesis, Engine, State, HardcodedSync}; +use serde::Deserialize; use serde_json::Error; -use spec::{Params, Genesis, Engine, State, HardcodedSync}; /// Fork spec definition #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deserialize)] @@ -70,8 +70,7 @@ impl Spec { #[cfg(test)] mod tests { - use serde_json; - use spec::spec::Spec; + use super::Spec; #[test] fn should_error_on_unknown_fields() { diff --git a/json/src/spec/state.rs b/json/src/spec/state.rs index e8a866367..fd50a864f 100644 --- a/json/src/spec/state.rs +++ b/json/src/spec/state.rs @@ -14,14 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! Blockchain test state deserializer. +//! Blockchain state deserializer. use std::collections::BTreeMap; -use hash::Address; -use bytes::Bytes; -use spec::{Account, Builtin}; +use crate::{ + bytes::Bytes, + hash::Address, + spec::{Account, Builtin} +}; +use serde::Deserialize; -/// Blockchain test state deserializer. +/// Blockchain state deserializer for tests +#[cfg(any(test, feature = "test-helpers"))] +#[derive(Clone, Debug, PartialEq, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct State(pub BTreeMap); + +/// Blockchain state deserializer. +#[cfg(not(any(test, feature = "test-helpers")))] #[derive(Debug, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] pub struct State(BTreeMap); diff --git a/json/src/spec/validator_set.rs b/json/src/spec/validator_set.rs index 4de1d3aa0..5dcc5558e 100644 --- a/json/src/spec/validator_set.rs +++ b/json/src/spec/validator_set.rs @@ -17,8 +17,8 @@ //! Validator set deserialization. use std::collections::BTreeMap; -use uint::Uint; -use hash::Address; +use crate::{hash::Address, uint::Uint}; +use serde::Deserialize; /// Different ways of specifying validators. #[derive(Debug, PartialEq, Deserialize)] @@ -37,12 +37,9 @@ pub enum ValidatorSet { #[cfg(test)] mod tests { - use serde_json; - use uint::Uint; - use ethereum_types::{H160, U256}; - use hash::Address; - use spec::validator_set::ValidatorSet; use std::str::FromStr; + use super::{Address, Uint, ValidatorSet}; + use ethereum_types::{H160, U256}; #[test] fn validator_set_deserialization() { diff --git a/json/src/state/log.rs b/json/src/state.rs similarity index 91% rename from json/src/state/log.rs rename to json/src/state.rs index 1a0dda529..da05b1f68 100644 --- a/json/src/state/log.rs +++ b/json/src/state.rs @@ -14,11 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! State test log deserialization. -use hash::{Address, H256, Bloom}; -use bytes::Bytes; +//! State deserialization types -/// State test log deserialization. +use crate::{ + bytes::Bytes, + hash::{Address, H256, Bloom}, +}; +use serde::Deserialize; + +/// State log deserialization. #[derive(Debug, PartialEq, Deserialize)] pub struct Log { /// Address. @@ -33,8 +37,7 @@ pub struct Log { #[cfg(test)] mod tests { - use serde_json; - use state::Log; + use super::Log; #[test] fn log_deserialization() { diff --git a/json/src/state/mod.rs b/json/src/state/mod.rs deleted file mode 100644 index 8c2ac2875..000000000 --- a/json/src/state/mod.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! State test deserialization. - -pub mod state; -pub mod transaction; -pub mod test; -pub mod log; - -pub use self::state::State; -pub use self::transaction::Transaction; -pub use self::test::Test; -pub use self::log::Log; -pub use vm::Env as Env; -pub use blockchain::State as AccountState; diff --git a/json/src/state/state.rs b/json/src/state/state.rs deleted file mode 100644 index f25dabec7..000000000 --- a/json/src/state/state.rs +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! State test deserialization. - -use bytes::Bytes; -use hash::H256; -use state::{Env, AccountState, Transaction, Log}; - -/// State test deserialization. -#[derive(Debug, PartialEq, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct State { - /// Environment. - pub env: Env, - /// Output. - #[serde(rename = "out")] - pub output: Bytes, - /// Pre state. - #[serde(rename = "pre")] - pub pre_state: AccountState, - /// Post state. - #[serde(rename = "post")] - pub post_state: AccountState, - /// Post state root. - pub post_state_root: H256, - /// Transaction. - pub transaction: Transaction, - /// Logs. - pub logs: Vec -} - -#[cfg(test)] -mod tests { - use serde_json; - use state::State; - - #[test] - fn state_deserialization() { - let s = r#"{ - "env" : { - "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", - "currentDifficulty" : "0x0100", - "currentGasLimit" : "0x01c9c380", - "currentNumber" : "0x00", - "currentTimestamp" : "0x01", - "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" - }, - "logs" : [ - ], - "out" : "0x", - "post" : { - "1000000000000000000000000000000000000000" : { - "balance" : "0x0de0b6b3a763ffff", - "code" : "0x6040600060406000600173100000000000000000000000000000000000000162055730f1600055", - "nonce" : "0x00", - "storage" : { - "0x00" : "0x01" - } - }, - "1000000000000000000000000000000000000001" : { - "balance" : "0x0de0b6b3a763ffff", - "code" : "0x604060006040600060027310000000000000000000000000000000000000026203d090f1600155", - "nonce" : "0x00", - "storage" : { - "0x01" : "0x01" - } - }, - "1000000000000000000000000000000000000002" : { - "balance" : "0x02", - "code" : "0x600160025533600455346007553060e6553260e8553660ec553860ee553a60f055", - "nonce" : "0x00", - "storage" : { - "0x02" : "0x01", - "0x04" : "0x1000000000000000000000000000000000000001", - "0x07" : "0x02", - "0xe6" : "0x1000000000000000000000000000000000000002", - "0xe8" : "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", - "0xec" : "0x40", - "0xee" : "0x21", - "0xf0" : "0x01" - } - }, - "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" : { - "balance" : "0x039455", - "code" : "0x", - "nonce" : "0x00", - "storage" : { - } - }, - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "0x0de0b6b3a7606bab", - "code" : "0x", - "nonce" : "0x01", - "storage" : { - } - } - }, - "postStateRoot" : "8f8ed2aed2973e159fa5486f47c6ebf15c5058f8e2350286b84b569bc6ce2d25", - "pre" : { - "1000000000000000000000000000000000000000" : { - "balance" : "0x0de0b6b3a7640000", - "code" : "0x6040600060406000600173100000000000000000000000000000000000000162055730f1600055", - "nonce" : "0x00", - "storage" : { - } - }, - "1000000000000000000000000000000000000001" : { - "balance" : "0x0de0b6b3a7640000", - "code" : "0x604060006040600060027310000000000000000000000000000000000000026203d090f1600155", - "nonce" : "0x00", - "storage" : { - } - }, - "1000000000000000000000000000000000000002" : { - "balance" : "0x00", - "code" : "0x600160025533600455346007553060e6553260e8553660ec553860ee553a60f055", - "nonce" : "0x00", - "storage" : { - } - }, - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "0x0de0b6b3a7640000", - "code" : "0x", - "nonce" : "0x00", - "storage" : { - } - } - }, - "transaction" : { - "data" : "", - "gasLimit" : "0x2dc6c0", - "gasPrice" : "0x01", - "nonce" : "0x00", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "1000000000000000000000000000000000000000", - "value" : "0x00" - } - }"#; - let _deserialized: State = serde_json::from_str(s).unwrap(); - // TODO: validate all fields - } -} diff --git a/json/src/state/transaction.rs b/json/src/state/transaction.rs deleted file mode 100644 index 693b97699..000000000 --- a/json/src/state/transaction.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! State test transaction deserialization. - -use uint::Uint; -use bytes::Bytes; -use hash::{Address, H256}; -use maybe::MaybeEmpty; - -/// State test transaction deserialization. -#[derive(Debug, PartialEq, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Transaction { - /// Transaction data. - pub data: Bytes, - /// Gas limit. - pub gas_limit: Uint, - /// Gas price. - pub gas_price: Uint, - /// Nonce. - pub nonce: Uint, - /// Secret key. - #[serde(rename = "secretKey")] - pub secret: Option, - /// To. - pub to: MaybeEmpty
, - /// Value. - pub value: Uint, -} - -#[cfg(test)] -mod tests { - use serde_json; - use state::Transaction; - - #[test] - fn transaction_deserialization() { - let s = r#"{ - "data" : "", - "gasLimit" : "0x2dc6c0", - "gasPrice" : "0x01", - "nonce" : "0x00", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "to" : "1000000000000000000000000000000000000000", - "value" : "0x00" - }"#; - let _deserialized: Transaction = serde_json::from_str(s).unwrap(); - // TODO: validate all fields - } -} diff --git a/json/src/test/mod.rs b/json/src/test/mod.rs deleted file mode 100644 index 355d30d69..000000000 --- a/json/src/test/mod.rs +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Additional test structures deserialization. - -use std::collections::BTreeMap; -use std::io::Read; -use serde_json; -use serde_json::Error; -use hash::H256; -use uint::Uint; - -/// Blockchain test header deserializer. -#[derive(Debug, PartialEq, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct DifficultyTestCase { - /// Parent timestamp. - pub parent_timestamp: Uint, - /// Parent difficulty. - pub parent_difficulty: Uint, - /// Parent uncle hash. - pub parent_uncles: H256, - /// Current timestamp. - pub current_timestamp: Uint, - /// Current difficulty. - pub current_difficulty: Uint, - /// Current block number. - pub current_block_number: Uint, -} - -/// Blockchain test deserializer. -#[derive(Debug, PartialEq, Deserialize)] -pub struct DifficultyTest(BTreeMap); - -impl IntoIterator for DifficultyTest { - type Item = as IntoIterator>::Item; - type IntoIter = as IntoIterator>::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} - -impl DifficultyTest { - /// Loads test from json. - pub fn load(reader: R) -> Result where R: Read { - serde_json::from_reader(reader) - } -} - -/// Test to skip (only if issue ongoing) -#[derive(Debug, PartialEq, Deserialize)] -pub struct SkipStates { - /// Block tests - pub block: Vec, - /// State tests - pub state: Vec, - -} - -/// Block test to skip. -#[derive(Debug, PartialEq, Deserialize)] -pub struct BlockSkipStates { - /// Issue reference. - pub reference: String, - /// Test failing name. - pub failing: String, - /// Items failing for the test. - pub subtests: Vec, -} - -/// State test to skip. -#[derive(Debug, PartialEq, Deserialize)] -pub struct StateSkipStates { - /// Issue reference. - pub reference: String, - /// Test failing name. - pub failing: String, - /// Items failing for the test. - pub subtests: BTreeMap -} - -/// State subtest to skip. -#[derive(Debug, PartialEq, Deserialize)] -pub struct StateSkipSubStates { - /// State test number of this item. Or '*' for all state. - pub subnumbers: Vec, - /// Chain for this items. - pub chain: String, -} - -impl SkipStates { - /// Loads skip states from json. - pub fn load(reader: R) -> Result where R: Read { - serde_json::from_reader(reader) - } - - /// Empty skip states. - pub fn empty() -> Self { - SkipStates { - block: Vec::new(), - state: Vec::new(), - } - } -} diff --git a/json/src/blockchain/block.rs b/json/src/test_helpers/blockchain/block.rs similarity index 95% rename from json/src/blockchain/block.rs rename to json/src/test_helpers/blockchain/block.rs index 23ba5300d..e219fb7bf 100644 --- a/json/src/blockchain/block.rs +++ b/json/src/test_helpers/blockchain/block.rs @@ -16,9 +16,9 @@ //! Blockchain test block deserializer. -use bytes::Bytes; -use blockchain::header::Header; -use blockchain::transaction::Transaction; +use crate::{bytes::Bytes, transaction::Transaction}; +use super::header::Header; +use serde::Deserialize; /// Blockchain test block deserializer. #[derive(Debug, PartialEq, Deserialize)] @@ -40,8 +40,7 @@ impl Block { #[cfg(test)] mod tests { - use serde_json; - use blockchain::block::Block; + use super::Block; #[test] fn block_deserialization() { @@ -66,7 +65,7 @@ mod tests { }, "blocknumber" : "1", "rlp" : "0xf901fcf901f7a05a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5aea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0c5c83ff43741f573a0c9b31d0e56fdd745f4e37d193c4e78544f302777aafcf3a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefba808456850b7b80a013735ab4156c9b36327224d92e1692fab8fc362f8e0f868c94d421848ef7cd0688931dcc53e5edc514c0c0", - "transactions" : [], + "transaction" : [], "uncleHeaders" : [] }"#; let _deserialized: Block = serde_json::from_str(s).unwrap(); diff --git a/json/src/blockchain/header.rs b/json/src/test_helpers/blockchain/header.rs similarity index 96% rename from json/src/blockchain/header.rs rename to json/src/test_helpers/blockchain/header.rs index 8de5b16ed..b11449342 100644 --- a/json/src/blockchain/header.rs +++ b/json/src/test_helpers/blockchain/header.rs @@ -16,9 +16,12 @@ //! Blockchain test header deserializer. -use hash::{H64, Address, H256, Bloom}; -use uint::Uint; -use bytes::Bytes; +use crate::{ + bytes::Bytes, + hash::{H64, Address, H256, Bloom}, + uint::Uint +}; +use serde::Deserialize; /// Blockchain test header deserializer. #[derive(Debug, PartialEq, Deserialize)] @@ -64,8 +67,7 @@ pub struct Header { #[cfg(test)] mod tests { - use serde_json; - use blockchain::header::Header; + use super::Header; #[test] fn header_deserialization() { diff --git a/json/src/blockchain/blockchain.rs b/json/src/test_helpers/blockchain/mod.rs similarity index 96% rename from json/src/blockchain/blockchain.rs rename to json/src/test_helpers/blockchain/mod.rs index b92336f79..3aac3e8a0 100644 --- a/json/src/blockchain/blockchain.rs +++ b/json/src/test_helpers/blockchain/mod.rs @@ -14,14 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! Blockchain deserialization. +//! Blockchain test deserialization. -use bytes::Bytes; -use hash::H256; -use blockchain::state::State; -use blockchain::header::Header; -use blockchain::block::Block; -use spec::{ForkSpec, Genesis, Seal, Ethereum}; +use crate::{ + bytes::Bytes, + hash::H256, + spec::{Ethereum, ForkSpec, Genesis, Seal, State} + +}; +use serde::Deserialize; + +pub mod block; +pub mod header; + +pub use self::block::Block; +pub use self::header::Header; + +/// Type for running `Blockchain` tests +pub type Test = super::tester::GenericTester; /// Json Block test possible engine kind. #[derive(Debug, PartialEq, Deserialize)] @@ -95,8 +105,7 @@ impl BlockChain { #[cfg(test)] mod tests { - use serde_json; - use blockchain::blockchain::BlockChain; + use super::BlockChain; #[test] fn blockchain_deserialization() { diff --git a/json/src/test_helpers/difficulty.rs b/json/src/test_helpers/difficulty.rs new file mode 100644 index 000000000..023966c6a --- /dev/null +++ b/json/src/test_helpers/difficulty.rs @@ -0,0 +1,23 @@ +use crate::{hash::H256, uint::Uint}; +use serde::Deserialize; + +/// Blockchain test header deserializer. +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DifficultyTestCase { + /// Parent timestamp. + pub parent_timestamp: Uint, + /// Parent difficulty. + pub parent_difficulty: Uint, + /// Parent uncle hash. + pub parent_uncles: H256, + /// Current timestamp. + pub current_timestamp: Uint, + /// Current difficulty. + pub current_difficulty: Uint, + /// Current block number. + pub current_block_number: Uint, +} + +/// Type for running `Difficulty` tests +pub type DifficultyTest = super::tester::GenericTester; diff --git a/json/src/blockchain/mod.rs b/json/src/test_helpers/mod.rs similarity index 65% rename from json/src/blockchain/mod.rs rename to json/src/test_helpers/mod.rs index 0a3b162e9..095738a0c 100644 --- a/json/src/blockchain/mod.rs +++ b/json/src/test_helpers/mod.rs @@ -14,21 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! Blockchain test deserialization. +//! Test structures for JSON deserialization. -pub mod account; -pub mod block; +/// Blockchain test helpers pub mod blockchain; -pub mod header; +/// Difficulty test helpers +pub mod difficulty; +/// Tests to skip helpers +pub mod skip; +/// State test helpers pub mod state; +/// Test primitives +pub mod tester; +/// Transaction test helpers pub mod transaction; -pub mod test; - -pub use self::account::Account; -pub use self::block::Block; -pub use self::blockchain::BlockChain; -pub use self::blockchain::Engine; -pub use self::header::Header; -pub use self::state::State; -pub use self::test::Test; -pub use self::transaction::Transaction; +/// Trie test helpers +pub mod trie; +/// Vm test helpers +pub mod vm { + /// Type for running `vm` tests + pub type Test = super::tester::GenericTester; +} diff --git a/json/src/test_helpers/skip.rs b/json/src/test_helpers/skip.rs new file mode 100644 index 000000000..3245fb1c3 --- /dev/null +++ b/json/src/test_helpers/skip.rs @@ -0,0 +1,58 @@ +use std::collections::BTreeMap; +use serde::Deserialize; + +/// Test to skip (only if issue ongoing) +#[derive(Debug, PartialEq, Deserialize)] +pub struct SkipStates { + /// Block tests + pub block: Vec, + /// State tests + pub state: Vec, + +} + +/// Block test to skip. +#[derive(Debug, PartialEq, Deserialize)] +pub struct BlockSkipStates { + /// Issue reference. + pub reference: String, + /// Test failing name. + pub failing: String, + /// Items failing for the test. + pub subtests: Vec, +} + +/// State test to skip. +#[derive(Debug, PartialEq, Deserialize)] +pub struct StateSkipStates { + /// Issue reference. + pub reference: String, + /// Test failing name. + pub failing: String, + /// Items failing for the test. + pub subtests: BTreeMap +} + +/// State subtest to skip. +#[derive(Debug, PartialEq, Deserialize)] +pub struct StateSkipSubStates { + /// State test number of this item. Or '*' for all state. + pub subnumbers: Vec, + /// Chain for this items. + pub chain: String, +} + +impl SkipStates { + /// Empty skip states. + pub fn empty() -> Self { + SkipStates { + block: Vec::new(), + state: Vec::new(), + } + } + + /// Loads test from json. + pub fn load(reader: R) -> Result where R: std::io::Read { + serde_json::from_reader(reader) + } +} diff --git a/json/src/state/test.rs b/json/src/test_helpers/state.rs similarity index 85% rename from json/src/state/test.rs rename to json/src/test_helpers/state.rs index b8e5f35f6..f86257dfa 100644 --- a/json/src/state/test.rs +++ b/json/src/test_helpers/state.rs @@ -14,37 +14,22 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! General test deserialization. +//! State test deserialization. + +/// Type for running `State` tests +pub type Test = super::tester::GenericTester; -use std::io::Read; use std::collections::BTreeMap; -use uint::Uint; -use bytes::Bytes; -use hash::{Address, H256}; -use spec::ForkSpec; -use state::{Env, AccountState, Transaction}; -use maybe::MaybeEmpty; -use serde_json::{self, Error}; - -/// State test deserializer. -#[derive(Debug, PartialEq, Deserialize)] -pub struct Test(BTreeMap); - -impl IntoIterator for Test { - type Item = as IntoIterator>::Item; - type IntoIter = as IntoIterator>::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} - -impl Test { - /// Loads test from json. - pub fn load(reader: R) -> Result where R: Read { - serde_json::from_reader(reader) - } -} +use serde::Deserialize; +use crate::{ + bytes::Bytes, + hash::{Address, H256}, + maybe::MaybeEmpty, + uint::Uint, + spec::{ForkSpec, State as AccountState}, + transaction::Transaction, + vm::Env +}; /// State test deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -87,12 +72,15 @@ impl MultiTransaction { pub fn select(&self, indexes: &PostStateIndexes) -> Transaction { Transaction { data: self.data[indexes.data as usize].clone(), - gas_limit: self.gas_limit[indexes.gas as usize].clone(), - gas_price: self.gas_price.clone(), - nonce: self.nonce.clone(), - secret: self.secret.clone(), + gas_limit: self.gas_limit[indexes.gas as usize], + gas_price: self.gas_price, + nonce: self.nonce, to: self.to.clone(), - value: self.value[indexes.value as usize].clone(), + value: self.value[indexes.value as usize], + r: Default::default(), + s: Default::default(), + v: Default::default(), + secret: self.secret.clone(), } } } diff --git a/json/src/test_helpers/tester.rs b/json/src/test_helpers/tester.rs new file mode 100644 index 000000000..610f59723 --- /dev/null +++ b/json/src/test_helpers/tester.rs @@ -0,0 +1,27 @@ +use std::collections::BTreeMap; +use serde::Deserialize; +use serde::de::DeserializeOwned; + +/// A genric wrapper over a `BTreeMap` for tests +#[derive(Deserialize)] +pub struct GenericTester(BTreeMap); + +impl IntoIterator for GenericTester { + type Item = as IntoIterator>::Item; + type IntoIter = as IntoIterator>::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + +impl GenericTester +where + T: DeserializeOwned + Ord, + U: DeserializeOwned +{ + /// Loads test from json. + pub fn load(reader: R) -> Result where R: std::io::Read { + serde_json::from_reader(reader) + } +} diff --git a/json/src/transaction/txtest.rs b/json/src/test_helpers/transaction.rs similarity index 90% rename from json/src/transaction/txtest.rs rename to json/src/test_helpers/transaction.rs index e72e5f60b..9cfeb032b 100644 --- a/json/src/transaction/txtest.rs +++ b/json/src/test_helpers/transaction.rs @@ -17,16 +17,17 @@ //! Transaction test deserialization. use std::collections::BTreeMap; -use bytes::Bytes; -use hash::Address; -use hash::H256; -use spec::ForkSpec; +use crate::{bytes::Bytes, hash::{Address, H256}, spec::ForkSpec}; +use serde::Deserialize; + +/// Type for running `Transaction` tests +pub type Test = super::tester::GenericTester; /// Transaction test deserialization. #[derive(Debug, Deserialize)] pub struct TransactionTest { pub rlp: Bytes, - pub _info: ::serde::de::IgnoredAny, + pub _info: serde::de::IgnoredAny, #[serde(flatten)] pub post_state: BTreeMap, } @@ -43,8 +44,7 @@ pub struct PostState { #[cfg(test)] mod tests { - use serde_json; - use transaction::TransactionTest; + use super::TransactionTest; #[test] fn transaction_deserialization() { diff --git a/json/src/trie/input.rs b/json/src/test_helpers/trie/input.rs similarity index 95% rename from json/src/trie/input.rs rename to json/src/test_helpers/trie/input.rs index 4c56c10d7..01d223b59 100644 --- a/json/src/trie/input.rs +++ b/json/src/test_helpers/trie/input.rs @@ -19,7 +19,7 @@ use std::fmt; use std::collections::BTreeMap; use std::str::FromStr; -use bytes::Bytes; +use crate::bytes::Bytes; use serde::{Deserialize, Deserializer}; use serde::de::{Error as ErrorTrait, Visitor, MapAccess, SeqAccess}; @@ -89,8 +89,8 @@ impl<'a> Visitor<'a> for InputVisitor { return Err(V::Error::custom("Invalid key value pair.")); } - let ref key_str: Option = keyval[0]; - let ref val_str: Option = keyval[1]; + let key_str = &keyval[0]; + let val_str = &keyval[1]; let key = match *key_str { Some(ref k) if k.starts_with("0x") => Bytes::from_str(k).map_err(V::Error::custom)?, @@ -117,10 +117,7 @@ impl<'a> Visitor<'a> for InputVisitor { #[cfg(test)] mod tests { - use std::collections::BTreeMap; - use serde_json; - use bytes::Bytes; - use super::Input; + use super::{BTreeMap, Bytes, Input}; #[test] fn input_deserialization_from_map() { diff --git a/json/src/trie/trie.rs b/json/src/test_helpers/trie/mod.rs similarity index 84% rename from json/src/trie/trie.rs rename to json/src/test_helpers/trie/mod.rs index 756e54f43..29bb55531 100644 --- a/json/src/trie/trie.rs +++ b/json/src/test_helpers/trie/mod.rs @@ -16,8 +16,15 @@ //! Trie test deserialization. -use hash::H256; -use trie::Input; +mod input; + +pub use self::input::Input; + +/// Type used by `trie` tests +pub type Test = super::tester::GenericTester; + +use serde::Deserialize; +use crate::hash::H256; /// Trie test deserialization. #[derive(Debug, Deserialize, PartialEq)] diff --git a/json/src/transaction/transaction.rs b/json/src/transaction.rs similarity index 56% rename from json/src/transaction/transaction.rs rename to json/src/transaction.rs index 718d3080b..84a496c5a 100644 --- a/json/src/transaction/transaction.rs +++ b/json/src/transaction.rs @@ -14,14 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! Transaction test transaction deserialization. +//! Transaction deserialization. -use uint::Uint; -use bytes::Bytes; -use hash::Address; -use maybe::MaybeEmpty; +use crate::{bytes::Bytes, hash::{Address, H256}, maybe::MaybeEmpty, uint::Uint}; +use serde::Deserialize; -/// Transaction test transaction deserialization. +/// Unsigned transaction with signing information deserialization. #[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Transaction { @@ -43,12 +41,15 @@ pub struct Transaction { pub s: Uint, /// V. pub v: Uint, + /// Secret + #[serde(rename = "secretKey")] + pub secret: Option, } #[cfg(test)] mod tests { - use serde_json; - use transaction::Transaction; + use super::{Bytes, H256, MaybeEmpty, Transaction, Uint}; + use ethereum_types::{H256 as Eth256, U256}; #[test] fn transaction_deserialization() { @@ -57,13 +58,23 @@ mod tests { "gasLimit" : "0xf388", "gasPrice" : "0x09184e72a000", "nonce" : "0x00", - "r" : "0x2c", - "s" : "0x04", "to" : "", - "v" : "0x1b", - "value" : "0x00" + "value" : "0x00", + "r": 0, + "s": 1, + "v": 2, + "secretKey": "0x0000000000000000000000000000000000000000000000000000000000000000" }"#; - let _deserialized: Transaction = serde_json::from_str(s).unwrap(); - // TODO: validate all fields + let tx: Transaction = serde_json::from_str(s).unwrap(); + assert_eq!(tx.data, Bytes::new(Vec::new())); + assert_eq!(tx.gas_limit, Uint(U256::from(0xf388))); + assert_eq!(tx.gas_price, Uint(U256::from(0x09184e72a000_u64))); + assert_eq!(tx.nonce, Uint(U256::zero())); + assert_eq!(tx.to, MaybeEmpty::None); + assert_eq!(tx.value, Uint(U256::zero())); + assert_eq!(tx.r, Uint(U256::zero())); + assert_eq!(tx.s, Uint(U256::one())); + assert_eq!(tx.v, Uint(U256::from(2))); + assert_eq!(tx.secret, Some(H256(Eth256::zero()))); } } diff --git a/json/src/transaction/mod.rs b/json/src/transaction/mod.rs deleted file mode 100644 index f845fe334..000000000 --- a/json/src/transaction/mod.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Transaction test deserialization. - -mod transaction; -mod txtest; -mod test; - -pub use self::transaction::Transaction; -pub use self::txtest::TransactionTest; -pub use self::test::Test; diff --git a/json/src/transaction/test.rs b/json/src/transaction/test.rs deleted file mode 100644 index ee9d4110f..000000000 --- a/json/src/transaction/test.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! TransactionTest test deserializer. - -use std::collections::BTreeMap; -use std::io::Read; -use serde_json; -use serde_json::Error; -use transaction::TransactionTest; - -/// TransactionTest test deserializer. -#[derive(Debug, Deserialize)] -pub struct Test(BTreeMap); - -impl IntoIterator for Test { - type Item = as IntoIterator>::Item; - type IntoIter = as IntoIterator>::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} - -impl Test { - /// Loads test from json. - pub fn load(reader: R) -> Result where R: Read { - serde_json::from_reader(reader) - } -} diff --git a/json/src/trie/mod.rs b/json/src/trie/mod.rs deleted file mode 100644 index 68fec0876..000000000 --- a/json/src/trie/mod.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Trie test deserialization. - -mod input; -mod trie; -mod test; - -pub use self::input::Input; -pub use self::trie::Trie; -pub use self::test::Test; diff --git a/json/src/trie/test.rs b/json/src/trie/test.rs deleted file mode 100644 index 39876da0a..000000000 --- a/json/src/trie/test.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! TransactionTest test deserializer. - -use std::collections::BTreeMap; -use std::io::Read; -use serde_json; -use serde_json::Error; -use trie::Trie; - -/// TransactionTest test deserializer. -#[derive(Debug, PartialEq, Deserialize)] -pub struct Test(BTreeMap); - -impl IntoIterator for Test { - type Item = as IntoIterator>::Item; - type IntoIter = as IntoIterator>::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} - -impl Test { - /// Loads test from json. - pub fn load(reader: R) -> Result where R: Read { - serde_json::from_reader(reader) - } -} diff --git a/json/src/uint.rs b/json/src/uint.rs index 3428fd56c..8cba3f1dd 100644 --- a/json/src/uint.rs +++ b/json/src/uint.rs @@ -92,6 +92,7 @@ impl<'a> Visitor<'a> for UintVisitor { } } +/// Deserialize and validate that the value is non-zero pub fn validate_non_zero<'de, D>(d: D) -> Result where D: Deserializer<'de> { let value = Uint::deserialize(d)?; @@ -102,6 +103,7 @@ pub fn validate_non_zero<'de, D>(d: D) -> Result where D: Deseri Ok(value) } +/// Deserialize and validate that the value is non-zero pub fn validate_optional_non_zero<'de, D>(d: D) -> Result, D::Error> where D: Deserializer<'de> { let value: Option = Option::deserialize(d)?; @@ -116,9 +118,8 @@ pub fn validate_optional_non_zero<'de, D>(d: D) -> Result, D::Error #[cfg(test)] mod test { - use serde_json; + use super::Uint; use ethereum_types::U256; - use uint::Uint; #[test] fn uint_deserialization() { diff --git a/json/src/vm.rs b/json/src/vm.rs new file mode 100644 index 000000000..f4bc791c1 --- /dev/null +++ b/json/src/vm.rs @@ -0,0 +1,272 @@ +// Copyright 2015-2019 Parity Technologies (UK) Ltd. +// This file is part of Parity Ethereum. + +// Parity Ethereum is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity Ethereum is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity Ethereum. If not, see . + +//! Vm json deserialization + +use crate::{ + bytes::Bytes, + hash::{Address, H256}, + maybe::MaybeEmpty, + spec::State, + uint::Uint, +}; +use serde::Deserialize; + +/// Represents vm execution environment before and after execution of transaction. +#[derive(Debug, PartialEq, Deserialize)] +pub struct Vm { + /// Contract calls made internaly by executed transaction. + #[serde(rename = "callcreates")] + pub calls: Option>, + /// Env info. + pub env: Env, + /// Executed transaction + #[serde(rename = "exec")] + pub transaction: Transaction, + /// Gas left after transaction execution. + #[serde(rename = "gas")] + pub gas_left: Option, + /// Hash of logs created during execution of transaction. + pub logs: Option, + /// Transaction output. + #[serde(rename = "out")] + pub output: Option, + /// Post execution vm state. + #[serde(rename = "post")] + pub post_state: Option, + /// Pre execution vm state. + #[serde(rename = "pre")] + pub pre_state: State, +} + +impl Vm { + /// Returns true if transaction execution run out of gas. + pub fn out_of_gas(&self) -> bool { + self.calls.is_none() + } +} + +/// Call deserialization. +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Call { + /// Call data. + pub data: Bytes, + /// Call destination. + pub destination: MaybeEmpty
, + /// Gas limit. + pub gas_limit: Uint, + /// Call value. + pub value: Uint, +} + +/// Executed transaction. +#[derive(Debug, PartialEq, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Transaction { + /// Contract address. + pub address: Address, + /// Transaction sender. + #[serde(rename = "caller")] + pub sender: Address, + /// Contract code. + pub code: Bytes, + /// Input data. + pub data: Bytes, + /// Gas. + pub gas: Uint, + /// Gas price. + pub gas_price: Uint, + /// Transaction origin. + pub origin: Address, + /// Sent value. + pub value: Uint, + /// Contract code version. + #[serde(default)] + pub code_version: Uint, +} + +/// Environment. +#[derive(Debug, PartialEq, Deserialize)] +pub struct Env { + /// Address. + #[serde(rename = "currentCoinbase")] + pub author: Address, + /// Difficulty + #[serde(rename = "currentDifficulty")] + pub difficulty: Uint, + /// Gas limit. + #[serde(rename = "currentGasLimit")] + pub gas_limit: Uint, + /// Number. + #[serde(rename = "currentNumber")] + pub number: Uint, + /// Timestamp. + #[serde(rename = "currentTimestamp")] + pub timestamp: Uint, +} + +#[cfg(test)] +mod tests { + use std::{ + collections::BTreeMap, + str::FromStr + }; + use super::{Address, Bytes, Call, Env, H256, MaybeEmpty, State, Transaction, Uint, Vm}; + + use crate::spec::Account; + use ethereum_types::{U256, H160 as Hash160, H256 as Hash256}; + use macros::map; + use rustc_hex::FromHex; + + const TEST_CODE: &str = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055"; + + #[test] + fn vm_deserialization() { + let s = r#"{ + "callcreates" : [ + ], + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x0100", + "currentGasLimit" : "0x0f4240", + "currentNumber" : "0x00", + "currentTimestamp" : "0x01" + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "caller" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055", + "data" : "0x", + "gas" : "0x0186a0", + "gasPrice" : "0x5af3107a4000", + "origin" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "value" : "0x0de0b6b3a7640000" + }, + "gas" : "0x013874", + "logs" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "out" : "0x", + "post" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055", + "nonce" : "0x00", + "storage" : { + "0x00" : "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" + } + } + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055", + "nonce" : "0x00", + "storage" : { + } + } + } + }"#; + let vm: Vm = serde_json::from_str(s).unwrap(); + assert_eq!(vm.calls, Some(Vec::new())); + assert_eq!(vm.env, Env { + author: Address(Hash160::from_str("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").unwrap()), + difficulty: Uint(0x0100.into()), + gas_limit: Uint(0x0f4240.into()), + number: Uint(0.into()), + timestamp: Uint(1.into()) + }); + assert_eq!(vm.transaction, Transaction { + address: Address(Hash160::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap()), + sender: Address(Hash160::from_str("cd1722f2947def4cf144679da39c4c32bdc35681").unwrap()), + code: Bytes::new(TEST_CODE.from_hex().unwrap()), + code_version: Uint(0.into()), + data: Bytes::new(Vec::new()), + gas: Uint(0x0186a0.into()), + gas_price: Uint(0x5af3107a4000_u64.into()), + origin: Address(Hash160::from_str("cd1722f2947def4cf144679da39c4c32bdc35681").unwrap()), + value: Uint(0x0de0b6b3a7640000_u64.into()) + }); + assert_eq!(vm.gas_left, Some(Uint(0x013874.into()))); + assert_eq!( + vm.logs, + Some(H256(Hash256::from_str("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").unwrap())) + ); + assert_eq!(vm.output, Some(Bytes::new(Vec::new()))); + assert_eq!(vm.pre_state, State(map![ + Address(Hash160::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap()) => Account { + builtin: None, + balance: Some(Uint(0x0de0b6b3a7640000_u64.into())), + code: Some(Bytes::new(TEST_CODE.from_hex().unwrap())), + constructor: None, + nonce: Some(Uint(0.into())), + storage: Some(map![]), + version: None, + }]) + ); + assert_eq!(vm.post_state, Some( + State(map![ + Address(Hash160::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap()) => Account { + builtin: None, + balance: Some(Uint(0x0de0b6b3a7640000_u64.into())), + code: Some(Bytes::new(TEST_CODE.from_hex().unwrap())), + constructor: None, + nonce: Some(Uint(0.into())), + storage: Some(map![ + Uint(0.into()) => Uint(U256::from_str("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe").unwrap()) + ]), + version: None, + }]) + ) + ); + } + + #[test] + fn call_deserialization_empty_dest() { + let s = r#"{ + "data" : "0x1111222233334444555566667777888899990000aaaabbbbccccddddeeeeffff", + "destination" : "", + "gasLimit" : "0x1748766aa5", + "value" : "0x00" + }"#; + 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/json/src/vm/call.rs b/json/src/vm/call.rs deleted file mode 100644 index aa75862f0..000000000 --- a/json/src/vm/call.rs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Vm call deserialization. - -use bytes::Bytes; -use hash::Address; -use uint::Uint; -use maybe::MaybeEmpty; - -/// Vm call deserialization. -#[derive(Debug, PartialEq, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Call { - /// Call data. - pub data: Bytes, - /// Call destination. - pub destination: MaybeEmpty
, - /// Gas limit. - pub gas_limit: Uint, - /// Call value. - pub value: Uint, -} - -#[cfg(test)] -mod tests { - use serde_json; - use vm::Call; - use ethereum_types::{U256, H160 as Hash160}; - use uint::Uint; - use hash::Address; - use maybe::MaybeEmpty; - use std::str::FromStr; - - #[test] - fn call_deserialization_empty_dest() { - let s = r#"{ - "data" : "0x1111222233334444555566667777888899990000aaaabbbbccccddddeeeeffff", - "destination" : "", - "gasLimit" : "0x1748766aa5", - "value" : "0x00" - }"#; - 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/json/src/vm/env.rs b/json/src/vm/env.rs deleted file mode 100644 index e06812c0a..000000000 --- a/json/src/vm/env.rs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Vm environment. -use hash::Address; -use uint::Uint; - -/// Vm environment. -#[derive(Debug, PartialEq, Deserialize)] -pub struct Env { - /// Address. - #[serde(rename = "currentCoinbase")] - pub author: Address, - /// Difficulty - #[serde(rename = "currentDifficulty")] - pub difficulty: Uint, - /// Gas limit. - #[serde(rename = "currentGasLimit")] - pub gas_limit: Uint, - /// Number. - #[serde(rename = "currentNumber")] - pub number: Uint, - /// Timestamp. - #[serde(rename = "currentTimestamp")] - pub timestamp: Uint, -} - -#[cfg(test)] -mod tests { - use serde_json; - use vm::Env; - - #[test] - fn env_deserialization() { - let s = r#"{ - "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", - "currentDifficulty" : "0x0100", - "currentGasLimit" : "0x0f4240", - "currentNumber" : "0x00", - "currentTimestamp" : "0x01" - }"#; - let _deserialized: Env = serde_json::from_str(s).unwrap(); - // TODO: validate all fields - } -} diff --git a/json/src/vm/mod.rs b/json/src/vm/mod.rs deleted file mode 100644 index d8f99e200..000000000 --- a/json/src/vm/mod.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Vm test loader. - -pub mod env; -pub mod transaction; -pub mod vm; -pub mod call; -pub mod test; - -pub use self::env::Env; -pub use self::transaction::Transaction; -pub use self::vm::Vm; -pub use self::call::Call; -pub use self::test::Test; diff --git a/json/src/vm/test.rs b/json/src/vm/test.rs deleted file mode 100644 index 9dfe814ae..000000000 --- a/json/src/vm/test.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Vm test deserializer. - -use std::collections::BTreeMap; -use std::io::Read; -use serde_json; -use serde_json::Error; -use vm::Vm; - -/// Vm test deserializer. -#[derive(Debug, PartialEq, Deserialize)] -pub struct Test(BTreeMap); - -impl IntoIterator for Test { - type Item = as IntoIterator>::Item; - type IntoIter = as IntoIterator>::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } -} - -impl Test { - /// Loads test from json. - pub fn load(reader: R) -> Result where R: Read { - serde_json::from_reader(reader) - } -} diff --git a/json/src/vm/transaction.rs b/json/src/vm/transaction.rs deleted file mode 100644 index 10ca308df..000000000 --- a/json/src/vm/transaction.rs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Executed transaction. -use hash::Address; -use uint::Uint; -use bytes::Bytes; - -/// Executed transaction. -#[derive(Debug, PartialEq, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Transaction { - /// Contract address. - pub address: Address, - /// Transaction sender. - #[serde(rename = "caller")] - pub sender: Address, - /// Contract code. - pub code: Bytes, - /// Input data. - pub data: Bytes, - /// Gas. - pub gas: Uint, - /// Gas price. - pub gas_price: Uint, - /// Transaction origin. - pub origin: Address, - /// Sent value. - pub value: Uint, - /// Contract code version. - #[serde(default)] - pub code_version: Uint, -} - -#[cfg(test)] -mod tests { - use serde_json; - use vm::Transaction; - - #[test] - fn transaction_deserialization() { - let s = r#"{ - "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", - "caller" : "cd1722f2947def4cf144679da39c4c32bdc35681", - "code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055", - "data" : "0x", - "gas" : "0x0186a0", - "gasPrice" : "0x5af3107a4000", - "origin" : "cd1722f2947def4cf144679da39c4c32bdc35681", - "value" : "0x0de0b6b3a7640000" - }"#; - let _deserialized: Transaction = serde_json::from_str(s).unwrap(); - } -} diff --git a/json/src/vm/vm.rs b/json/src/vm/vm.rs deleted file mode 100644 index 1fbb937cb..000000000 --- a/json/src/vm/vm.rs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . - -//! Vm execution env. - -use bytes::Bytes; -use uint::Uint; -use hash::H256; -use blockchain::State; -use vm::{Transaction, Call, Env}; - -/// Represents vm execution environment before and after execution of transaction. -#[derive(Debug, PartialEq, Deserialize)] -pub struct Vm { - /// Contract calls made internaly by executed transaction. - #[serde(rename = "callcreates")] - pub calls: Option>, - /// Env info. - pub env: Env, - /// Executed transaction - #[serde(rename = "exec")] - pub transaction: Transaction, - /// Gas left after transaction execution. - #[serde(rename = "gas")] - pub gas_left: Option, - /// Hash of logs created during execution of transaction. - pub logs: Option, - /// Transaction output. - #[serde(rename = "out")] - pub output: Option, - /// Post execution vm state. - #[serde(rename = "post")] - pub post_state: Option, - /// Pre execution vm state. - #[serde(rename = "pre")] - pub pre_state: State, -} - -impl Vm { - /// Returns true if transaction execution run out of gas. - pub fn out_of_gas(&self) -> bool { - self.calls.is_none() - } -} - -#[cfg(test)] -mod tests { - use serde_json; - use vm::Vm; - - #[test] - fn vm_deserialization() { - let s = r#"{ - "callcreates" : [ - ], - "env" : { - "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", - "currentDifficulty" : "0x0100", - "currentGasLimit" : "0x0f4240", - "currentNumber" : "0x00", - "currentTimestamp" : "0x01" - }, - "exec" : { - "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", - "caller" : "cd1722f2947def4cf144679da39c4c32bdc35681", - "code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055", - "data" : "0x", - "gas" : "0x0186a0", - "gasPrice" : "0x5af3107a4000", - "origin" : "cd1722f2947def4cf144679da39c4c32bdc35681", - "value" : "0x0de0b6b3a7640000" - }, - "gas" : "0x013874", - "logs" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", - "out" : "0x", - "network" : "Frontier", - "post" : { - "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { - "balance" : "0x0de0b6b3a7640000", - "code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055", - "nonce" : "0x00", - "storage" : { - "0x00" : "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" - } - } - }, - "pre" : { - "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { - "balance" : "0x0de0b6b3a7640000", - "code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055", - "nonce" : "0x00", - "storage" : { - } - } - } - }"#; - let _deserialized: Vm = serde_json::from_str(s).unwrap(); - // TODO: validate all fields - } -} diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index aa555d75f..f332dbe7a 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -75,6 +75,7 @@ ethcore = { path = "../ethcore", features = ["test-helpers"] } ethcore-accounts = { path = "../accounts" } ethcore-io = { path = "../util/io" } ethcore-network = { path = "../util/network" } +ethjson = { path = "../json", features = ["test-helpers"] } fake-fetch = { path = "../util/fake-fetch" } macros = { path = "../util/macros" } spec = { path = "../ethcore/spec" } diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index 062acb10d..56d46d02f 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -15,8 +15,8 @@ // along with Parity Ethereum. If not, see . //! rpc integration tests. -use std::env; -use std::sync::Arc; + +use std::{env, sync::Arc}; use accounts::AccountProvider; use client_traits::{BlockChainClient, ChainInfo, ImportBlock}; @@ -26,7 +26,7 @@ use spec::{Genesis, Spec, self}; use ethcore::test_helpers; use verification::VerifierType; use ethereum_types::{Address, H256, U256}; -use ethjson::blockchain::BlockChain; +use ethjson::test_helpers::blockchain::BlockChain; use ethjson::spec::ForkSpec; use io::IoChannel; use miner::external::ExternalMiner; @@ -85,7 +85,7 @@ struct EthTester { impl EthTester { fn from_chain(chain: &BlockChain) -> Self { - let tester = if ::ethjson::blockchain::Engine::NoProof == chain.engine { + let tester = if ethjson::test_helpers::blockchain::Engine::NoProof == chain.engine { let mut config = ClientConfig::default(); config.verifier_type = VerifierType::CanonNoSeal; config.check_seal = false; diff --git a/rpc/src/v1/tests/mod.rs b/rpc/src/v1/tests/mod.rs index 83f9dca90..76e89e8bc 100644 --- a/rpc/src/v1/tests/mod.rs +++ b/rpc/src/v1/tests/mod.rs @@ -32,7 +32,7 @@ macro_rules! extract_chain { (iter $file:expr) => {{ const RAW_DATA: &'static [u8] = include_bytes!(concat!("../../../../ethcore/res/ethereum/tests/", $file, ".json")); - ::ethjson::blockchain::Test::load(RAW_DATA).unwrap().into_iter() + ethjson::test_helpers::blockchain::Test::load(RAW_DATA).unwrap().into_iter() }}; ($file:expr) => {{