diff --git a/Cargo.lock b/Cargo.lock index e08327657a..aead5ac56d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4871,6 +4871,7 @@ dependencies = [ "sn_service_management", "sn_transfers", "sysinfo", + "test_utils", "tokio", "tonic 0.6.2", "tracing", @@ -5135,6 +5136,7 @@ dependencies = [ "sn_transfers", "strum", "tempfile", + "test_utils", "thiserror", "tokio", "tokio-stream", @@ -5555,6 +5557,17 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" +[[package]] +name = "test_utils" +version = "0.1.0" +dependencies = [ + "color-eyre", + "dirs-next", + "libp2p", + "serde", + "serde_json", +] + [[package]] name = "textwrap" version = "0.16.1" diff --git a/Cargo.toml b/Cargo.toml index 0a4655ccc6..240923af77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ members = [ "sn_registers", "sn_service_management", "sn_transfers", + "test_utils", "token_supplies", ] diff --git a/sn_client/Cargo.toml b/sn_client/Cargo.toml index 960070f170..d9b3f29d22 100644 --- a/sn_client/Cargo.toml +++ b/sn_client/Cargo.toml @@ -14,7 +14,7 @@ version = "0.104.29-alpha.1" default=[] local-discovery=["sn_networking/local-discovery"] open-metrics = ["sn_networking/open-metrics", "prometheus-client"] -test-utils=["sn_protocol/test-utils", "sn_peers_acquisition", "lazy_static", "eyre"] +test-utils=["sn_peers_acquisition", "lazy_static", "eyre"] # required to pass on flag to node builds websockets = ["sn_networking/websockets", "sn_protocol/websockets"] diff --git a/sn_node/Cargo.toml b/sn_node/Cargo.toml index fc0633059a..b2e4abc05c 100644 --- a/sn_node/Cargo.toml +++ b/sn_node/Cargo.toml @@ -74,10 +74,10 @@ color-eyre = "0.6.2" [dev-dependencies] assert_matches = "1.5.0" -tempfile = "3.6.0" reqwest = { version="0.11.18", default-features=false, features = ["rustls"] } -sn_protocol = { path = "../sn_protocol", version = "0.15.3", features = ["test-utils", "rpc"]} serde_json = "1.0" +tempfile = "3.6.0" +test_utils = { version = "0.1.0", path = "../test_utils"} [lints] workspace = true diff --git a/sn_node/tests/common/client.rs b/sn_node/tests/common/client.rs index 38f1214f16..2bba76cf6e 100644 --- a/sn_node/tests/common/client.rs +++ b/sn_node/tests/common/client.rs @@ -11,15 +11,13 @@ use lazy_static::lazy_static; use libp2p::PeerId; use sn_client::{send, Client}; use sn_peers_acquisition::parse_peer_addr; -use sn_protocol::{ - safenode_proto::{NodeInfoRequest, RestartRequest}, - test_utils::DeploymentInventory, -}; +use sn_protocol::safenode_proto::{NodeInfoRequest, RestartRequest}; use sn_service_management::{ get_local_node_registry_path, safenode_manager_proto::NodeServiceRestartRequest, NodeRegistry, }; use sn_transfers::{create_faucet_wallet, HotWallet, NanoTokens, Transfer}; use std::{net::SocketAddr, path::Path}; +use test_utils::testnet::DeploymentInventory; use tokio::{ sync::Mutex, time::{Duration, Instant}, diff --git a/sn_node/tests/common/mod.rs b/sn_node/tests/common/mod.rs index 1447c785de..6366e2092c 100644 --- a/sn_node/tests/common/mod.rs +++ b/sn_node/tests/common/mod.rs @@ -23,7 +23,6 @@ use sn_client::{Client, FilesApi}; use sn_protocol::{ safenode_proto::{safe_node_client::SafeNodeClient, NodeInfoRequest}, storage::ChunkAddress, - test_utils::DeploymentInventory, }; use sn_service_management::{ get_local_node_registry_path, @@ -36,6 +35,7 @@ use std::{ path::{Path, PathBuf}, time::Duration, }; +use test_utils::testnet::DeploymentInventory; use tonic::Request; use tracing::{debug, error, warn}; use xor_name::XorName; diff --git a/sn_node_manager/Cargo.toml b/sn_node_manager/Cargo.toml index 14099cdb88..ef5162ca21 100644 --- a/sn_node_manager/Cargo.toml +++ b/sn_node_manager/Cargo.toml @@ -66,6 +66,7 @@ assert_cmd = "2.0.12" assert_fs = "1.0.13" assert_matches = "1.5.0" async-trait = "0.1" +test_utils = { version = "0.1.0", path = "../test_utils"} mockall = "0.11.3" reqwest = { version = "0.11", default-features = false, features = [ "json", diff --git a/sn_node_manager/examples/churn.rs b/sn_node_manager/examples/churn.rs index 29488f1d0e..de090819be 100644 --- a/sn_node_manager/examples/churn.rs +++ b/sn_node_manager/examples/churn.rs @@ -12,7 +12,6 @@ use color_eyre::{ Result, }; use libp2p::PeerId; -use sn_protocol::test_utils::DeploymentInventory; use sn_service_management::{ safenode_manager_proto::{ safe_node_manager_client::SafeNodeManagerClient, GetStatusRequest, @@ -21,6 +20,7 @@ use sn_service_management::{ ServiceStatus, }; use std::{collections::BTreeSet, net::SocketAddr, time::Duration}; +use test_utils::testnet::DeploymentInventory; use tonic::{transport::Channel, Request}; #[derive(Parser, Debug)] @@ -44,6 +44,7 @@ struct Opt { churn_cycles: usize, } +// Run using `cargo run --release --example churn -- --inventory --churn-cycles 2` #[tokio::main] async fn main() -> Result<()> { let opt = Opt::parse(); diff --git a/sn_protocol/Cargo.toml b/sn_protocol/Cargo.toml index e478052637..325d6d1788 100644 --- a/sn_protocol/Cargo.toml +++ b/sn_protocol/Cargo.toml @@ -11,7 +11,6 @@ version = "0.15.3" [features] default = [] -test-utils=[] websockets=[] rpc=["tonic", "prost"] diff --git a/sn_protocol/src/lib.rs b/sn_protocol/src/lib.rs index 67bea4ffb7..f61113e26d 100644 --- a/sn_protocol/src/lib.rs +++ b/sn_protocol/src/lib.rs @@ -19,9 +19,6 @@ pub mod node; pub mod node_rpc; /// Storage types for spends, chunks and registers. pub mod storage; -#[cfg(feature = "test-utils")] -/// Test utilities used among crates -pub mod test_utils; // this includes code generated from .proto files #[allow(clippy::unwrap_used)] diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml new file mode 100644 index 0000000000..9d86a33a65 --- /dev/null +++ b/test_utils/Cargo.toml @@ -0,0 +1,17 @@ +[package] +authors = ["MaidSafe Developers "] +description = "Safe Network Test Utilities" +edition = "2021" +homepage = "https://maidsafe.net" +license = "GPL-3.0" +name = "test_utils" +readme = "README.md" +repository = "https://github.com/maidsafe/safe_network" +version = "0.1.0" + +[dependencies] +color-eyre = "~0.6.2" +dirs-next = "~2.0.0" +libp2p = { version="0.53", features = ["identify", "kad"] } +serde = { version = "1.0.133", features = [ "derive"]} +serde_json = "1.0" \ No newline at end of file diff --git a/test_utils/README.md b/test_utils/README.md new file mode 100644 index 0000000000..d4be657ff2 --- /dev/null +++ b/test_utils/README.md @@ -0,0 +1,2 @@ +# Test utilities +A place to store test utilities that are shared among crates. \ No newline at end of file diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs new file mode 100644 index 0000000000..3466e43bc4 --- /dev/null +++ b/test_utils/src/lib.rs @@ -0,0 +1,9 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + +pub mod testnet; diff --git a/sn_protocol/src/test_utils.rs b/test_utils/src/testnet.rs similarity index 100% rename from sn_protocol/src/test_utils.rs rename to test_utils/src/testnet.rs diff --git a/token_supplies/src/main.rs b/token_supplies/src/main.rs index ae32af5c3c..d7718cf20f 100644 --- a/token_supplies/src/main.rs +++ b/token_supplies/src/main.rs @@ -1,3 +1,11 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + use serde::{Deserialize, Serialize}; use std::fs::{self, File}; use std::io::{self, Read};