From 3e6d0602ea86fb664f2704a97aea5f452ed6bfbf Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 17 Mar 2016 23:58:30 +0100 Subject: [PATCH] running rpc tests --- parity/rpctest.rs | 57 ++++++++++++++++++++++++++++++++++++++--- rpc/src/v1/mod.rs | 3 +-- rpc/src/v1/tests/mod.rs | 6 ++++- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/parity/rpctest.rs b/parity/rpctest.rs index ca12eed93..d972a779e 100644 --- a/parity/rpctest.rs +++ b/parity/rpctest.rs @@ -14,19 +14,32 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +extern crate ctrlc; extern crate docopt; extern crate rustc_serialize; extern crate serde_json; extern crate ethjson; +extern crate ethcore_util as util; extern crate ethcore; +extern crate ethcore_devtools as devtools; +extern crate ethcore_rpc as rpc; +use std::collections::HashMap; +use std::sync::{Arc, Mutex, Condvar}; use std::process; use std::fs::File; use std::path::Path; use docopt::Docopt; +use ctrlc::CtrlC; use ethcore::spec::Genesis; use ethcore::pod_state::PodState; use ethcore::ethereum; +use ethcore::client::{BlockChainClient, Client, ClientConfig}; +use devtools::RandomTempPath; +use util::io::IoChannel; +use rpc::v1::tests::helpers::{TestSyncProvider, Config as SyncConfig, TestMinerService, TestAccountProvider}; +use rpc::v1::{Eth, EthClient}; +use util::panics::MayPanic; const USAGE: &'static str = r#" Parity rpctest client. @@ -34,13 +47,22 @@ Parity rpctest client. Copyright 2015, 2016 Ethcore (UK) Limited Usage: - parity --json --name + parity --json --name [options] + parity --help + +Options: + --jsonrpc-addr HOST Specify the hostname portion of the JSONRPC API + server [default: 127.0.0.1]. + --jsonrpc-port PORT Specify the port portion of the JSONRPC API server + [default: 8545]. "#; #[derive(Debug, RustcDecodable)] struct Args { arg_test_file: String, arg_test_name: String, + flag_jsonrpc_addr: String, + flag_jsonrpc_port: u16, } struct Configuration { @@ -81,8 +103,37 @@ impl Configuration { spec.overwrite_genesis_params(genesis); assert!(spec.is_state_root_valid()); - //let temp = RandomTempPath::new(); - //spec. + let temp = RandomTempPath::new(); + { + let client: Arc = Client::new(ClientConfig::default(), spec, temp.as_path(), IoChannel::disconnected()).unwrap(); + for b in &blockchain.blocks_rlp() { + let _ = client.import_block(b.clone()); + client.flush_queue(); + client.import_verified_blocks(&IoChannel::disconnected()); + } + let sync = Arc::new(TestSyncProvider::new(SyncConfig { + protocol_version: 65, + num_peers: 120 + })); + + let miner = Arc::new(TestMinerService::default()); + let accounts = Arc::new(TestAccountProvider::new(HashMap::new())); + let server = rpc::RpcServer::new(); + server.add_delegate(EthClient::new(&client, &sync, &accounts, &miner).to_delegate()); + + let url = format!("{}:{}", self.args.flag_jsonrpc_addr, self.args.flag_jsonrpc_port); + let panic_handler = server.start_http(url.as_ref(), "*", 1); + let exit = Arc::new(Condvar::new()); + + let e = exit.clone(); + CtrlC::set_handler(move || { e.notify_all(); }); + + let e = exit.clone(); + panic_handler.on_panic(move |_reason| { e.notify_all(); }); + + let mutex = Mutex::new(()); + let _ = exit.wait(mutex.lock().unwrap()).unwrap(); + } } } diff --git a/rpc/src/v1/mod.rs b/rpc/src/v1/mod.rs index b82a20e89..c81f58156 100644 --- a/rpc/src/v1/mod.rs +++ b/rpc/src/v1/mod.rs @@ -23,8 +23,7 @@ mod impls; mod types; mod helpers; -#[cfg(test)] -mod tests; +pub mod tests; pub use self::traits::{Web3, Eth, EthFilter, Personal, Net}; pub use self::impls::*; diff --git a/rpc/src/v1/tests/mod.rs b/rpc/src/v1/tests/mod.rs index 21085a0fd..7a6340ce1 100644 --- a/rpc/src/v1/tests/mod.rs +++ b/rpc/src/v1/tests/mod.rs @@ -16,8 +16,12 @@ //!TODO: load custom blockchain state and test +pub mod helpers; +#[cfg(test)] mod eth; +#[cfg(test)] mod net; +#[cfg(test)] mod web3; -mod helpers; +#[cfg(test)] mod personal;