Skip to content

Commit

Permalink
chore(autonomi): use a single utility function to get evm vars
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed Oct 11, 2024
1 parent 5541413 commit c5285c4
Show file tree
Hide file tree
Showing 29 changed files with 181 additions and 107 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ jobs:
- uses: Swatinem/rust-cache@v2

- name: Build binaries
run: cargo build --release --bin safenode --bin autonomi_cli
run: cargo build --release --features local --bin safenode --bin autonomi_cli
timeout-minutes: 30

- name: Start a local network
uses: maidsafe/sn-local-testnet-action@evm-dev
uses: maidsafe/sn-local-testnet-action@main
with:
action: start
enable-evm-testnet: true
Expand Down Expand Up @@ -338,7 +338,7 @@ jobs:

- name: Stop the local network and upload logs
if: always()
uses: maidsafe/sn-local-testnet-action@evm-dev
uses: maidsafe/sn-local-testnet-action@main
with:
action: stop
log_file_prefix: safe_test_logs_e2e
Expand Down Expand Up @@ -592,7 +592,7 @@ jobs:
timeout-minutes: 30

- name: Start a local network
uses: maidsafe/sn-local-testnet-action@evm-dev
uses: maidsafe/sn-local-testnet-action@main
with:
action: start
enable-evm-testnet: true
Expand Down Expand Up @@ -625,7 +625,7 @@ jobs:

- name: Stop the local network and upload logs
if: always()
uses: maidsafe/sn-local-testnet-action@evm-dev
uses: maidsafe/sn-local-testnet-action@main
with:
action: stop
log_file_prefix: safe_test_logs_churn
Expand Down Expand Up @@ -721,7 +721,7 @@ jobs:
timeout-minutes: 30

- name: Start a local network
uses: maidsafe/sn-local-testnet-action@evm-dev
uses: maidsafe/sn-local-testnet-action@main
with:
action: start
enable-evm-testnet: true
Expand Down Expand Up @@ -765,7 +765,7 @@ jobs:

- name: Stop the local network and upload logs
if: always()
uses: maidsafe/sn-local-testnet-action@evm-dev
uses: maidsafe/sn-local-testnet-action@main
with:
action: stop
log_file_prefix: safe_test_logs_data_location
Expand Down
2 changes: 1 addition & 1 deletion autonomi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ full = ["data", "registers", "vault"]
data = []
vault = ["data"]
fs = ["tokio/fs", "data"]
local = ["sn_networking/local", "test_utils/local"]
local = ["sn_networking/local", "test_utils/local", "sn_evm/local"]
registers = ["data"]
loud = []

Expand Down
2 changes: 1 addition & 1 deletion autonomi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod client;
#[cfg(feature = "data")]
mod self_encryption;

pub use sn_evm::evm;
pub use sn_evm::get_evm_network_from_env;
pub use sn_evm::EvmNetwork;
pub use sn_evm::EvmWallet as Wallet;

Expand Down
8 changes: 5 additions & 3 deletions autonomi/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// permissions and limitations relating to use of the SAFE Network Software.

use const_hex::traits::FromHex;
use sn_evm::evm::network_from_env;
use sn_evm::get_evm_network_from_env;
use sn_evm::EvmWallet;
use sn_evm::{Amount, RewardsAddress};
use sn_logging::LogBuilder;
Expand All @@ -16,7 +16,8 @@ use test_utils::evm::get_funded_wallet;
#[tokio::test]
async fn from_private_key() {
let private_key = "0xdb1049e76a813c94be0df47ec3e20533ca676b1b9fef2ddbce9daa117e4da4aa";
let network = network_from_env().expect("Could not get EVM network from environment variables");
let network =
get_evm_network_from_env().expect("Could not get EVM network from environment variables");
let wallet = EvmWallet::new_from_private_key(network, private_key).unwrap();

assert_eq!(
Expand All @@ -29,7 +30,8 @@ async fn from_private_key() {
async fn send_tokens() {
let _log_appender_guard = LogBuilder::init_single_threaded_tokio_test("wallet", false);

let network = network_from_env().expect("Could not get EVM network from environment variables");
let network =
get_evm_network_from_env().expect("Could not get EVM network from environment variables");
let wallet = get_funded_wallet();

let receiving_wallet = EvmWallet::new_with_random_wallet(network);
Expand Down
2 changes: 1 addition & 1 deletion autonomi_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[features]
default = ["metrics"]
local = ["sn_peers_acquisition/local"]
local = ["sn_peers_acquisition/local", "autonomi/local"]
metrics = ["sn_logging/process-metrics"]
network-contacts = ["sn_peers_acquisition/network-contacts"]

Expand Down
4 changes: 2 additions & 2 deletions autonomi_cli/src/access/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// permissions and limitations relating to use of the SAFE Network Software.

use autonomi::client::registers::RegisterSecretKey;
use autonomi::Wallet;
use autonomi::{get_evm_network_from_env, Wallet};
use color_eyre::eyre::{Context, Result};
use color_eyre::Section;
use std::env;
Expand All @@ -24,7 +24,7 @@ const REGISTER_SIGNING_KEY_FILE: &str = "register_signing_key";
pub fn load_evm_wallet() -> Result<Wallet> {
let secret_key =
get_secret_key().wrap_err("The secret key is required to perform this action")?;
let network = crate::network::get_evm_network_from_env()?;
let network = get_evm_network_from_env()?;
let wallet = Wallet::new_from_private_key(network, &secret_key)
.wrap_err("Failed to load EVM wallet from key")?;
Ok(wallet)
Expand Down
26 changes: 0 additions & 26 deletions autonomi_cli/src/access/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,16 @@
// 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 autonomi::EvmNetwork;
use autonomi::Multiaddr;
use color_eyre::eyre::Context;
use color_eyre::Result;
use color_eyre::Section;
use sn_peers_acquisition::PeersArgs;
use sn_peers_acquisition::SAFE_PEERS_ENV;

#[cfg(not(feature = "local"))]
use autonomi::evm::{DATA_PAYMENTS_ADDRESS, PAYMENT_TOKEN_ADDRESS, RPC_URL};

pub async fn get_peers(peers: PeersArgs) -> Result<Vec<Multiaddr>> {
peers.get_peers().await
.wrap_err("Please provide valid Network peers to connect to")
.with_suggestion(|| format!("make sure you've provided network peers using the --peers option or the {SAFE_PEERS_ENV} env var"))
.with_suggestion(|| "a peer address looks like this: /ip4/42.42.42.42/udp/4242/quic-v1/p2p/B64nodePeerIDvdjb3FAJF4ks3moreBase64CharsHere")
}

pub fn get_evm_network_from_env() -> Result<EvmNetwork> {
#[cfg(feature = "local")]
{
println!("Getting EVM network from local CSV as the local feature is enabled");
let network = autonomi::evm::local_evm_network_from_csv()
.wrap_err("Failed to get EVM network from local CSV")
.with_suggestion(|| "make sure you've set up the local EVM network by running `cargo run --bin evm_testnet`")?;
Ok(network)
}
#[cfg(not(feature = "local"))]
{
let network = autonomi::evm::network_from_env()
.wrap_err("Failed to get EVM network from environment variables")
.with_suggestion(|| format!("If connecting to a custom EVM network, make sure you've set the following environment variables: {RPC_URL}, {PAYMENT_TOKEN_ADDRESS} and {DATA_PAYMENTS_ADDRESS}"))?;
if matches!(network, EvmNetwork::Custom(_)) {
println!("Using custom EVM network found from environment variables");
info!("Using custom EVM network found from environment variables {network:?}");
}
Ok(network)
}
}
6 changes: 3 additions & 3 deletions evm_testnet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ impl TestnetData {
println!("Run the CLI or Node with the following env vars set to manually connect to this network:");
println!(
"{}=\"{}\" {}=\"{}\" {}=\"{}\"",
sn_evm::evm::RPC_URL,
sn_evm::RPC_URL,
self.rpc_url,
sn_evm::evm::PAYMENT_TOKEN_ADDRESS,
sn_evm::PAYMENT_TOKEN_ADDRESS,
self.payment_token_address,
sn_evm::evm::DATA_PAYMENTS_ADDRESS,
sn_evm::DATA_PAYMENTS_ADDRESS,
self.data_payments_address
);
println!("--------------");
Expand Down
1 change: 1 addition & 0 deletions evmlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ version = "0.1.0"

[features]
wasm-bindgen = ["alloy/wasm-bindgen"]
local = []

[dependencies]
alloy = { version = "0.4.2", default-features = false, features = ["std", "reqwest-rustls-tls", "provider-anvil-node", "sol-types", "json", "signers", "contract", "signer-local", "network"] }
Expand Down
8 changes: 8 additions & 0 deletions evmlib/src/common.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 alloy::primitives::FixedBytes;

pub type Address = alloy::primitives::Address;
Expand Down
8 changes: 8 additions & 0 deletions evmlib/src/contract/data_payments/error.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 crate::contract::network_token;
use alloy::transports::{RpcError, TransportErrorKind};

Expand Down
8 changes: 8 additions & 0 deletions evmlib/src/contract/data_payments/mod.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.

pub mod error;

use crate::common;
Expand Down
8 changes: 8 additions & 0 deletions evmlib/src/contract/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
// 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 data_payments;
pub mod network_token;
8 changes: 8 additions & 0 deletions evmlib/src/contract/network_token.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 crate::common::{Address, TxHash, U256};
use crate::contract::network_token::NetworkTokenContract::NetworkTokenContractInstance;
use alloy::providers::{Network, Provider};
Expand Down
8 changes: 8 additions & 0 deletions evmlib/src/cryptography.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 crate::common::Hash;
use alloy::primitives::keccak256;

Expand Down
8 changes: 8 additions & 0 deletions evmlib/src/event.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 crate::common::{Address, Hash, U256};
use alloy::primitives::{b256, FixedBytes};
use alloy::rpc::types::Log;
Expand Down
8 changes: 8 additions & 0 deletions evmlib/src/lib.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 crate::common::{Address, QuoteHash, TxHash, U256};
use crate::transaction::verify_data_payment;
use alloy::primitives::address;
Expand Down
8 changes: 8 additions & 0 deletions evmlib/src/testnet.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 crate::common::Address;
use crate::contract::data_payments::DataPaymentsHandler;
use crate::contract::network_token::NetworkToken;
Expand Down
8 changes: 8 additions & 0 deletions evmlib/src/transaction.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 crate::common::{Address, QuoteHash, TxHash, U256};
use crate::event::{ChunkPaymentEvent, DATA_PAYMENT_EVENT_SIGNATURE};
use crate::Network;
Expand Down
Loading

0 comments on commit c5285c4

Please sign in to comment.