From f92a0c8df296c83c69d7a78ba0502153f79744e0 Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 17 Mar 2016 11:50:31 +0100 Subject: [PATCH] rpctest executable --- Cargo.lock | 1 + Cargo.toml | 5 ++ json/src/blockchain/block.rs | 7 +++ json/src/blockchain/blockchain.rs | 12 +++++ json/src/blockchain/mod.rs | 8 ++++ json/src/blockchain/test.rs | 1 + json/src/bytes.rs | 2 +- parity/rpctest.rs | 80 +++++++++++++++++++++++++++++++ 8 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 parity/rpctest.rs diff --git a/Cargo.lock b/Cargo.lock index 79ca26582..1a701042e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,7 @@ dependencies = [ "rpassword 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index fd1d16cff..d00f1ff60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ ethminer = { path = "miner" } ethcore-devtools = { path = "devtools" } ethcore-rpc = { path = "rpc", optional = true } ethjson = { path = "json" } +serde_json = "0.7.0" [features] default = ["rpc"] @@ -40,6 +41,10 @@ travis-nightly = ["ethcore/json-tests", "dev"] path = "parity/main.rs" name = "parity" +[[bin]] +path = "parity/rpctest.rs" +name = "rpctest" + [profile.release] debug = false lto = false diff --git a/json/src/blockchain/block.rs b/json/src/blockchain/block.rs index ed297077c..190102ae5 100644 --- a/json/src/blockchain/block.rs +++ b/json/src/blockchain/block.rs @@ -31,6 +31,13 @@ pub struct Block { uncles: Vec
, } +impl Block { + /// Returns block rlp. + pub fn rlp(&self) -> Vec { + self.rlp.clone().into() + } +} + #[cfg(test)] mod tests { use serde_json; diff --git a/json/src/blockchain/blockchain.rs b/json/src/blockchain/blockchain.rs index f6b1259ca..8c67799e1 100644 --- a/json/src/blockchain/blockchain.rs +++ b/json/src/blockchain/blockchain.rs @@ -35,6 +35,18 @@ pub struct BlockChain { pre_state: State, } +impl BlockChain { + /// Returns genesis block rlp. + pub fn genesis_rlp(&self) -> Vec { + self.genesis_rlp.clone().into() + } + + /// Returns blocks rlp. + pub fn blocks_rlp(&self) -> Vec> { + self.blocks.iter().map(|block| block.rlp()).collect() + } +} + #[cfg(test)] mod tests { use serde_json; diff --git a/json/src/blockchain/mod.rs b/json/src/blockchain/mod.rs index 046b2e534..727469ea2 100644 --- a/json/src/blockchain/mod.rs +++ b/json/src/blockchain/mod.rs @@ -23,3 +23,11 @@ pub mod header; pub mod state; pub mod transaction; pub mod test; + +pub use self::account::Account; +pub use self::block::Block; +pub use self::blockchain::BlockChain; +pub use self::header::Header; +pub use self::state::State; +pub use self::test::Test; +pub use self::transaction::Transaction; diff --git a/json/src/blockchain/test.rs b/json/src/blockchain/test.rs index 6097a60e6..6f48a8bc6 100644 --- a/json/src/blockchain/test.rs +++ b/json/src/blockchain/test.rs @@ -21,6 +21,7 @@ use std::ops::Deref; use blockchain::blockchain::BlockChain; /// Blockchain test deserializer. +#[derive(Debug, PartialEq, Deserialize)] pub struct Test(BTreeMap); impl Deref for Test { diff --git a/json/src/bytes.rs b/json/src/bytes.rs index 28b7636d4..061795b40 100644 --- a/json/src/bytes.rs +++ b/json/src/bytes.rs @@ -21,7 +21,7 @@ use serde::{Deserialize, Deserializer, Error}; use serde::de::Visitor; /// Lenient bytes json deserialization for test json files. -#[derive(Default, Debug, PartialEq)] +#[derive(Default, Debug, PartialEq, Clone)] pub struct Bytes(Vec); impl Into> for Bytes { diff --git a/parity/rpctest.rs b/parity/rpctest.rs new file mode 100644 index 000000000..182f6dfed --- /dev/null +++ b/parity/rpctest.rs @@ -0,0 +1,80 @@ +// Copyright 2015, 2016 Ethcore (UK) Ltd. +// This file is part of Parity. + +// Parity 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 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. If not, see . + +extern crate docopt; +extern crate rustc_serialize; +extern crate serde_json; +extern crate ethjson; + +use std::process; +use std::fs::File; +use std::path::Path; +use docopt::Docopt; + +const USAGE: &'static str = r#" +Parity rpctest client. + By Wood/Paronyan/Kotewicz/Drwięga/Volf. + Copyright 2015, 2016 Ethcore (UK) Limited + +Usage: + parity --json --name +"#; + +#[derive(Debug, RustcDecodable)] +struct Args { + arg_test_file: String, + arg_test_name: String, +} + +struct Configuration { + args: Args, +} + +impl Configuration { + fn parse() -> Self { + Configuration { + args: Docopt::new(USAGE).and_then(|d| d.decode()).unwrap_or_else(|e| e.exit()) + } + } + + fn execute(&self) { + println!("file path: {:?}", self.args.arg_test_file); + println!("test name: {:?}", self.args.arg_test_name); + + let path = Path::new(&self.args.arg_test_file); + let file = File::open(path).unwrap_or_else(|_| { + println!("Cannot open file."); + process::exit(1); + }); + + let tests: ethjson::blockchain::Test = serde_json::from_reader(file).unwrap_or_else(|_| { + println!("Invalid json file."); + process::exit(2); + }); + + let blockchain = tests.get(&self.args.arg_test_name).unwrap_or_else(|| { + println!("Invalid test name."); + process::exit(3); + }); + + + + } +} + +fn main() { + Configuration::parse().execute(); +}