Merge pull request #333 from ethcore/nvolf
Network tests, separate local coverage for utils
This commit is contained in:
commit
bb6115cbef
@ -1 +0,0 @@
|
||||
../cov.sh
|
9
util/cov.sh
Executable file
9
util/cov.sh
Executable file
@ -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
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user