Skip to content

Commit

Permalink
Merge pull request maidsafe#2181 from RolandSherwin/emv_ci_2
Browse files Browse the repository at this point in the history
feat: enable CI action
  • Loading branch information
RolandSherwin authored Oct 8, 2024
2 parents 5c61df8 + 4dcda6a commit cbb89f9
Show file tree
Hide file tree
Showing 15 changed files with 424 additions and 355 deletions.
566 changes: 289 additions & 277 deletions .github/workflows/merge.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion autonomi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data = []
vault = ["data"]
files = ["fs", "data"]
fs = ["tokio/fs"]
local = ["sn_networking/local-discovery"]
local-discovery = ["sn_networking/local-discovery"]
registers = []

[dependencies]
Expand Down Expand Up @@ -47,6 +47,7 @@ xor_name = "5.0.0"

[dev-dependencies]
eyre = "0.6.5"
sn_logging = { path = "../sn_logging", version = "0.2.33" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
# Do not specify the version field. Release process expects even the local dev deps to be published.
# Removing the version field is a workaround.
Expand Down
4 changes: 2 additions & 2 deletions autonomi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cargo run --bin=safenode-manager --features=local-discovery -- local run --build
```sh
$ EVM_NETWORK=local cargo test --package=autonomi --features=local
# Or with logs
$ RUST_LOG=autonomi EVM_NETWORK=local cargo test --package=autonomi --features=local -- --nocapture
$ RUST_LOG=autonomi EVM_NETWORK=local cargo test --package=autonomi --features=local-discovery -- --nocapture
```

### Using a live testnet or mainnet
Expand All @@ -57,7 +57,7 @@ cargo run --bin=safenode-manager --features=local-discovery -- local run --build
```sh
$ EVM_NETWORK=arbitrum-one EVM_PRIVATE_KEY=<PRIVATE_KEY> cargo test --package=autonomi --features=local
# Or with logs
$ RUST_LOG=autonomi EVM_NETWORK=arbitrum-one EVM_PRIVATE_KEY=<PRIVATE_KEY> cargo test --package=autonomi --features=local -- --nocapture
$ RUST_LOG=autonomi EVM_NETWORK=arbitrum-one EVM_PRIVATE_KEY=<PRIVATE_KEY> cargo test --package=autonomi --features=local-discovery -- --nocapture
```

## Faucet (local)
Expand Down
24 changes: 18 additions & 6 deletions autonomi/tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
// 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 bytes::Bytes;
use eyre::Result;
use libp2p::Multiaddr;
use rand::Rng;
use sn_peers_acquisition::parse_peer_addr;
Expand All @@ -23,10 +32,13 @@ pub fn enable_logging() {
/// Parse the `SAFE_PEERS` env var into a list of Multiaddrs.
///
/// An empty `Vec` will be returned if the env var is not set.
pub fn peers_from_env() -> Result<Vec<Multiaddr>, libp2p::multiaddr::Error> {
let Ok(peers_str) = env::var("SAFE_PEERS") else {
return Ok(vec![]);
};

peers_str.split(',').map(parse_peer_addr).collect()
pub fn peers_from_env() -> Result<Vec<Multiaddr>> {
let bootstrap_peers = if cfg!(feature = "local-discovery") {
Ok(vec![])
} else if let Ok(peers_str) = env::var("SAFE_PEERS") {
peers_str.split(',').map(parse_peer_addr).collect()
} else {
Ok(vec![])
}?;
Ok(bootstrap_peers)
}
11 changes: 10 additions & 1 deletion autonomi/tests/evm/file.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.

#[cfg(feature = "evm-payments")]
mod test {
use autonomi::Client;
Expand All @@ -9,7 +17,8 @@ mod test {

#[tokio::test]
async fn file() -> Result<(), Box<dyn std::error::Error>> {
common::enable_logging();
let _log_appender_guard =
sn_logging::LogBuilder::init_single_threaded_tokio_test("file", false);

let mut client = Client::connect(&[]).await.unwrap();
let mut wallet = get_funded_wallet();
Expand Down
23 changes: 17 additions & 6 deletions autonomi/tests/file.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
// 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.

#![cfg(feature = "files")]

mod common;

use autonomi::Client;
use common::peers_from_env;
use eyre::Result;
use sn_logging::LogBuilder;
use std::time::Duration;
use test_utils::evm::get_funded_wallet;
use tokio::time::sleep;

#[tokio::test]
async fn file() -> Result<(), Box<dyn std::error::Error>> {
common::enable_logging();
async fn file() -> Result<()> {
let _log_appender_guard = LogBuilder::init_single_threaded_tokio_test("file", false);

let mut client = Client::connect(&[]).await.unwrap();
let mut client = Client::connect(&peers_from_env()?).await?;
let wallet = get_funded_wallet();

let (root, addr) = client
Expand All @@ -32,10 +43,10 @@ async fn file() -> Result<(), Box<dyn std::error::Error>> {

#[cfg(feature = "vault")]
#[tokio::test]
async fn file_into_vault() -> eyre::Result<()> {
common::enable_logging();
async fn file_into_vault() -> Result<()> {
let _log_appender_guard = LogBuilder::init_single_threaded_tokio_test("file", false);

let mut client = Client::connect(&[]).await?;
let mut client = Client::connect(&peers_from_env()?).await?;
let mut wallet = get_funded_wallet();
let client_sk = bls::SecretKey::random();

Expand Down
23 changes: 18 additions & 5 deletions autonomi/tests/put.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
// 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.

#![cfg(feature = "data")]

mod common;

use autonomi::Client;
use common::peers_from_env;
use eyre::Result;
use sn_logging::LogBuilder;
use std::time::Duration;
use test_utils::evm::get_funded_wallet;
use tokio::time::sleep;

#[tokio::test]
async fn put() {
common::enable_logging();
async fn put() -> Result<()> {
let _log_appender_guard = LogBuilder::init_single_threaded_tokio_test("put", false);

let client = Client::connect(&[]).await.unwrap();
let client = Client::connect(&peers_from_env()?).await?;
let wallet = get_funded_wallet();
let data = common::gen_random_data(1024 * 1024 * 10);

let addr = client.put(data.clone(), &wallet).await.unwrap();
let addr = client.put(data.clone(), &wallet).await?;

sleep(Duration::from_secs(10)).await;

let data_fetched = client.get(addr).await.unwrap();
let data_fetched = client.get(addr).await?;
assert_eq!(data, data_fetched, "data fetched should match data put");

Ok(())
}
19 changes: 16 additions & 3 deletions autonomi/tests/register.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
// 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.

#![cfg(feature = "registers")]

mod common;

use autonomi::Client;
use bytes::Bytes;
use common::peers_from_env;
use eyre::Result;
use rand::Rng;
use sn_logging::LogBuilder;
use std::time::Duration;
use test_utils::evm::get_funded_wallet;
use tokio::time::sleep;

#[tokio::test]
async fn register() {
common::enable_logging();
async fn register() -> Result<()> {
let _log_appender_guard = LogBuilder::init_single_threaded_tokio_test("register", false);

let client = Client::connect(&[]).await.unwrap();
let client = Client::connect(&peers_from_env()?).await?;
let wallet = get_funded_wallet();

// Owner key of the register.
Expand Down Expand Up @@ -46,4 +57,6 @@ async fn register() {
// Fetch and verify the register contains the updated value
let register = client.register_get(*register.address()).await.unwrap();
assert_eq!(register.values(), vec![Bytes::from(vec![5, 6, 7, 8])]);

Ok(())
}
11 changes: 11 additions & 0 deletions autonomi/tests/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
// 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.

mod common;

use const_hex::traits::FromHex;
use evmlib::common::{Address, Amount};
use evmlib::utils::evm_network_from_env;
use evmlib::wallet::Wallet;
use sn_logging::LogBuilder;
use test_utils::evm::get_funded_wallet;

#[tokio::test]
Expand All @@ -21,6 +30,8 @@ async fn from_private_key() {

#[tokio::test]
async fn send_tokens() {
let _log_appender_guard = LogBuilder::init_single_threaded_tokio_test("wallet", false);

let network =
evm_network_from_env().expect("Could not get EVM network from environment variables");
let wallet = get_funded_wallet();
Expand Down
17 changes: 10 additions & 7 deletions autonomi/tests/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
// 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 std::time::Duration;

use autonomi::Client;
use common::peers_from_env;
use test_utils::evm::get_funded_wallet;
use tokio::time::sleep;
use wasm_bindgen_test::*;
Expand All @@ -14,13 +23,7 @@ wasm_bindgen_test_configure!(run_in_browser);
async fn file() -> Result<(), Box<dyn std::error::Error>> {
common::enable_logging();

let peers = vec![
"/ip4/127.0.0.1/tcp/35499/ws/p2p/12D3KooWGN5RqREZ4RYtsUc3DNCkrNSVXEzTYEbMb1AZx2rNddoW"
.try_into()
.expect("str to be valid multiaddr"),
];

let client = Client::connect(&peers).await.unwrap();
let client = Client::connect(&peers_from_env()?).await.unwrap();
let wallet = get_funded_wallet();

let data = common::gen_random_data(1024 * 1024 * 10);
Expand Down
40 changes: 0 additions & 40 deletions autonomi_cli/src/log_metrics.rs

This file was deleted.

31 changes: 26 additions & 5 deletions autonomi_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extern crate tracing;
mod access;
mod actions;
mod commands;
mod log_metrics;
mod opt;

pub use access::data_dir;
Expand All @@ -23,18 +22,40 @@ use clap::Parser;
use color_eyre::Result;

use opt::Opt;
use sn_logging::{LogBuilder, LogFormat, ReloadHandle, WorkerGuard};
use tracing::Level;

fn main() -> Result<()> {
#[tokio::main]
async fn main() -> Result<()> {
color_eyre::install().expect("Failed to initialise error handler");
let opt = Opt::parse();
log_metrics::init_logging_and_metrics(&opt).expect("Failed to initialise logging and metrics");
let _log_guards = init_logging_and_metrics(&opt)?;

// Log the full command that was run and the git version
info!("\"{}\"", std::env::args().collect::<Vec<_>>().join(" "));
let version = sn_build_info::git_info();
info!("autonomi client built with git version: {version}");
println!("autonomi client built with git version: {version}");

let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime");
rt.block_on(commands::handle_subcommand(opt))
commands::handle_subcommand(opt).await?;

Ok(())
}

fn init_logging_and_metrics(opt: &Opt) -> Result<(ReloadHandle, Option<WorkerGuard>)> {
let logging_targets = vec![
("sn_networking".to_string(), Level::INFO),
("sn_build_info".to_string(), Level::TRACE),
("autonomi_cli".to_string(), Level::TRACE),
("sn_logging".to_string(), Level::TRACE),
("sn_peers_acquisition".to_string(), Level::TRACE),
("sn_protocol".to_string(), Level::TRACE),
("sn_registers".to_string(), Level::TRACE),
("sn_evm".to_string(), Level::TRACE),
];
let mut log_builder = LogBuilder::new(logging_targets);
log_builder.output_dest(opt.log_output_dest.clone());
log_builder.format(opt.log_format.unwrap_or(LogFormat::Default));
let guards = log_builder.initialize()?;
Ok(guards)
}
Loading

0 comments on commit cbb89f9

Please sign in to comment.