Skip to content

Commit 45a78b6

Browse files
Imod7lexnv
andauthored
notif/tests: check test state (#360)
Relates to #340 ### Description Added the check that the peer's `state` is `Closed`. This is the expected state since: - in the beginning we check that the peer starts with state [Closed](https://github.com/paritytech/litep2p/blob/e0b7118ea2ca3e9f9beb9605f649d7e9dcdd24c4/src/protocol/notification/tests/substream_validation.rs#L275) - then we check that it changes to `state` [Validating](https://github.com/paritytech/litep2p/blob/e0b7118ea2ca3e9f9beb9605f649d7e9dcdd24c4/src/protocol/notification/tests/substream_validation.rs#L295) - then we have a [NegotiationError](https://github.com/paritytech/litep2p/blob/e0b7118ea2ca3e9f9beb9605f649d7e9dcdd24c4/src/protocol/notification/tests/substream_validation.rs#L325) - so then we should check again that the peer's state is reset to `Closed`. ### Additional Changes Replaced also all instances of ``` _ => panic!("invalid state for peer"), ``` with ``` state => panic!("invalid state for peer: {state:?}"), ``` since it might be more helpful for debugging purposes. If not necessary, I can revert these. --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
1 parent 0d388b2 commit 45a78b6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/protocol/notification/tests/substream_validation.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ async fn substream_accepted() {
8484
// connect peer and verify it's in closed state
8585
notif.next_event().await;
8686

87-
match notif.peers.get(&peer).unwrap().state {
87+
match &notif.peers.get(&peer).unwrap().state {
8888
PeerState::Closed { .. } => {}
89-
_ => panic!("invalid state for peer"),
89+
state => panic!("invalid state for peer: {state:?}"),
9090
}
9191

9292
// open inbound substream and verify that peer state has changed to `Validating`
@@ -182,9 +182,9 @@ async fn substream_rejected() {
182182
// connect peer and verify it's in closed state
183183
notif.on_connection_established(peer).await.unwrap();
184184

185-
match notif.peers.get(&peer).unwrap().state {
185+
match &notif.peers.get(&peer).unwrap().state {
186186
PeerState::Closed { .. } => {}
187-
_ => panic!("invalid state for peer"),
187+
state => panic!("invalid state for peer: {state:?}"),
188188
}
189189

190190
// open inbound substream and verify that peer state has changed to `Validating`
@@ -271,9 +271,9 @@ async fn accept_fails_due_to_closed_substream() {
271271
// connect peer and verify it's in closed state
272272
notif.next_event().await;
273273

274-
match notif.peers.get(&peer).unwrap().state {
274+
match &notif.peers.get(&peer).unwrap().state {
275275
PeerState::Closed { .. } => {}
276-
_ => panic!("invalid state for peer"),
276+
state => panic!("invalid state for peer: {state:?}"),
277277
}
278278

279279
// open inbound substream and verify that peer state has changed to `InboundOpen`
@@ -329,7 +329,10 @@ async fn accept_fails_due_to_closed_substream() {
329329
}
330330
notif.on_handshake_event(peer, event).await;
331331

332-
// TODO: https://github.com/paritytech/litep2p/issues/340 check state
332+
match &notif.peers.get(&peer).unwrap().state {
333+
PeerState::Closed { .. } => {}
334+
state => panic!("invalid state for peer: {state:?}"),
335+
}
333336
}
334337

335338
#[tokio::test]

0 commit comments

Comments
 (0)