network: add connect_isolated distinguisher test

This is currently broken due to a rustc bug.
This commit is contained in:
Henry de Valence 2020-09-14 12:47:07 -07:00
parent b7472de43f
commit 81e8195f68
2 changed files with 55 additions and 1 deletions

View File

@ -22,7 +22,7 @@ serde = { version = "1", features = ["serde_derive"] }
thiserror = "1"
futures = "0.3"
tokio = { version = "0.2.22", features = ["net", "time", "stream", "tracing"] }
tokio = { version = "0.2.22", features = ["net", "time", "stream", "tracing", "macros"] }
tokio-util = { version = "0.2", features = ["codec"] }
tower = "0.3"
tower-load = "0.3"

View File

@ -76,3 +76,57 @@ impl Service<Request> for Wrapper {
self.0.call(req).map_err(Into::into).boxed()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn connect_isolated_sends_minimally_distinguished_version_message() {
use crate::{
protocol::external::{Codec, Message},
types::PeerServices,
};
use futures::stream::StreamExt;
use tokio_util::codec::Framed;
let mut listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let listen_addr = listener.local_addr().unwrap();
let conn = tokio::net::TcpStream::connect(listen_addr).await.unwrap();
tokio::spawn(connect_isolated(conn, "".to_string()));
let (conn, _) = listener.accept().await.unwrap();
let mut stream = Framed::new(conn, Codec::builder().finish());
if let Message::Version {
services,
timestamp,
address_from,
user_agent,
start_height,
relay,
..
} = stream
.next()
.await
.expect("stream item")
.expect("item is Ok(msg)")
{
// Check that the version message sent by connect_isolated
// has the fields specified in the Stolon RFC.
assert_eq!(services, PeerServices::empty());
assert_eq!(timestamp.timestamp() % (5 * 60), 0);
assert_eq!(
address_from,
(PeerServices::empty(), "0.0.0.0:8233".parse().unwrap())
);
assert_eq!(user_agent, "");
assert_eq!(start_height.0, 0);
assert_eq!(relay, false);
} else {
panic!("handshake did not send version message");
}
}
}