Skip to content

Commit

Permalink
refactor: store test utils under a new crate
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin authored and JasonPaulGithub committed Mar 13, 2024
1 parent 7703988 commit cdc574b
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 13 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"sn_registers",
"sn_service_management",
"sn_transfers",
"test_utils",
"token_supplies",
]

Expand Down
2 changes: 1 addition & 1 deletion sn_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
4 changes: 2 additions & 2 deletions sn_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions sn_node/tests/common/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion sn_node/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions sn_node_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion sn_node_manager/examples/churn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)]
Expand All @@ -44,6 +44,7 @@ struct Opt {
churn_cycles: usize,
}

// Run using `cargo run --release --example churn -- --inventory <inventory name/path> --churn-cycles 2`
#[tokio::main]
async fn main() -> Result<()> {
let opt = Opt::parse();
Expand Down
1 change: 0 additions & 1 deletion sn_protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ version = "0.15.3"

[features]
default = []
test-utils=[]
websockets=[]
rpc=["tonic", "prost"]

Expand Down
3 changes: 0 additions & 3 deletions sn_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
17 changes: 17 additions & 0 deletions test_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
authors = ["MaidSafe Developers <[email protected]>"]
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"
2 changes: 2 additions & 0 deletions test_utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Test utilities
A place to store test utilities that are shared among crates.
9 changes: 9 additions & 0 deletions test_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
File renamed without changes.
8 changes: 8 additions & 0 deletions token_supplies/src/main.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down

0 comments on commit cdc574b

Please sign in to comment.