diff --git a/crates/core/src/swarm/impls.rs b/crates/core/src/swarm/impls.rs index 46004a807..160900bfb 100644 --- a/crates/core/src/swarm/impls.rs +++ b/crates/core/src/swarm/impls.rs @@ -262,7 +262,7 @@ impl ConnectionHandshake for Swarm { // The party with a smaller Did should reject answering the other party and report an Error::AlreadyConnected error. if conn.webrtc_connection_state() == WebrtcConnectionState::New { // drop local offer and continue answer remote offer - if peer > self.did() { + if self.did() > peer { // this connection will replaced by new connection created bellow self.disconnect(peer).await?; } else { diff --git a/crates/core/src/tests/default/test_connection.rs b/crates/core/src/tests/default/test_connection.rs index c57c5e15c..9035924e3 100644 --- a/crates/core/src/tests/default/test_connection.rs +++ b/crates/core/src/tests/default/test_connection.rs @@ -8,9 +8,6 @@ use crate::message::handlers::tests::wait_for_msgs; use crate::tests::default::prepare_node; use crate::tests::manually_establish_connection; -// this function not work for dummy test -// TODO: need to fix it -#[cfg(not(feature = "dummy"))] #[tokio::test] async fn test_handshake_on_both_sides() -> Result<()> { let key1 = SecretKey::random(); @@ -30,11 +27,20 @@ async fn test_handshake_on_both_sides() -> Result<()> { wait_for_msgs(&swarm1, &swarm2, &swarm3).await; assert_no_more_msg(&swarm1, &swarm2, &swarm3).await; - assert!(swarm3.get_connection(swarm1.did()).is_some()); - assert!(swarm3.get_connection(swarm2.did()).is_some()); - - assert!(swarm1.get_connection(swarm3.did()).is_some()); - assert!(swarm2.get_connection(swarm3.did()).is_some()); + assert_eq!( + swarm3 + .get_connection(swarm1.did()) + .unwrap() + .webrtc_connection_state(), + WebrtcConnectionState::Connected + ); + assert_eq!( + swarm3 + .get_connection(swarm2.did()) + .unwrap() + .webrtc_connection_state(), + WebrtcConnectionState::Connected + ); assert_eq!( swarm1 @@ -81,9 +87,6 @@ async fn test_handshake_on_both_sides() -> Result<()> { // and response answer // When node 2 got offer, node 2 reject offer if did 1 < did 2 - assert!(swarm1.get_connection(swarm2.did()).is_some()); - assert!(swarm2.get_connection(swarm1.did()).is_some()); - assert_eq!( swarm1 .get_connection(swarm2.did()) diff --git a/crates/core/src/tests/default/test_stabilization.rs b/crates/core/src/tests/default/test_stabilization.rs index a3892b029..bee3a9608 100644 --- a/crates/core/src/tests/default/test_stabilization.rs +++ b/crates/core/src/tests/default/test_stabilization.rs @@ -126,9 +126,6 @@ async fn test_stabilization() -> Result<()> { Ok(()) } -// this function not work for dummy test -// TODO: need to fix it -#[cfg(not(feature = "dummy"))] #[tokio::test] async fn test_stabilization_final_dht() -> Result<()> { let mut nodes = vec![]; diff --git a/crates/transport/src/connections/dummy/mod.rs b/crates/transport/src/connections/dummy/mod.rs index d4d19ea79..e843a5f5e 100644 --- a/crates/transport/src/connections/dummy/mod.rs +++ b/crates/transport/src/connections/dummy/mod.rs @@ -159,7 +159,13 @@ impl ConnectionInterface for DummyConnection { if CHANNEL_OPEN_DELAY { random_delay().await; } - if self.webrtc_connection_state() == WebrtcConnectionState::Connected { + + // Will pass if the state is connecting to prevent release connection in the `test_handshake_on_both_sides` test. + // The connecting state means an offer is answered but not accepted by the other side. + if matches!( + self.webrtc_connection_state(), + WebrtcConnectionState::Connected | WebrtcConnectionState::Connecting + ) { Ok(()) } else { Err(Error::DataChannelOpen(