node/test: check remote events for `Event::PeerDisconnected`

The node being connected to may be blocking the connecting node.
In this case the service will emit an event that says the connecting
node is disconnected.

Check the events for this event as well as `Event::PeerConnected`.
This commit is contained in:
Fintan Halpenny 2026-02-17 14:02:05 +00:00 committed by Lorenz Leutgeb
parent 1fa14ef529
commit a4806f2718
1 changed files with 6 additions and 1 deletions

View File

@ -99,6 +99,9 @@ impl<G: 'static> Drop for NodeHandle<G> {
impl<G: Signer<Signature> + cyphernet::Ecdh> NodeHandle<G> {
/// Connect this node to another node, and wait for the connection to be established both ways.
///
/// If the remote has blocked this node, then the remote event will be
/// [`Event::PeerDisconnected`].
pub fn connect(&mut self, remote: &NodeHandle<G>) -> &mut Self {
let local_events = self.handle.events();
let remote_events = remote.handle.events();
@ -119,7 +122,9 @@ impl<G: Signer<Signature> + cyphernet::Ecdh> NodeHandle<G> {
.iter()
.find(|e| {
matches!(
e, Event::PeerConnected { nid } if nid == &self.id
e,
Event::PeerConnected { nid } | Event::PeerDisconnected { nid, .. }
if nid == &self.id
)
})
.unwrap();