rpctest executable
This commit is contained in:
parent
5e44769f82
commit
f92a0c8df2
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -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)",
|
||||
]
|
||||
|
||||
|
@ -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
|
||||
|
@ -31,6 +31,13 @@ pub struct Block {
|
||||
uncles: Vec<Header>,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
/// Returns block rlp.
|
||||
pub fn rlp(&self) -> Vec<u8> {
|
||||
self.rlp.clone().into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json;
|
||||
|
@ -35,6 +35,18 @@ pub struct BlockChain {
|
||||
pre_state: State,
|
||||
}
|
||||
|
||||
impl BlockChain {
|
||||
/// Returns genesis block rlp.
|
||||
pub fn genesis_rlp(&self) -> Vec<u8> {
|
||||
self.genesis_rlp.clone().into()
|
||||
}
|
||||
|
||||
/// Returns blocks rlp.
|
||||
pub fn blocks_rlp(&self) -> Vec<Vec<u8>> {
|
||||
self.blocks.iter().map(|block| block.rlp()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json;
|
||||
|
@ -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;
|
||||
|
@ -21,6 +21,7 @@ use std::ops::Deref;
|
||||
use blockchain::blockchain::BlockChain;
|
||||
|
||||
/// Blockchain test deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Test(BTreeMap<String, BlockChain>);
|
||||
|
||||
impl Deref for Test {
|
||||
|
@ -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<u8>);
|
||||
|
||||
impl Into<Vec<u8>> for Bytes {
|
||||
|
80
parity/rpctest.rs
Normal file
80
parity/rpctest.rs
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 <test-file> --name <test-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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user