test(net): add active session tests (#230)

* test(net): add active session tests

* more tests
This commit is contained in:
Matthias Seitz
2022-11-22 06:22:43 +01:00
committed by GitHub
parent f7c6ae5858
commit 46e4ad9744
5 changed files with 317 additions and 7 deletions

View File

@ -21,6 +21,19 @@ pub enum EthStreamError {
MessageTooBig(usize),
}
// === impl EthStreamError ===
impl EthStreamError {
/// Returns the [`DisconnectReason`] if the error is a disconnect message
pub fn as_disconnected(&self) -> Option<DisconnectReason> {
if let EthStreamError::P2PStreamError(err) = self {
err.as_disconnected()
} else {
None
}
}
}
#[derive(thiserror::Error, Debug)]
#[allow(missing_docs)]
pub enum HandshakeError {
@ -73,6 +86,19 @@ pub enum P2PStreamError {
Disconnected(DisconnectReason),
}
// === impl P2PStreamError ===
impl P2PStreamError {
/// Returns the [`DisconnectReason`] if it is the `Disconnected` variant.
pub fn as_disconnected(&self) -> Option<DisconnectReason> {
if let P2PStreamError::Disconnected(reason) = self {
Some(*reason)
} else {
None
}
}
}
/// Errors when conducting a p2p handshake
#[derive(thiserror::Error, Debug)]
pub enum P2PHandshakeError {

View File

@ -141,6 +141,11 @@ impl<S> EthStream<S> {
pub fn inner_mut(&mut self) -> &mut S {
&mut self.inner
}
/// Consumes this type and returns the wrapped stream.
pub fn into_inner(self) -> S {
self.inner
}
}
impl<S, E> EthStream<S>

View File

@ -23,5 +23,5 @@ pub use types::*;
pub use crate::{
ethstream::{EthStream, UnauthedEthStream},
p2pstream::{DisconnectReason, HelloMessage, P2PStream, UnauthedP2PStream},
p2pstream::{DisconnectReason, HelloMessage, P2PStream, ProtocolVersion, UnauthedP2PStream},
};