From 719f4cd64d7bdd12a4fced727692bce1b956ace3 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Thu, 19 Sep 2024 17:14:58 -0400 Subject: [PATCH] fix tests --- Cargo.lock | 1 + Cargo.toml | 1 - p2p/p2p-core/Cargo.toml | 1 + p2p/p2p-core/src/client/handshaker.rs | 2 +- p2p/p2p-core/src/lib.rs | 12 +++++++++--- p2p/p2p-core/{src => }/tests/fragmented_handshake.rs | 4 +++- p2p/p2p-core/{src => }/tests/handles.rs | 4 +++- p2p/p2p-core/{src => }/tests/handshake.rs | 5 ++++- p2p/p2p-core/{src => }/tests/sending_receiving.rs | 4 +++- 9 files changed, 25 insertions(+), 9 deletions(-) rename p2p/p2p-core/{src => }/tests/fragmented_handshake.rs (98%) rename p2p/p2p-core/{src => }/tests/handles.rs (93%) rename p2p/p2p-core/{src => }/tests/handshake.rs (97%) rename p2p/p2p-core/{src => }/tests/sending_receiving.rs (95%) diff --git a/Cargo.lock b/Cargo.lock index 605af04..613aef2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -776,6 +776,7 @@ version = "0.1.0" dependencies = [ "async-trait", "borsh", + "cfg-if", "cuprate-helper", "cuprate-pruning", "cuprate-test-utils", diff --git a/Cargo.toml b/Cargo.toml index f991f73..2554fbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -210,7 +210,6 @@ unseparated_literal_suffix = "deny" unnecessary_safety_doc = "deny" unnecessary_safety_comment = "deny" unnecessary_self_imports = "deny" -tests_outside_test_module = "deny" string_to_string = "deny" rest_pat_in_fully_bound_structs = "deny" redundant_type_annotations = "deny" diff --git a/p2p/p2p-core/Cargo.toml b/p2p/p2p-core/Cargo.toml index 4175c5f..ea69d5e 100644 --- a/p2p/p2p-core/Cargo.toml +++ b/p2p/p2p-core/Cargo.toml @@ -21,6 +21,7 @@ futures = { workspace = true, features = ["std"] } async-trait = { workspace = true } tower = { workspace = true, features = ["util", "tracing"] } +cfg-if = { workspace = true } thiserror = { workspace = true } tracing = { workspace = true, features = ["std", "attributes"] } hex-literal = { workspace = true } diff --git a/p2p/p2p-core/src/client/handshaker.rs b/p2p/p2p-core/src/client/handshaker.rs index 46b63e4..d6873a8 100644 --- a/p2p/p2p-core/src/client/handshaker.rs +++ b/p2p/p2p-core/src/client/handshaker.rs @@ -231,7 +231,7 @@ pub async fn ping(addr: N::Addr) -> Result } /// This function completes a handshake with the requested peer. -#[allow(clippy::too_many_arguments)] +#[expect(clippy::too_many_arguments)] async fn handshake( req: DoHandshakeRequest, diff --git a/p2p/p2p-core/src/lib.rs b/p2p/p2p-core/src/lib.rs index 54b40c6..24c0776 100644 --- a/p2p/p2p-core/src/lib.rs +++ b/p2p/p2p-core/src/lib.rs @@ -56,6 +56,15 @@ //! .unwrap(); //! # }); //! ``` + +cfg_if::cfg_if! { + // Used in `tests/` + if #[cfg(test)] { + use cuprate_test_utils as _; + use hex as _; + } +} + use std::{fmt::Debug, future::Future, hash::Hash}; use futures::{Sink, Stream}; @@ -65,9 +74,6 @@ use cuprate_wire::{ NetworkAddress, }; -#[cfg(test)] -mod tests; - pub mod client; mod constants; pub mod error; diff --git a/p2p/p2p-core/src/tests/fragmented_handshake.rs b/p2p/p2p-core/tests/fragmented_handshake.rs similarity index 98% rename from p2p/p2p-core/src/tests/fragmented_handshake.rs rename to p2p/p2p-core/tests/fragmented_handshake.rs index 6058542..679f829 100644 --- a/p2p/p2p-core/src/tests/fragmented_handshake.rs +++ b/p2p/p2p-core/tests/fragmented_handshake.rs @@ -1,5 +1,7 @@ //! This file contains a test for a handshake with monerod but uses fragmented messages. +#![expect(unused_crate_dependencies, reason = "external test module")] + use std::{ net::SocketAddr, pin::Pin, @@ -29,7 +31,7 @@ use cuprate_wire::{ BasicNodeData, Message, MoneroWireCodec, }; -use crate::{ +use cuprate_p2p_core::{ client::{ handshaker::HandshakerBuilder, ConnectRequest, Connector, DoHandshakeRequest, InternalPeerID, diff --git a/p2p/p2p-core/src/tests/handles.rs b/p2p/p2p-core/tests/handles.rs similarity index 93% rename from p2p/p2p-core/src/tests/handles.rs rename to p2p/p2p-core/tests/handles.rs index 3f247b1..2a2e2be 100644 --- a/p2p/p2p-core/src/tests/handles.rs +++ b/p2p/p2p-core/tests/handles.rs @@ -1,8 +1,10 @@ +#![expect(unused_crate_dependencies, reason = "external test module")] + use std::{sync::Arc, time::Duration}; use tokio::sync::Semaphore; -use crate::handles::HandleBuilder; +use cuprate_p2p_core::handles::HandleBuilder; #[test] fn send_ban_signal() { diff --git a/p2p/p2p-core/src/tests/handshake.rs b/p2p/p2p-core/tests/handshake.rs similarity index 97% rename from p2p/p2p-core/src/tests/handshake.rs rename to p2p/p2p-core/tests/handshake.rs index 599f33b..4170151 100644 --- a/p2p/p2p-core/src/tests/handshake.rs +++ b/p2p/p2p-core/tests/handshake.rs @@ -1,3 +1,5 @@ +#![expect(unused_crate_dependencies, reason = "external test module")] + use std::time::Duration; use futures::StreamExt; @@ -15,7 +17,7 @@ use cuprate_test_utils::{ }; use cuprate_wire::{common::PeerSupportFlags, BasicNodeData, MoneroWireCodec}; -use crate::{ +use cuprate_p2p_core::{ client::{ handshaker::HandshakerBuilder, ConnectRequest, Connector, DoHandshakeRequest, InternalPeerID, @@ -24,6 +26,7 @@ use crate::{ }; #[tokio::test] +#[expect(clippy::significant_drop_tightening)] async fn handshake_cuprate_to_cuprate() { // Tests a Cuprate <-> Cuprate handshake by making 2 handshake services and making them talk to // each other. diff --git a/p2p/p2p-core/src/tests/sending_receiving.rs b/p2p/p2p-core/tests/sending_receiving.rs similarity index 95% rename from p2p/p2p-core/src/tests/sending_receiving.rs rename to p2p/p2p-core/tests/sending_receiving.rs index f820d98..8c90c83 100644 --- a/p2p/p2p-core/src/tests/sending_receiving.rs +++ b/p2p/p2p-core/tests/sending_receiving.rs @@ -1,10 +1,12 @@ +#![expect(unused_crate_dependencies, reason = "external test module")] + use tower::{Service, ServiceExt}; use cuprate_helper::network::Network; use cuprate_test_utils::monerod::monerod; use cuprate_wire::{common::PeerSupportFlags, protocol::GetObjectsRequest, BasicNodeData}; -use crate::{ +use cuprate_p2p_core::{ client::{handshaker::HandshakerBuilder, ConnectRequest, Connector}, protocol::{PeerRequest, PeerResponse}, ClearNet, ProtocolRequest, ProtocolResponse,