mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
test(net): add active session tests (#230)
* test(net): add active session tests * more tests
This commit is contained in:
@ -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 {
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -23,5 +23,5 @@ pub use types::*;
|
||||
|
||||
pub use crate::{
|
||||
ethstream::{EthStream, UnauthedEthStream},
|
||||
p2pstream::{DisconnectReason, HelloMessage, P2PStream, UnauthedP2PStream},
|
||||
p2pstream::{DisconnectReason, HelloMessage, P2PStream, ProtocolVersion, UnauthedP2PStream},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user