diff --git a/util/cov.sh b/util/cov.sh deleted file mode 120000 index 72bb061f8..000000000 --- a/util/cov.sh +++ /dev/null @@ -1 +0,0 @@ -../cov.sh \ No newline at end of file diff --git a/util/cov.sh b/util/cov.sh new file mode 100755 index 000000000..19aa3b892 --- /dev/null +++ b/util/cov.sh @@ -0,0 +1,9 @@ +if ! type kcov > /dev/null; then + echo "Install kcov first (details inside this file). Aborting." + exit 1 +fi + +cargo test --no-run || exit $? +mkdir -p target/coverage +kcov --exclude-pattern ~/.multirust,rocksdb,secp256k1 --include-pattern src --verify target/coverage target/debug/ethcore_util* +xdg-open target/coverage/index.html diff --git a/util/src/network/connection.rs b/util/src/network/connection.rs index f91c38b04..de1ca185a 100644 --- a/util/src/network/connection.rs +++ b/util/src/network/connection.rs @@ -603,7 +603,7 @@ mod tests { } #[test] - fn connection_write_to_broken_socket() { + fn connection_write_to_broken() { let mut connection = TestBrokenConnection::new(); let data = Cursor::new(vec![0; 10240]); connection.send_queue.push_back(data); @@ -613,4 +613,50 @@ mod tests { assert!(!status.is_ok()); assert_eq!(1, connection.send_queue.len()); } + + #[test] + fn connection_read() { + let mut connection = TestConnection::new(); + connection.rec_size = 2048; + connection.rec_buf = vec![10; 1024]; + connection.socket.read_buffer = vec![99; 2048]; + + let status = connection.readable(); + + assert!(status.is_ok()); + assert_eq!(1024, connection.socket.cursor); + } + + #[test] + fn connection_read_from_broken() { + let mut connection = TestBrokenConnection::new(); + connection.rec_size = 2048; + + let status = connection.readable(); + assert!(!status.is_ok()); + assert_eq!(0, connection.rec_buf.len()); + } + + #[test] + fn connection_read_nothing() { + let mut connection = TestConnection::new(); + connection.rec_size = 2048; + + let status = connection.readable(); + + assert!(status.is_ok()); + assert_eq!(0, connection.rec_buf.len()); + } + + #[test] + fn connection_read_full() { + let mut connection = TestConnection::new(); + connection.rec_size = 1024; + connection.rec_buf = vec![76;1024]; + + let status = connection.readable(); + + assert!(status.is_ok()); + assert_eq!(0, connection.socket.cursor); + } } diff --git a/util/src/network/node.rs b/util/src/network/node.rs index fd27e58e2..d99754cff 100644 --- a/util/src/network/node.rs +++ b/util/src/network/node.rs @@ -83,3 +83,36 @@ impl Hash for Node { } } +#[cfg(test)] +mod tests { + use super::*; + use std::str::FromStr; + use std::net::*; + use hash::*; + + #[test] + fn endpoint_parse() { + let endpoint = NodeEndpoint::from_str("123.99.55.44:7770"); + assert!(endpoint.is_ok()); + let v4 = match endpoint.unwrap().address { + SocketAddr::V4(v4address) => v4address, + _ => panic!("should ve v4 address") + }; + assert_eq!(SocketAddrV4::new(Ipv4Addr::new(123, 99, 55, 44), 7770), v4); + } + + #[test] + fn node_parse() { + let node = Node::from_str("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@22.99.55.44:7770"); + assert!(node.is_ok()); + let node = node.unwrap(); + let v4 = match node.endpoint.address { + SocketAddr::V4(v4address) => v4address, + _ => panic!("should ve v4 address") + }; + assert_eq!(SocketAddrV4::new(Ipv4Addr::new(22, 99, 55, 44), 7770), v4); + assert_eq!( + H512::from_str("a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c").unwrap(), + node.id); + } +}