diff --git a/core/src/upgrade/apply.rs b/core/src/upgrade/apply.rs index 50aa8e2c..aa997435 100644 --- a/core/src/upgrade/apply.rs +++ b/core/src/upgrade/apply.rs @@ -55,7 +55,7 @@ where { InboundUpgradeApply { inner: InboundUpgradeApplyState::Init { - future: multistream_select::listener_select_proto(conn, up.protocol_info().into_iter()), + future: multistream_select::listener_select_proto(conn, up.protocol_info()), upgrade: up, }, } diff --git a/misc/allow-block-list/src/lib.rs b/misc/allow-block-list/src/lib.rs index a9e3280c..eed79d74 100644 --- a/misc/allow-block-list/src/lib.rs +++ b/misc/allow-block-list/src/lib.rs @@ -354,9 +354,16 @@ mod tests { .block_peer(*listener.local_peer_id()); let ( - [SwarmEvent::ConnectionClosed { peer_id: closed_dialer_peer, .. }], - [SwarmEvent::ConnectionClosed { peer_id: closed_listener_peer, .. }] - ) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await else { + [SwarmEvent::ConnectionClosed { + peer_id: closed_dialer_peer, + .. + }], + [SwarmEvent::ConnectionClosed { + peer_id: closed_listener_peer, + .. + }], + ) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await + else { panic!("unexpected events") }; assert_eq!(closed_dialer_peer, *listener.local_peer_id()); @@ -417,9 +424,22 @@ mod tests { .unwrap(); let ( - [SwarmEvent::OutgoingConnectionError { error: DialError::Denied { cause: outgoing_cause }, .. }], - [_, SwarmEvent::IncomingConnectionError { error: ListenError::Denied { cause: incoming_cause }, .. }], - ) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await else { + [SwarmEvent::OutgoingConnectionError { + error: + DialError::Denied { + cause: outgoing_cause, + }, + .. + }], + [_, SwarmEvent::IncomingConnectionError { + error: + ListenError::Denied { + cause: incoming_cause, + }, + .. + }], + ) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await + else { panic!("unexpected events") }; assert!(outgoing_cause.downcast::().is_ok()); @@ -447,9 +467,16 @@ mod tests { .list .disallow_peer(*listener.local_peer_id()); let ( - [SwarmEvent::ConnectionClosed { peer_id: closed_dialer_peer, .. }], - [SwarmEvent::ConnectionClosed { peer_id: closed_listener_peer, .. }] - ) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await else { + [SwarmEvent::ConnectionClosed { + peer_id: closed_dialer_peer, + .. + }], + [SwarmEvent::ConnectionClosed { + peer_id: closed_listener_peer, + .. + }], + ) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await + else { panic!("unexpected events") }; assert_eq!(closed_dialer_peer, *listener.local_peer_id()); diff --git a/misc/multistream-select/src/length_delimited.rs b/misc/multistream-select/src/length_delimited.rs index 85f6ffc1..cff2f4ab 100644 --- a/misc/multistream-select/src/length_delimited.rs +++ b/misc/multistream-select/src/length_delimited.rs @@ -411,7 +411,7 @@ mod tests { assert!(len < (1 << 15)); let frame = (0..len).map(|n| (n & 0xff) as u8).collect::>(); let mut data = vec![(len & 0x7f) as u8 | 0x80, (len >> 7) as u8]; - data.extend(frame.clone().into_iter()); + data.extend(frame.clone()); let mut framed = LengthDelimited::new(Cursor::new(data)); let recved = futures::executor::block_on(async move { framed.next().await }).unwrap(); assert_eq!(recved.unwrap(), frame); diff --git a/misc/multistream-select/tests/dialer_select.rs b/misc/multistream-select/tests/dialer_select.rs index 18f8238c..d1b27645 100644 --- a/misc/multistream-select/tests/dialer_select.rs +++ b/misc/multistream-select/tests/dialer_select.rs @@ -47,10 +47,9 @@ fn select_proto_basic() { let client = async_std::task::spawn(async move { let protos = vec!["/proto3", "/proto2"]; - let (proto, mut io) = - dialer_select_proto(client_connection, protos.into_iter(), version) - .await - .unwrap(); + let (proto, mut io) = dialer_select_proto(client_connection, protos, version) + .await + .unwrap(); assert_eq!(proto, "/proto2"); io.write_all(b"ping").await.unwrap(); @@ -99,25 +98,21 @@ fn negotiation_failed() { } }); - let client = - async_std::task::spawn(async move { - let mut io = - match dialer_select_proto(client_connection, dial_protos.into_iter(), version) - .await - { - Err(NegotiationError::Failed) => return, - Ok((_, io)) => io, - Err(_) => panic!(), - }; - // The dialer may write a payload that is even sent before it - // got confirmation of the last proposed protocol, when `V1Lazy` - // is used. - io.write_all(&dial_payload).await.unwrap(); - match io.complete().await { - Err(NegotiationError::Failed) => {} - _ => panic!(), - } - }); + let client = async_std::task::spawn(async move { + let mut io = match dialer_select_proto(client_connection, dial_protos, version).await { + Err(NegotiationError::Failed) => return, + Ok((_, io)) => io, + Err(_) => panic!(), + }; + // The dialer may write a payload that is even sent before it + // got confirmation of the last proposed protocol, when `V1Lazy` + // is used. + io.write_all(&dial_payload).await.unwrap(); + match io.complete().await { + Err(NegotiationError::Failed) => {} + _ => panic!(), + } + }); server.await; client.await; @@ -185,10 +180,9 @@ async fn v1_lazy_do_not_wait_for_negotiation_on_poll_close() { let client = async_std::task::spawn(async move { // Single protocol to allow for lazy (or optimistic) protocol negotiation. let protos = vec!["/proto1"]; - let (proto, mut io) = - dialer_select_proto(client_connection, protos.into_iter(), Version::V1Lazy) - .await - .unwrap(); + let (proto, mut io) = dialer_select_proto(client_connection, protos, Version::V1Lazy) + .await + .unwrap(); assert_eq!(proto, "/proto1"); // client can close the connection even though protocol negotiation is not yet done, i.e. diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index 37f25631..b2414fd7 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -858,7 +858,7 @@ fn test_handle_received_subscriptions() { // UNSUBSCRIBE - Remove topic from peer_topics for peer. // - Remove peer from topic_peers. - let topics = vec!["topic1", "topic2", "topic3", "topic4"] + let topics = ["topic1", "topic2", "topic3", "topic4"] .iter() .map(|&t| String::from(t)) .collect(); @@ -1280,7 +1280,7 @@ fn test_handle_graft_is_not_subscribed() { #[test] // tests multiple topics in a single graft message fn test_handle_graft_multiple_topics() { - let topics: Vec = vec!["topic1", "topic2", "topic3", "topic4"] + let topics: Vec = ["topic1", "topic2", "topic3", "topic4"] .iter() .map(|&t| String::from(t)) .collect(); diff --git a/protocols/gossipsub/src/subscription_filter.rs b/protocols/gossipsub/src/subscription_filter.rs index 8ec633d0..9f883f12 100644 --- a/protocols/gossipsub/src/subscription_filter.rs +++ b/protocols/gossipsub/src/subscription_filter.rs @@ -222,7 +222,7 @@ mod test { let t1 = TopicHash::from_raw("t1"); let t2 = TopicHash::from_raw("t2"); - let old = BTreeSet::from_iter(vec![t1.clone()].into_iter()); + let old = BTreeSet::from_iter(vec![t1.clone()]); let subscriptions = vec![ Subscription { action: Unsubscribe, diff --git a/transports/noise/tests/webtransport_certhashes.rs b/transports/noise/tests/webtransport_certhashes.rs index 41341fe8..95ce0bf5 100644 --- a/transports/noise/tests/webtransport_certhashes.rs +++ b/transports/noise/tests/webtransport_certhashes.rs @@ -40,9 +40,10 @@ fn webtransport_server_empty_certhashes() { // Invalid case, because a MITM attacker may strip certificates of the server. let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) = - handshake_with_certhashes(vec![certhash1, certhash2], vec![]) else { - panic!("unexpected result"); - }; + handshake_with_certhashes(vec![certhash1, certhash2], vec![]) + else { + panic!("unexpected result"); + }; assert_eq!(expected, HashSet::from([certhash1, certhash2])); assert_eq!(received, HashSet::new()); @@ -68,9 +69,10 @@ fn webtransport_server_uninit_certhashes() { // Invalid case, because a MITM attacker may strip certificates of the server. let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) = - handshake_with_certhashes(vec![certhash1, certhash2], None) else { - panic!("unexpected result"); - }; + handshake_with_certhashes(vec![certhash1, certhash2], None) + else { + panic!("unexpected result"); + }; assert_eq!(expected, HashSet::from([certhash1, certhash2])); assert_eq!(received, HashSet::new()); @@ -81,9 +83,10 @@ fn webtransport_different_server_certhashes() { let (certhash1, certhash2, certhash3) = certhashes(); let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) = - handshake_with_certhashes(vec![certhash1, certhash3], vec![certhash1, certhash2]) else { - panic!("unexpected result"); - }; + handshake_with_certhashes(vec![certhash1, certhash3], vec![certhash1, certhash2]) + else { + panic!("unexpected result"); + }; assert_eq!(expected, HashSet::from([certhash1, certhash3])); assert_eq!(received, HashSet::from([certhash1, certhash2])); @@ -94,9 +97,10 @@ fn webtransport_superset_of_certhashes() { let (certhash1, certhash2, _) = certhashes(); let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) = - handshake_with_certhashes(vec![certhash1, certhash2], vec![certhash1]) else { - panic!("unexpected result"); - }; + handshake_with_certhashes(vec![certhash1, certhash2], vec![certhash1]) + else { + panic!("unexpected result"); + }; assert_eq!(expected, HashSet::from([certhash1, certhash2])); assert_eq!(received, HashSet::from([certhash1]));