Skip to content

Commit

Permalink
Fix ipc tests and bring to CI (openethereum#1789)
Browse files Browse the repository at this point in the history
* fixed compilation

* Fix warnings

* fix remaining tests

* add to ci and fix test.sh
  • Loading branch information
NikVolf authored and gavofyork committed Aug 1, 2016
1 parent f19b00b commit 4e72608
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 56 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ build = "build.rs"
rustc_version = "0.1"
syntex = "*"
ethcore-ipc-codegen = { path = "ipc/codegen" }
ethcore-ipc-tests = { path = "ipc/tests" }

[dependencies]
log = "0.3"
Expand Down Expand Up @@ -58,6 +59,7 @@ use-precompiled-js = ["ethcore-dapps/use-precompiled-js", "ethcore-signer/use-pr
dapps = ["ethcore-dapps"]
dev = ["clippy", "ethcore/dev", "ethcore-util/dev", "ethsync/dev", "ethcore-rpc/dev", "ethcore-dapps/dev", "ethcore-signer/dev"]
ipc = ["ethcore/ipc"]
json-tests = ["ethcore/json-tests"]

[[bin]]
path = "parity/main.rs"
Expand Down
3 changes: 2 additions & 1 deletion devtools/src/test_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ impl TestSocket {
impl Read for TestSocket {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
let end_position = cmp::min(self.read_buffer.len(), self.cursor+buf.len());
if self.cursor > end_position { return Ok(0) }
let len = cmp::max(end_position - self.cursor, 0);
match len {
0 => Ok(0),
_ => {
for i in self.cursor..end_position {
buf[i-self.cursor] = self.read_buffer[i];
}
self.cursor = self.cursor + buf.len();
self.cursor = end_position;
Ok(len)
}
}
Expand Down
3 changes: 2 additions & 1 deletion ipc/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ path = "run.rs"
[dependencies]
ethcore-ipc = { path = "../rpc" }
ethcore-devtools = { path = "../../devtools" }
semver = "0.2.0"
semver = "0.2"
nanomsg = { git = "https://github.com/ethcore/nanomsg.rs.git" }
ethcore-ipc-nano = { path = "../nano" }
ethcore-util = { path = "../../util" }
log = "0.3"

[build-dependencies]
syntex = "0.33"
Expand Down
8 changes: 8 additions & 0 deletions ipc/tests/binary.rs.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ fn opt_two_vec() {
let serialized = ::ipc::binary::serialize(&example).unwrap();
assert_eq!(serialized, vec![0u8; 16]);
}

#[test]
fn enum_with_struct() {
let example = EnumWithStruct::Right { how_much: 15 };
let serialized = ::ipc::binary::serialize(&example).unwrap();
let deserialized = ::ipc::binary::deserialize::<EnumWithStruct>(&serialized).unwrap();
assert_eq!(example, deserialized);
}
49 changes: 6 additions & 43 deletions ipc/tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,6 @@ mod tests {
assert_eq!(10, *service.commits.read().unwrap());
}


#[test]
fn call_service_handshake() {
let mut socket = TestSocket::new_ready(vec![0, 0,
// part count = 3
3, 0, 0, 0, 0, 0, 0, 0,
// part sizes
5, 0, 0, 0, 0, 0, 0, 0,
5, 0, 0, 0, 0, 0, 0, 0,
64, 0, 0, 0, 0, 0, 0, 0,
// total payload length
70, 0, 0, 0, 0, 0, 0, 0,
// protocol version
b'1', b'.', b'0', b'.', b'0',
// api version
b'1', b'.', b'0', b'.', b'0',
// reserved

0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]);

let service = Arc::new(Service::new());
let result = service.dispatch(&mut socket);

// single `true`
assert_eq!(vec![1], result);
}


#[test]
fn call_service_client() {
let mut socket = TestSocket::new();
Expand Down Expand Up @@ -110,9 +78,9 @@ mod tests {

#[test]
fn query_default_version() {
let ver = Arc::<Service>::protocol_version();
let ver = Service::protocol_version();
assert_eq!(ver, Version::parse("1.0.0").unwrap());
let ver = Arc::<Service>::api_version();
let ver = Service::api_version();
assert_eq!(ver, Version::parse("1.0.0").unwrap());
}

Expand Down Expand Up @@ -153,16 +121,11 @@ mod tests {
#[test]
fn can_invoke_generic_service() {
let mut socket = TestSocket::new();
socket.read_buffer = vec![
1, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
0,
];
socket.read_buffer = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
let db_client = DBClient::<u64, _>::init(socket);

let result = db_client.write(vec![0u8; 100]);

let result = db_client.write(vec![1u8; 1]);
assert_eq!(vec![0, 16, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
db_client.socket().write().unwrap().write_buffer.clone());
assert!(result.is_ok());
}

Expand Down
8 changes: 3 additions & 5 deletions ipc/tests/nested.rs.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use std::sync::RwLock;
use std::ops::*;
use ipc::IpcConfig;
use ipc::BinaryConvertable;
use std::mem;
use ipc::binary::BinaryConvertError;
use std::collections::VecDeque;
Expand All @@ -29,11 +27,11 @@ pub struct DB<L: Sized> {
}

pub trait DBWriter {
fn write(&self, data: Vec<u8>) -> Result<(), DBError>;
fn write(&self, data: Vec<u8>) -> Result<(), DBError>;
fn write_slice(&self, data: &[u8]) -> Result<(), DBError>;
}

impl IpcConfig<DBWriter> for ::std::sync::Arc<DBWriter> {}
impl IpcConfig for DBWriter {}

#[derive(Binary)]
pub enum DBError { Write, Read }
Expand All @@ -58,4 +56,4 @@ trait DBNotify {
fn notify(&self, a: u64, b: u64) -> bool;
}

impl IpcConfig<DBNotify> for ::std::sync::Arc<DBNotify> { }
impl IpcConfig for DBNotify { }
1 change: 1 addition & 0 deletions ipc/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern crate semver;
extern crate nanomsg;
extern crate ethcore_ipc_nano as nanoipc;
extern crate ethcore_util as util;
#[macro_use] extern crate log;

pub mod service;
mod examples;
Expand Down
3 changes: 1 addition & 2 deletions ipc/tests/service.rs.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use std::sync::RwLock;
use std::ops::*;
use ipc::IpcConfig;
use std::mem;
use ipc::binary::BinaryConvertError;
Expand Down Expand Up @@ -70,4 +69,4 @@ impl Service {
}
}

impl ::ipc::IpcConfig<Service> for ::std::sync::Arc<Service> {}
impl ::ipc::IpcConfig for Service {}
4 changes: 1 addition & 3 deletions ipc/tests/with_attrs.rs.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use std::sync::RwLock;
use std::ops::*;
use ipc::IpcConfig;
use std::mem;
use ipc::binary::BinaryConvertError;
Expand All @@ -31,4 +29,4 @@ impl BadlyNamedService {
}
}

impl ::ipc::IpcConfig<BadlyNamedService> for ::std::sync::Arc<BadlyNamedService> {}
impl IpcConfig for BadlyNamedService {}
1 change: 1 addition & 0 deletions scripts/targets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export TARGETS="
-p ethstore \
-p ethsync \
-p ethcore-ipc \
-p ethcore-ipc-tests \
-p parity"
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# Running Parity Full Test Sute

FEATURES="--features ethcore/json-tests"
FEATURES="--features json-tests"

case $1 in
--no-json)
Expand Down

0 comments on commit 4e72608

Please sign in to comment.