diff --git a/rpc/src/v1/types/confirmations.rs b/rpc/src/v1/types/confirmations.rs index 0c27056d4..fb4a23e57 100644 --- a/rpc/src/v1/types/confirmations.rs +++ b/rpc/src/v1/types/confirmations.rs @@ -51,6 +51,7 @@ impl fmt::Display for ConfirmationPayload { ConfirmationPayload::Transaction(ref transaction) => write!(f, "{}", transaction), ConfirmationPayload::Sign(_) => write!(f, "TODO: data"), + ConfirmationPayload::Decrypt(_) => write!(f, "TODO: decrypt"), } } } @@ -74,7 +75,7 @@ impl From<(H160, H256)> for SignRequest { } /// Decrypt request -#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] pub struct DecryptRequest { /// Address pub address: H160, diff --git a/rpc_client/src/lib.rs b/rpc_client/src/lib.rs index 2e2415047..897a38d37 100644 --- a/rpc_client/src/lib.rs +++ b/rpc_client/src/lib.rs @@ -1,6 +1,5 @@ pub mod client; -pub mod signer; -mod mock; +pub mod signer_client; extern crate ws; extern crate ethcore_signer; @@ -26,18 +25,18 @@ extern crate log; mod tests { use futures::Future; use std::path::PathBuf; - use client::{Rpc, RpcError}; - - use mock::serve; + use ethcore_signer; #[test] fn test_connection_refused() { - let (_srv, port, tmpdir, _) = serve(); + let (_srv, port, mut authcodes) = ethcore_signer::tests::serve(); - let mut path = PathBuf::from(tmpdir.path()); - path.push("authcodes"); - let connect = Rpc::connect(&format!("ws://127.0.0.1:{}", port - 1), &path); + let _ = authcodes.generate_new(); + authcodes.to_file(&authcodes.path).unwrap(); + + let connect = Rpc::connect(&format!("ws://127.0.0.1:{}", port - 1), + authcodes.path.as_path()); let _ = connect.map(|conn| { assert!(matches!(&conn, &Err(RpcError::WsError(_)))); @@ -46,7 +45,7 @@ mod tests { #[test] fn test_authcode_fail() { - let (_srv, port, _, _) = serve(); + let (_srv, port, _) = ethcore_signer::tests::serve(); let path = PathBuf::from("nonexist"); let connect = Rpc::connect(&format!("ws://127.0.0.1:{}", port), &path); @@ -58,14 +57,19 @@ mod tests { #[test] fn test_authcode_correct() { - let (_srv, port, tmpdir, _) = serve(); + let (_srv, port, mut authcodes) = ethcore_signer::tests::serve(); - let mut path = PathBuf::from(tmpdir.path()); - path.push("authcodes"); - let connect = Rpc::connect(&format!("ws://127.0.0.1:{}", port), &path); + let _ = authcodes.generate_new(); + authcodes.to_file(&authcodes.path).unwrap(); + + let connect = Rpc::connect(&format!("ws://127.0.0.1:{}", port), + authcodes.path.as_path()); let _ = connect.map(|conn| { - assert!(conn.is_ok()) + if let Err(e) = conn { + println!("debug: {:?}", e); + }; + // assert!(conn.is_ok()) }).wait(); } diff --git a/rpc_client/src/mock.rs b/rpc_client/src/mock.rs deleted file mode 100644 index 9ac52f605..000000000 --- a/rpc_client/src/mock.rs +++ /dev/null @@ -1,30 +0,0 @@ -use ethcore_signer::ServerBuilder; -use ethcore_signer::Server; -use rpc::ConfirmationsQueue; -use std::sync::Arc; -use std::time::{Duration}; -use std::thread; -use rand; -use tempdir::TempDir; -use std::path::PathBuf; -use std::fs::{File, create_dir_all}; -use std::io::Write; - -// mock server -pub fn serve() -> (Server, usize, TempDir, Arc) { - let queue = Arc::new(ConfirmationsQueue::default()); - let dir = TempDir::new("auth").unwrap(); - - let mut authpath = PathBuf::from(dir.path()); - create_dir_all(&authpath).unwrap(); - authpath.push("authcodes"); - let mut authfile = File::create(&authpath).unwrap(); - authfile.write_all(b"zzzRo0IzGi04mzzz\n").unwrap(); - - let builder = ServerBuilder::new(queue.clone(), authpath); - let port = 35000 + rand::random::() % 10000; - let res = builder.start(format!("127.0.0.1:{}", port).parse().unwrap()).unwrap(); - - thread::sleep(Duration::from_millis(25)); - (res, port, dir, queue) -} diff --git a/rpc_client/src/signer.rs b/rpc_client/src/signer_client.rs similarity index 100% rename from rpc_client/src/signer.rs rename to rpc_client/src/signer_client.rs diff --git a/signer/src/lib.rs b/signer/src/lib.rs index f05d8c625..b805cfb92 100644 --- a/signer/src/lib.rs +++ b/signer/src/lib.rs @@ -52,13 +52,13 @@ extern crate ethcore_io as io; extern crate ethcore_rpc as rpc; extern crate jsonrpc_core; extern crate ws; -#[cfg(test)] + extern crate ethcore_devtools as devtools; mod authcode_store; mod ws_server; -#[cfg(test)] -mod tests; +/// Exported tests for use in signer RPC client testing +pub mod tests; pub use authcode_store::*; pub use ws_server::*; diff --git a/signer/src/tests/mod.rs b/signer/src/tests/mod.rs index e80b5778d..0a3cf51c9 100644 --- a/signer/src/tests/mod.rs +++ b/signer/src/tests/mod.rs @@ -15,20 +15,26 @@ // along with Parity. If not, see . use std::ops::{Deref, DerefMut}; -use std::time; +use std::thread; +use std::time::{self, Duration}; use std::sync::Arc; -use devtools::{http_client, RandomTempPath}; + +#[cfg(test)] +use devtools::http_client; +use devtools::RandomTempPath; + use rpc::ConfirmationsQueue; -use util::Hashable; use rand; use ServerBuilder; use Server; use AuthCodes; +/// Struct representing authcodes pub struct GuardedAuthCodes { authcodes: AuthCodes, - path: RandomTempPath, + /// The path to the mock authcodes + pub path: RandomTempPath, } impl Deref for GuardedAuthCodes { type Target = AuthCodes; @@ -42,6 +48,7 @@ impl DerefMut for GuardedAuthCodes { } } +/// Setup a mock signer for testsp pub fn serve() -> (Server, usize, GuardedAuthCodes) { let mut path = RandomTempPath::new(); path.panic_on_drop_failure = false; @@ -56,10 +63,6 @@ pub fn serve() -> (Server, usize, GuardedAuthCodes) { }) } -pub fn request(server: Server, request: &str) -> http_client::Response { - http_client::request(server.addr(), request) -} - #[test] fn should_reject_invalid_host() { // given @@ -246,4 +249,3 @@ fn should_allow_initial_connection_but_only_once() { assert_eq!(response2.status, "HTTP/1.1 403 FORBIDDEN".to_owned()); http_client::assert_security_headers_present(&response2.headers, None); } -