diff --git a/Cargo.lock b/Cargo.lock index f5267b6c79..8840b0fa11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1677,6 +1677,7 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", + "serde", "wasm-bindgen", "windows-targets 0.52.6", ] @@ -2380,6 +2381,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", + "serde", ] [[package]] @@ -2763,6 +2765,7 @@ dependencies = [ "getrandom 0.2.15", "rand 0.8.5", "serde", + "serde_with", "thiserror", "tokio", "tracing", @@ -4343,6 +4346,7 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg 1.3.0", "hashbrown 0.12.3", + "serde", ] [[package]] @@ -5708,6 +5712,7 @@ dependencies = [ "sn-node-manager", "sn-releases", "sn_build_info", + "sn_evm", "sn_peers_acquisition", "sn_protocol", "sn_service_management", @@ -7797,6 +7802,36 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e28bdad6db2b8340e449f7108f020b3b092e8583a9e3fb82713e1d4e71fe817" +dependencies = [ + "base64 0.22.1", + "chrono", + "hex 0.4.3", + "indexmap 1.9.3", + "indexmap 2.6.0", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d846214a9854ef724f3da161b426242d8de7c1fc7de2f89bb1efcb154dca79d" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "serde_yaml" version = "0.9.34+deprecated" diff --git a/evmlib/Cargo.toml b/evmlib/Cargo.toml index fae3cba0cb..9a26778c36 100644 --- a/evmlib/Cargo.toml +++ b/evmlib/Cargo.toml @@ -16,6 +16,7 @@ local = [] alloy = { version = "0.4.2", default-features = false, features = ["std", "reqwest-rustls-tls", "provider-anvil-node", "sol-types", "json", "signers", "contract", "signer-local", "network"] } dirs-next = "~2.0.0" serde = "1.0" +serde_with = { version = "3.11.0", features = ["macros"] } thiserror = "1.0" tracing = { version = "~0.1.26" } tokio = "1.38.0" diff --git a/evmlib/src/lib.rs b/evmlib/src/lib.rs index 6e29a7f4d5..8bf3734265 100644 --- a/evmlib/src/lib.rs +++ b/evmlib/src/lib.rs @@ -10,6 +10,8 @@ use crate::common::{Address, QuoteHash, TxHash, U256}; use crate::transaction::verify_data_payment; use alloy::primitives::address; use alloy::transports::http::reqwest; +use serde::{Deserialize, Serialize}; +use serde_with::{serde_as, DisplayFromStr}; use std::str::FromStr; use std::sync::LazyLock; @@ -38,8 +40,10 @@ const ARBITRUM_ONE_PAYMENT_TOKEN_ADDRESS: Address = const ARBITRUM_ONE_DATA_PAYMENTS_ADDRESS: Address = address!("887930F30EDEb1B255Cd2273C3F4400919df2EFe"); -#[derive(Clone, Debug, PartialEq)] +#[serde_as] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct CustomNetwork { + #[serde_as(as = "DisplayFromStr")] pub rpc_url_http: reqwest::Url, pub payment_token_address: Address, pub data_payments_address: Address, @@ -57,12 +61,21 @@ impl CustomNetwork { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum Network { ArbitrumOne, Custom(CustomNetwork), } +impl std::fmt::Display for Network { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Network::ArbitrumOne => write!(f, "evm-arbitrum-one"), + Network::Custom(_) => write!(f, "evm-custom"), + } + } +} + impl Network { pub fn new_custom(rpc_url: &str, payment_token_addr: &str, chunk_payments_addr: &str) -> Self { Self::Custom(CustomNetwork::new( diff --git a/node-launchpad/Cargo.toml b/node-launchpad/Cargo.toml index 3b55815bfe..cb9c03ab3f 100644 --- a/node-launchpad/Cargo.toml +++ b/node-launchpad/Cargo.toml @@ -52,6 +52,7 @@ serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.107" signal-hook = "0.3.17" sn_build_info = { path = "../sn_build_info", version = "0.1.15" } +sn_evm = { path = "../sn_evm", version = "0.1" } sn-node-manager = { version = "0.10.6", path = "../sn_node_manager" } sn_peers_acquisition = { version = "0.5.3", path = "../sn_peers_acquisition" } sn_protocol = { path = "../sn_protocol", version = "0.17.11" } diff --git a/node-launchpad/src/node_mgmt.rs b/node-launchpad/src/node_mgmt.rs index 0ee2c22294..c8812e4b20 100644 --- a/node-launchpad/src/node_mgmt.rs +++ b/node-launchpad/src/node_mgmt.rs @@ -1,19 +1,17 @@ -use std::path::PathBuf; - +use crate::action::{Action, StatusActions}; +use crate::connection_mode::ConnectionMode; use color_eyre::eyre::{eyre, Error}; -use sn_node_manager::{ - add_services::config::PortRange, config::get_node_registry_path, VerbosityLevel, -}; +use sn_evm::RewardsAddress; +use sn_node_manager::{add_services::config::PortRange, config::get_node_registry_path, VerbosityLevel}; use sn_peers_acquisition::PeersArgs; +use sn_releases::{self, ReleaseType, SafeReleaseRepoActions}; use sn_service_management::NodeRegistry; +use std::{ + path::PathBuf, + str::FromStr, +}; use tokio::sync::mpsc::UnboundedSender; -use crate::action::{Action, StatusActions}; - -use crate::connection_mode::ConnectionMode; - -use sn_releases::{self, ReleaseType, SafeReleaseRepoActions}; - pub const PORT_MAX: u32 = 65535; pub const PORT_MIN: u32 = 1024; @@ -302,6 +300,7 @@ async fn scale_down_nodes(config: &NodeConfig, count: u16) { None, // We don't care about the port, as we are scaling down config.owner.clone(), config.peers_args.clone(), + RewardsAddress::from_str("0x1111111111111111111111111111111111111111").unwrap(), None, None, config.safenode_path.clone(), @@ -375,6 +374,7 @@ async fn add_nodes( port_range, config.owner.clone(), config.peers_args.clone(), + RewardsAddress::from_str("0x1111111111111111111111111111111111111111").unwrap(), None, None, config.safenode_path.clone(), diff --git a/sn_evm/src/lib.rs b/sn_evm/src/lib.rs index f4c70e04a6..a62fa5c0fd 100644 --- a/sn_evm/src/lib.rs +++ b/sn_evm/src/lib.rs @@ -17,6 +17,7 @@ pub use evmlib::utils::get_evm_network_from_env; pub use evmlib::utils::{DATA_PAYMENTS_ADDRESS, PAYMENT_TOKEN_ADDRESS, RPC_URL}; pub use evmlib::wallet::Error as EvmWalletError; pub use evmlib::wallet::Wallet as EvmWallet; +pub use evmlib::CustomNetwork; pub use evmlib::Network as EvmNetwork; mod amount; diff --git a/sn_node_manager/src/add_services/config.rs b/sn_node_manager/src/add_services/config.rs index 2d5cac69dc..7d44017f26 100644 --- a/sn_node_manager/src/add_services/config.rs +++ b/sn_node_manager/src/add_services/config.rs @@ -16,6 +16,7 @@ use std::{ path::PathBuf, str::FromStr, }; +use sn_evm::{EvmNetwork, RewardsAddress}; #[derive(Clone, Debug)] pub enum PortRange { @@ -72,6 +73,7 @@ pub struct InstallNodeServiceCtxBuilder { pub bootstrap_peers: Vec, pub data_dir_path: PathBuf, pub env_variables: Option>, + pub evm_network: EvmNetwork, pub genesis: bool, pub home_network: bool, pub local: bool, @@ -84,6 +86,7 @@ pub struct InstallNodeServiceCtxBuilder { pub node_ip: Option, pub node_port: Option, pub owner: Option, + pub rewards_address: RewardsAddress, pub rpc_socket_addr: SocketAddr, pub safenode_path: PathBuf, pub service_user: Option, @@ -154,6 +157,19 @@ impl InstallNodeServiceCtxBuilder { args.push(OsString::from(peers_str)); } + args.push(OsString::from("--rewards-address")); + args.push(OsString::from(self.rewards_address.to_string())); + + args.push(OsString::from(self.evm_network.to_string())); + if let EvmNetwork::Custom(custom_network) = &self.evm_network { + args.push(OsString::from("--rpc-url")); + args.push(OsString::from(custom_network.rpc_url_http.to_string())); + args.push(OsString::from("--payment-token-address")); + args.push(OsString::from(custom_network.payment_token_address.to_string())); + args.push(OsString::from("--data-payments-address")); + args.push(OsString::from(custom_network.data_payments_address.to_string())); + } + Ok(ServiceInstallCtx { args, autostart: self.autostart, @@ -175,6 +191,7 @@ pub struct AddNodeServiceOptions { pub delete_safenode_src: bool, pub enable_metrics_server: bool, pub env_variables: Option>, + pub evm_network: EvmNetwork, pub genesis: bool, pub home_network: bool, pub local: bool, @@ -185,6 +202,7 @@ pub struct AddNodeServiceOptions { pub node_ip: Option, pub node_port: Option, pub owner: Option, + pub rewards_address: RewardsAddress, pub rpc_address: Option, pub rpc_port: Option, pub safenode_src_path: PathBuf, @@ -319,3 +337,257 @@ pub struct AddDaemonServiceOptions { pub user: String, pub version: String, } + +#[cfg(test)] +mod tests { + use super::*; + use std::net::{IpAddr, Ipv4Addr}; + use sn_evm::{CustomNetwork, RewardsAddress}; + + fn create_default_builder() -> InstallNodeServiceCtxBuilder { + InstallNodeServiceCtxBuilder { + autostart: true, + bootstrap_peers: vec![], + data_dir_path: PathBuf::from("/data"), + env_variables: None, + evm_network: EvmNetwork::ArbitrumOne, + genesis: false, + home_network: false, + local: false, + log_dir_path: PathBuf::from("/logs"), + log_format: None, + name: "test-node".to_string(), + max_archived_log_files: None, + max_log_files: None, + metrics_port: None, + node_ip: None, + node_port: None, + owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + ).unwrap(), + rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080), + safenode_path: PathBuf::from("/bin/safenode"), + service_user: None, + upnp: false, + } + } + + fn create_custom_evm_network_builder() -> InstallNodeServiceCtxBuilder { + InstallNodeServiceCtxBuilder { + autostart: true, + bootstrap_peers: vec![], + data_dir_path: PathBuf::from("/data"), + env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse().unwrap(), + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + ).unwrap(), + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + ).unwrap(), + }), + genesis: false, + home_network: false, + local: false, + log_dir_path: PathBuf::from("/logs"), + log_format: None, + name: "test-node".to_string(), + max_archived_log_files: None, + max_log_files: None, + metrics_port: None, + node_ip: None, + node_port: None, + owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + ).unwrap(), + rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080), + safenode_path: PathBuf::from("/bin/safenode"), + service_user: None, + upnp: false, + } + } + + fn create_builder_with_all_options_enabled() -> InstallNodeServiceCtxBuilder { + InstallNodeServiceCtxBuilder { + autostart: true, + bootstrap_peers: vec![], + data_dir_path: PathBuf::from("/data"), + env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse().unwrap(), + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + ).unwrap(), + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + ).unwrap(), + }), + genesis: false, + home_network: false, + local: false, + log_dir_path: PathBuf::from("/logs"), + log_format: None, + name: "test-node".to_string(), + max_archived_log_files: Some(10), + max_log_files: Some(10), + metrics_port: None, + node_ip: None, + node_port: None, + owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + ).unwrap(), + rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080), + safenode_path: PathBuf::from("/bin/safenode"), + service_user: None, + upnp: false, + } + } + + #[test] + fn build_should_assign_expected_values_when_mandatory_options_are_provided() { + let builder = create_default_builder(); + let result = builder.build().unwrap(); + + assert_eq!(result.label.to_string(), "test-node"); + assert_eq!(result.program, PathBuf::from("/bin/safenode")); + assert_eq!(result.autostart, true); + assert_eq!(result.username, None); + assert_eq!(result.working_directory, None); + + let expected_args = vec![ + "--rpc", + "127.0.0.1:8080", + "--root-dir", + "/data", + "--log-output-dest", + "/logs", + "--rewards-address", + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + "evm-arbitrum-one" + ]; + assert_eq!( + result.args.iter().map(|os| os.to_str().unwrap()).collect::>(), + expected_args + ); + } + + #[test] + fn build_should_assign_expected_values_when_a_custom_evm_network_is_provided() { + let builder = create_custom_evm_network_builder(); + let result = builder.build().unwrap(); + + assert_eq!(result.label.to_string(), "test-node"); + assert_eq!(result.program, PathBuf::from("/bin/safenode")); + assert_eq!(result.autostart, true); + assert_eq!(result.username, None); + assert_eq!(result.working_directory, None); + + let expected_args = vec![ + "--rpc", + "127.0.0.1:8080", + "--root-dir", + "/data", + "--log-output-dest", + "/logs", + "--rewards-address", + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + "evm-custom", + "--rpc-url", + "http://localhost:8545/", + "--payment-token-address", + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + "--data-payments-address", + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + ]; + assert_eq!( + result.args.iter().map(|os| os.to_str().unwrap()).collect::>(), + expected_args + ); + } + + #[test] + fn build_should_assign_expected_values_when_all_options_are_enabled() { + let mut builder = create_builder_with_all_options_enabled(); + builder.genesis = true; + builder.home_network = true; + builder.local = true; + builder.log_format = Some(LogFormat::Json); + builder.upnp = true; + builder.node_ip = Some(Ipv4Addr::new(192, 168, 1, 1)); + builder.node_port = Some(12345); + builder.metrics_port = Some(9090); + builder.owner = Some("test-owner".to_string()); + builder.bootstrap_peers = vec![ + "/ip4/127.0.0.1/tcp/8080".parse().unwrap(), + "/ip4/192.168.1.1/tcp/8081".parse().unwrap(), + ]; + builder.service_user = Some("safenode-user".to_string()); + + let result = builder.build().unwrap(); + + let expected_args = vec![ + "--rpc", "127.0.0.1:8080", + "--root-dir", + "/data", + "--log-output-dest", + "/logs", + "--first", + "--home-network", + "--local", + "--log-format", + "json", + "--upnp", + "--ip", + "192.168.1.1", + "--port", + "12345", + "--metrics-server-port", + "9090", + "--owner", + "test-owner", + "--max-archived-log-files", + "10", + "--max-log-files", + "10", + "--peer", + "/ip4/127.0.0.1/tcp/8080,/ip4/192.168.1.1/tcp/8081", + "--rewards-address", + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + "evm-custom", + "--rpc-url", + "http://localhost:8545/", + "--payment-token-address", + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + "--data-payments-address", + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + ]; + assert_eq!( + result.args.iter().map(|os| os.to_str().unwrap()).collect::>(), + expected_args + ); + assert_eq!(result.username, Some("safenode-user".to_string())); + } + + #[test] + fn build_should_assign_expected_values_when_environment_variables_are_provided() { + let mut builder = create_default_builder(); + builder.env_variables = Some(vec![ + ("VAR1".to_string(), "value1".to_string()), + ("VAR2".to_string(), "value2".to_string()), + ]); + + let result = builder.build().unwrap(); + + assert_eq!( + result.environment, + Some(vec![ + ("VAR1".to_string(), "value1".to_string()), + ("VAR2".to_string(), "value2".to_string()), + ]) + ); + } +} diff --git a/sn_node_manager/src/add_services/mod.rs b/sn_node_manager/src/add_services/mod.rs index 86137d881d..96c6cf37a7 100644 --- a/sn_node_manager/src/add_services/mod.rs +++ b/sn_node_manager/src/add_services/mod.rs @@ -222,6 +222,7 @@ pub async fn add_node( bootstrap_peers: options.bootstrap_peers.clone(), data_dir_path: service_data_dir_path.clone(), env_variables: options.env_variables.clone(), + evm_network: options.evm_network.clone(), genesis: options.genesis, home_network: options.home_network, local: options.local, @@ -234,6 +235,7 @@ pub async fn add_node( node_ip: options.node_ip, node_port, owner: owner.clone(), + rewards_address: options.rewards_address, rpc_socket_addr, safenode_path: service_safenode_path.clone(), service_user: options.user.clone(), @@ -256,6 +258,7 @@ pub async fn add_node( auto_restart: options.auto_restart, connected_peers: None, data_dir_path: service_data_dir_path.clone(), + evm_network: options.evm_network.clone(), genesis: options.genesis, home_network: options.home_network, listen_addr: None, @@ -268,6 +271,7 @@ pub async fn add_node( node_ip: options.node_ip, node_port, number: node_number, + rewards_address: options.rewards_address, reward_balance: None, rpc_socket_addr, owner: owner.clone(), diff --git a/sn_node_manager/src/add_services/tests.rs b/sn_node_manager/src/add_services/tests.rs index 34a572ffce..2d37f436f8 100644 --- a/sn_node_manager/src/add_services/tests.rs +++ b/sn_node_manager/src/add_services/tests.rs @@ -23,7 +23,7 @@ use libp2p::Multiaddr; use mockall::{mock, predicate::*, Sequence}; use predicates::prelude::*; use service_manager::ServiceInstallCtx; -use sn_evm::AttoTokens; +use sn_evm::{AttoTokens, CustomNetwork, EvmNetwork, RewardsAddress}; use sn_service_management::{auditor::AuditorServiceData, control::ServiceControl}; use sn_service_management::{error::Result as ServiceControlResult, NatDetectionStatus}; use sn_service_management::{ @@ -115,6 +115,15 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode1"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: true, home_network: false, local: true, @@ -127,6 +136,9 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: node_data_dir .to_path_buf() @@ -172,6 +184,18 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -203,6 +227,22 @@ async fn add_genesis_node_should_use_latest_version_and_add_one_service() -> Res node_data_dir.to_path_buf().join("safenode1") ); assert_matches!(node_registry.nodes[0].status, ServiceStatus::Added); + assert_eq!( + node_registry.nodes[0].evm_network, + EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3" + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC" + )?, + }) + ); + assert_eq!( + node_registry.nodes[0].rewards_address, + RewardsAddress::from_str("0x03B770D9cD32077cC0bF330c13C114a87643B124")? + ); Ok(()) } @@ -225,6 +265,15 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: true, home_network: false, listen_addr: None, @@ -240,6 +289,9 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n pid: None, peer_id: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), status: ServiceStatus::Added, @@ -294,6 +346,18 @@ async fn add_genesis_node_should_return_an_error_if_there_is_already_a_genesis_n user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -365,6 +429,18 @@ async fn add_genesis_node_should_return_an_error_if_count_is_greater_than_1() -> user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -421,6 +497,15 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode1"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, local: false, @@ -438,6 +523,9 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( .to_path_buf() .join("safenode1") .join(SAFENODE_FILE_NAME), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, service_user: Some(get_username()), upnp: false, } @@ -461,6 +549,15 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode2"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, local: false, @@ -473,6 +570,9 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8083), safenode_path: node_data_dir .to_path_buf() @@ -501,6 +601,15 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( data_dir_path: node_data_dir.to_path_buf().join("safenode3"), bootstrap_peers: vec![], env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, local: false, @@ -513,6 +622,9 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8085), safenode_path: node_data_dir .to_path_buf() @@ -559,6 +671,18 @@ async fn add_node_should_use_latest_version_and_add_three_services() -> Result<( user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -664,6 +788,15 @@ async fn add_node_should_update_the_bootstrap_peers_inside_node_registry() -> Re bootstrap_peers: new_peers.clone(), data_dir_path: node_data_dir.to_path_buf().join("safenode1"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, local: false, @@ -676,6 +809,9 @@ async fn add_node_should_update_the_bootstrap_peers_inside_node_registry() -> Re node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), safenode_path: node_data_dir .to_path_buf() @@ -685,6 +821,7 @@ async fn add_node_should_update_the_bootstrap_peers_inside_node_registry() -> Re upnp: false, } .build()?; + mock_service_control .expect_install() .times(1) @@ -713,14 +850,26 @@ async fn add_node_should_update_the_bootstrap_peers_inside_node_registry() -> Re node_port: None, rpc_address: None, rpc_port: None, - safenode_dir_path: temp_dir.to_path_buf(), safenode_src_path: safenode_download_path.to_path_buf(), + safenode_dir_path: temp_dir.to_path_buf(), service_data_dir_path: node_data_dir.to_path_buf(), service_log_dir_path: node_logs_dir.to_path_buf(), upnp: false, user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -800,6 +949,15 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode1"), env_variables: env_variables.clone(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, local: false, @@ -812,6 +970,9 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), safenode_path: node_data_dir .to_path_buf() @@ -857,6 +1018,18 @@ async fn add_node_should_update_the_environment_variables_inside_node_registry() user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -909,6 +1082,15 @@ async fn add_new_node_should_add_another_service() -> Result<()> { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: true, home_network: false, listen_addr: None, @@ -924,6 +1106,9 @@ async fn add_new_node_should_add_another_service() -> Result<()> { owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -957,6 +1142,15 @@ async fn add_new_node_should_add_another_service() -> Result<()> { bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode2"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, local: false, @@ -968,6 +1162,9 @@ async fn add_new_node_should_add_another_service() -> Result<()> { name: "safenode2".to_string(), node_ip: None, node_port: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8083), owner: None, safenode_path: node_data_dir @@ -1015,6 +1212,18 @@ async fn add_new_node_should_add_another_service() -> Result<()> { user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -1107,6 +1316,15 @@ async fn add_node_should_use_custom_ip() -> Result<()> { ), OsString::from("--ip"), OsString::from(custom_ip.to_string()), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -1153,6 +1371,18 @@ async fn add_node_should_use_custom_ip() -> Result<()> { user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -1210,6 +1440,15 @@ async fn add_node_should_use_custom_ports_for_one_service() -> Result<()> { bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode1"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, local: false, @@ -1222,6 +1461,9 @@ async fn add_node_should_use_custom_ports_for_one_service() -> Result<()> { node_ip: None, node_port: Some(custom_port), owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), safenode_path: node_data_dir .to_path_buf() @@ -1268,6 +1510,18 @@ async fn add_node_should_use_custom_ports_for_one_service() -> Result<()> { user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -1345,6 +1599,15 @@ async fn add_node_should_use_a_custom_port_range() -> Result<()> { ), OsString::from("--port"), OsString::from("12000"), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -1394,6 +1657,15 @@ async fn add_node_should_use_a_custom_port_range() -> Result<()> { ), OsString::from("--port"), OsString::from("12001"), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -1443,6 +1715,15 @@ async fn add_node_should_use_a_custom_port_range() -> Result<()> { ), OsString::from("--port"), OsString::from("12002"), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -1489,6 +1770,18 @@ async fn add_node_should_use_a_custom_port_range() -> Result<()> { user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -1521,6 +1814,15 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_is_used() -> R auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1536,6 +1838,9 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_is_used() -> R owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1588,6 +1893,18 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_is_used() -> R user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &MockServiceControl::new(), @@ -1618,6 +1935,15 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_in_range_is_us auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1633,6 +1959,9 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_in_range_is_us owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1685,6 +2014,18 @@ async fn add_node_should_return_an_error_if_duplicate_custom_port_in_range_is_us user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &MockServiceControl::new(), @@ -1746,14 +2087,26 @@ async fn add_node_should_return_an_error_if_port_and_node_count_do_not_match() - node_port: Some(PortRange::Range(12000, 12002)), rpc_address: None, rpc_port: None, - safenode_dir_path: temp_dir.to_path_buf(), safenode_src_path: safenode_download_path.to_path_buf(), + safenode_dir_path: temp_dir.to_path_buf(), service_data_dir_path: node_data_dir.to_path_buf(), service_log_dir_path: node_logs_dir.to_path_buf(), upnp: false, user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &MockServiceControl::new(), @@ -1828,6 +2181,18 @@ async fn add_node_should_return_an_error_if_multiple_services_are_specified_with user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &MockServiceControl::new(), @@ -1909,6 +2274,15 @@ async fn add_node_should_set_random_ports_if_enable_metrics_server_is_true() -> ), OsString::from("--metrics-server-port"), OsString::from("15001"), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -1955,6 +2329,18 @@ async fn add_node_should_set_random_ports_if_enable_metrics_server_is_true() -> user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -2028,6 +2414,15 @@ async fn add_node_should_set_max_archived_log_files() -> Result<()> { ), OsString::from("--max-archived-log-files"), OsString::from("20"), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -2074,6 +2469,18 @@ async fn add_node_should_set_max_archived_log_files() -> Result<()> { user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -2148,6 +2555,15 @@ async fn add_node_should_set_max_log_files() -> Result<()> { ), OsString::from("--max-log-files"), OsString::from("20"), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -2194,6 +2610,18 @@ async fn add_node_should_set_max_log_files() -> Result<()> { user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -2266,6 +2694,15 @@ async fn add_node_should_use_a_custom_port_range_for_metrics_server() -> Result< ), OsString::from("--metrics-server-port"), OsString::from("12000"), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -2315,6 +2752,15 @@ async fn add_node_should_use_a_custom_port_range_for_metrics_server() -> Result< ), OsString::from("--metrics-server-port"), OsString::from("12001"), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -2364,6 +2810,15 @@ async fn add_node_should_use_a_custom_port_range_for_metrics_server() -> Result< ), OsString::from("--metrics-server-port"), OsString::from("12002"), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -2410,6 +2865,18 @@ async fn add_node_should_use_a_custom_port_range_for_metrics_server() -> Result< user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -2439,6 +2906,15 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_is_use auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -2454,6 +2930,9 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_is_use owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -2506,6 +2985,18 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_is_use user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &MockServiceControl::new(), @@ -2537,6 +3028,15 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_in_ran auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -2552,6 +3052,9 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_in_ran owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -2604,6 +3107,18 @@ async fn add_node_should_return_an_error_if_duplicate_custom_metrics_port_in_ran user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &MockServiceControl::new(), @@ -2673,6 +3188,15 @@ async fn add_node_should_use_a_custom_port_range_for_the_rpc_server() -> Result< .to_string_lossy() .to_string(), ), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -2715,6 +3239,15 @@ async fn add_node_should_use_a_custom_port_range_for_the_rpc_server() -> Result< .to_string_lossy() .to_string(), ), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -2757,6 +3290,15 @@ async fn add_node_should_use_a_custom_port_range_for_the_rpc_server() -> Result< .to_string_lossy() .to_string(), ), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -2803,6 +3345,18 @@ async fn add_node_should_use_a_custom_port_range_for_the_rpc_server() -> Result< user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -2843,6 +3397,15 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_is_used() auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -2858,6 +3421,9 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_is_used() owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -2910,6 +3476,18 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_is_used() user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &MockServiceControl::new(), @@ -2941,6 +3519,15 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_in_range_i auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -2956,6 +3543,9 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_in_range_i owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -3008,6 +3598,18 @@ async fn add_node_should_return_an_error_if_duplicate_custom_rpc_port_in_range_i user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &MockServiceControl::new(), @@ -3063,6 +3665,15 @@ async fn add_node_should_disable_upnp_and_home_network_if_nat_status_is_public() bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode1"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, local: false, @@ -3075,6 +3686,9 @@ async fn add_node_should_disable_upnp_and_home_network_if_nat_status_is_public() node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), safenode_path: node_data_dir .to_path_buf() @@ -3120,6 +3734,18 @@ async fn add_node_should_disable_upnp_and_home_network_if_nat_status_is_public() user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -3172,6 +3798,15 @@ async fn add_node_should_enable_upnp_if_nat_status_is_upnp() -> Result<()> { bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode1"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, local: false, @@ -3184,6 +3819,9 @@ async fn add_node_should_enable_upnp_if_nat_status_is_upnp() -> Result<()> { node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), safenode_path: node_data_dir .to_path_buf() @@ -3229,6 +3867,18 @@ async fn add_node_should_enable_upnp_if_nat_status_is_upnp() -> Result<()> { user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -3281,6 +3931,15 @@ async fn add_node_should_enable_home_network_if_nat_status_is_private() -> Resul bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode1"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: true, local: false, @@ -3293,6 +3952,9 @@ async fn add_node_should_enable_home_network_if_nat_status_is_private() -> Resul node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 12001), safenode_path: node_data_dir .to_path_buf() @@ -3338,6 +4000,18 @@ async fn add_node_should_enable_home_network_if_nat_status_is_private() -> Resul user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -3415,6 +4089,18 @@ async fn add_node_should_return_an_error_if_nat_status_is_none_but_auto_set_nat_ user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -4008,6 +4694,15 @@ async fn add_node_should_not_delete_the_source_binary_if_path_arg_is_used() -> R bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode1"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, local: false, @@ -4020,6 +4715,9 @@ async fn add_node_should_not_delete_the_source_binary_if_path_arg_is_used() -> R node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: node_data_dir .to_path_buf() @@ -4066,6 +4764,18 @@ async fn add_node_should_not_delete_the_source_binary_if_path_arg_is_used() -> R user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -4122,6 +4832,15 @@ async fn add_node_should_apply_the_home_network_flag_if_it_is_used() -> Result<( genesis: false, home_network: true, local: false, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), log_dir_path: node_logs_dir.to_path_buf().join("safenode1"), log_format: None, max_archived_log_files: None, @@ -4131,6 +4850,9 @@ async fn add_node_should_apply_the_home_network_flag_if_it_is_used() -> Result<( node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: node_data_dir .to_path_buf() @@ -4177,6 +4899,18 @@ async fn add_node_should_apply_the_home_network_flag_if_it_is_used() -> Result<( user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -4230,6 +4964,15 @@ async fn add_node_should_add_the_node_in_user_mode() -> Result<()> { bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode1"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: true, local: false, @@ -4242,6 +4985,9 @@ async fn add_node_should_add_the_node_in_user_mode() -> Result<()> { node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: node_data_dir .to_path_buf() @@ -4288,6 +5034,18 @@ async fn add_node_should_add_the_node_in_user_mode() -> Result<()> { user: Some(get_username()), user_mode: true, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -4338,6 +5096,15 @@ async fn add_node_should_add_the_node_with_upnp_enabled() -> Result<()> { bootstrap_peers: vec![], data_dir_path: node_data_dir.to_path_buf().join("safenode1"), env_variables: None, + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: true, local: false, @@ -4350,6 +5117,9 @@ async fn add_node_should_add_the_node_with_upnp_enabled() -> Result<()> { node_ip: None, node_port: None, owner: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: node_data_dir .to_path_buf() @@ -4396,6 +5166,18 @@ async fn add_node_should_add_the_node_with_upnp_enabled() -> Result<()> { user: Some(get_username()), user_mode: true, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -4467,6 +5249,15 @@ async fn add_node_should_assign_an_owner_in_lowercase() -> Result<()> { ), OsString::from("--owner"), OsString::from("discord_username"), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: false, contents: None, @@ -4514,6 +5305,18 @@ async fn add_node_should_assign_an_owner_in_lowercase() -> Result<()> { user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, @@ -4587,6 +5390,15 @@ async fn add_node_should_auto_restart() -> Result<()> { ), OsString::from("--owner"), OsString::from("discord_username"), + OsString::from("--rewards-address"), + OsString::from("0x03B770D9cD32077cC0bF330c13C114a87643B124"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), ], autostart: true, contents: None, @@ -4634,6 +5446,18 @@ async fn add_node_should_auto_restart() -> Result<()> { user: Some(get_username()), user_mode: false, version: latest_version.to_string(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }, &mut node_registry, &mock_service_control, diff --git a/sn_node_manager/src/bin/cli/main.rs b/sn_node_manager/src/bin/cli/main.rs index 5165eefae1..9269f76889 100644 --- a/sn_node_manager/src/bin/cli/main.rs +++ b/sn_node_manager/src/bin/cli/main.rs @@ -123,6 +123,9 @@ pub enum SubCmd { /// Example: --env SN_LOG=all,RUST_LOG=libp2p=debug #[clap(name = "env", long, use_value_delimiter = true, value_parser = parse_environment_variables)] env_variables: Option>, + /// Specify what EVM network to use for payments. + #[command(subcommand)] + evm_network: EvmNetworkCommand, /// Set this flag to use the safenode '--home-network' feature. /// /// This enables the use of safenode services from a home network with a router. @@ -188,13 +191,6 @@ pub enum SubCmd { /// services, which in this case would be 5. The range must also go from lower to higher. #[clap(long, value_parser = PortRange::parse)] node_port: Option, - /// Provide a path for the safenode binary to be used by the service. - /// - /// Useful for creating the service using a custom built binary. - #[clap(long)] - path: Option, - #[command(flatten)] - peers: PeersArgs, /// Specify the owner for the node service. /// /// This is mainly used for the 'Beta Rewards' programme, for linking your Discord username @@ -204,6 +200,16 @@ pub enum SubCmd { /// run as normal. #[clap(long)] owner: Option, + /// Provide a path for the safenode binary to be used by the service. + /// + /// Useful for creating the service using a custom built binary. + #[clap(long)] + path: Option, + #[command(flatten)] + peers: PeersArgs, + /// Specify the wallet address that will receive the node's earnings. + #[clap(long)] + rewards_address: RewardsAddress, /// Specify an Ipv4Addr for the node's RPC server to run on. /// /// Useful if you want to expose the RPC server pubilcly. Ports are assigned automatically. @@ -1082,6 +1088,7 @@ async fn main() -> Result<()> { data_dir_path, enable_metrics_server, env_variables, + evm_network, home_network, local, log_dir_path, @@ -1094,6 +1101,7 @@ async fn main() -> Result<()> { owner, path, peers, + rewards_address, rpc_address, rpc_port, url, @@ -1101,13 +1109,14 @@ async fn main() -> Result<()> { user, version, }) => { - let _ = cmd::node::add( + cmd::node::add( auto_restart, auto_set_nat_flags, count, data_dir_path, enable_metrics_server, env_variables, + Some(evm_network.try_into()?), home_network, local, log_dir_path, @@ -1119,6 +1128,7 @@ async fn main() -> Result<()> { node_port, owner, peers, + rewards_address, rpc_address, rpc_port, path, diff --git a/sn_node_manager/src/cmd/node.rs b/sn_node_manager/src/cmd/node.rs index ea30532c45..aefb30e855 100644 --- a/sn_node_manager/src/cmd/node.rs +++ b/sn_node_manager/src/cmd/node.rs @@ -22,6 +22,7 @@ use color_eyre::{eyre::eyre, Help, Result}; use colored::Colorize; use libp2p_identity::PeerId; use semver::Version; +use sn_evm::{EvmNetwork, RewardsAddress}; use sn_logging::LogFormat; use sn_peers_acquisition::PeersArgs; use sn_releases::{ReleaseType, SafeReleaseRepoActions}; @@ -42,6 +43,7 @@ pub async fn add( data_dir_path: Option, enable_metrics_server: bool, env_variables: Option>, + evm_network: Option, home_network: bool, local: bool, log_dir_path: Option, @@ -53,6 +55,7 @@ pub async fn add( node_port: Option, owner: Option, peers_args: PeersArgs, + rewards_address: RewardsAddress, rpc_address: Option, rpc_port: Option, src_path: Option, @@ -142,6 +145,7 @@ pub async fn add( count, delete_safenode_src: src_path.is_none(), enable_metrics_server, + evm_network: evm_network.unwrap_or_else(|| EvmNetwork::ArbitrumOne), env_variables, genesis: is_first, home_network, @@ -153,6 +157,7 @@ pub async fn add( node_ip, node_port, owner, + rewards_address, rpc_address, rpc_port, safenode_src_path, @@ -616,6 +621,7 @@ pub async fn maintain_n_running_nodes( node_port: Option, owner: Option, peers: PeersArgs, + rewards_address: RewardsAddress, rpc_address: Option, rpc_port: Option, src_path: Option, @@ -708,6 +714,7 @@ pub async fn maintain_n_running_nodes( data_dir_path.clone(), enable_metrics_server, env_variables.clone(), + None, home_network, local, log_dir_path.clone(), @@ -719,6 +726,7 @@ pub async fn maintain_n_running_nodes( Some(PortRange::Single(port)), owner.clone(), peers.clone(), + rewards_address, rpc_address, rpc_port.clone(), src_path.clone(), diff --git a/sn_node_manager/src/lib.rs b/sn_node_manager/src/lib.rs index 64c32bb9bb..721015ed2f 100644 --- a/sn_node_manager/src/lib.rs +++ b/sn_node_manager/src/lib.rs @@ -673,7 +673,7 @@ mod tests { use mockall::{mock, predicate::*}; use predicates::prelude::*; use service_manager::ServiceInstallCtx; - use sn_evm::AttoTokens; + use sn_evm::{AttoTokens, CustomNetwork, EvmNetwork, RewardsAddress}; use sn_logging::LogFormat; use sn_service_management::{ error::{Error as ServiceControlError, Result as ServiceControlResult}, @@ -768,6 +768,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -783,6 +792,9 @@ mod tests { owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -872,6 +884,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -889,6 +910,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -941,6 +965,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -958,6 +991,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1053,6 +1089,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1070,6 +1115,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1135,6 +1183,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1150,6 +1207,9 @@ mod tests { owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1227,6 +1287,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1242,6 +1311,9 @@ mod tests { owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1318,6 +1390,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1333,6 +1414,9 @@ mod tests { owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1379,6 +1463,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1396,6 +1489,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1430,6 +1526,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1445,6 +1550,9 @@ mod tests { owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1479,6 +1587,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1496,6 +1613,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1531,6 +1651,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1546,6 +1675,9 @@ mod tests { owner: None, peer_id: None, pid: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1596,6 +1728,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1613,6 +1754,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -1724,6 +1868,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1741,6 +1894,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -1814,6 +1970,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1831,6 +1996,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -1949,6 +2117,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -1966,6 +2143,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -2096,6 +2276,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -2113,6 +2302,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -2238,6 +2430,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -2255,6 +2456,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -2381,6 +2585,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -2398,6 +2611,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -2498,6 +2714,7 @@ mod tests { OsString::from("--log-output-dest"), OsString::from("/var/log/safenode/safenode1"), OsString::from("--upnp"), + OsString::from("evm-arbitrum-one"), ], autostart: false, contents: None, @@ -2554,6 +2771,7 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::ArbitrumOne, genesis: false, home_network: false, listen_addr: None, @@ -2571,6 +2789,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -2654,6 +2875,7 @@ mod tests { OsString::from("/var/log/safenode/safenode1"), OsString::from("--log-format"), OsString::from("json"), + OsString::from("evm-arbitrum-one"), ], autostart: false, contents: None, @@ -2710,6 +2932,7 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::ArbitrumOne, genesis: false, home_network: false, listen_addr: None, @@ -2727,6 +2950,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -2813,6 +3039,7 @@ mod tests { OsString::from("--log-output-dest"), OsString::from("/var/log/safenode/safenode1"), OsString::from("--home-network"), + OsString::from("evm-arbitrum-one"), ], autostart: false, contents: None, @@ -2869,6 +3096,7 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::ArbitrumOne, genesis: false, home_network: true, listen_addr: None, @@ -2886,6 +3114,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -2969,6 +3200,7 @@ mod tests { OsString::from("/var/log/safenode/safenode1"), OsString::from("--ip"), OsString::from("192.168.1.1"), + OsString::from("evm-arbitrum-one"), ], autostart: false, contents: None, @@ -3025,6 +3257,7 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::ArbitrumOne, genesis: false, home_network: false, listen_addr: None, @@ -3042,6 +3275,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -3128,6 +3364,7 @@ mod tests { OsString::from("/var/log/safenode/safenode1"), OsString::from("--port"), OsString::from("12000"), + OsString::from("evm-arbitrum-one"), ], autostart: false, contents: None, @@ -3184,6 +3421,7 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::ArbitrumOne, genesis: false, home_network: false, listen_addr: None, @@ -3201,6 +3439,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -3284,6 +3525,7 @@ mod tests { OsString::from("/var/log/safenode/safenode1"), OsString::from("--max-archived-log-files"), OsString::from("20"), + OsString::from("evm-arbitrum-one"), ], autostart: false, contents: None, @@ -3366,6 +3608,10 @@ mod tests { user: Some("safe".to_string()), user_mode: false, version: current_version.to_string(), + evm_network: EvmNetwork::ArbitrumOne, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }; let service = NodeService::new(&mut service_data, Box::new(mock_rpc_client)); @@ -3443,6 +3689,7 @@ mod tests { OsString::from("/var/log/safenode/safenode1"), OsString::from("--max-log-files"), OsString::from("20"), + OsString::from("evm-arbitrum-one"), ], autostart: false, contents: None, @@ -3525,6 +3772,10 @@ mod tests { user: Some("safe".to_string()), user_mode: false, version: current_version.to_string(), + evm_network: EvmNetwork::ArbitrumOne, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, }; let service = NodeService::new(&mut service_data, Box::new(mock_rpc_client)); @@ -3599,6 +3850,7 @@ mod tests { OsString::from("/var/log/safenode/safenode1"), OsString::from("--metrics-server-port"), OsString::from("12000"), + OsString::from("evm-arbitrum-one"), ], autostart: false, contents: None, @@ -3655,6 +3907,7 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::ArbitrumOne, genesis: false, home_network: false, listen_addr: None, @@ -3672,6 +3925,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -3758,6 +4014,7 @@ mod tests { OsString::from("/var/log/safenode/safenode1"), OsString::from("--metrics-server-port"), OsString::from("12000"), + OsString::from("evm-arbitrum-one"), ], autostart: false, contents: None, @@ -3814,6 +4071,7 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::ArbitrumOne, genesis: false, home_network: false, listen_addr: None, @@ -3831,6 +4089,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -3917,6 +4178,7 @@ mod tests { OsString::from("/var/log/safenode/safenode1"), OsString::from("--owner"), OsString::from("discord_username"), + OsString::from("evm-arbitrum-one"), ], autostart: false, contents: None, @@ -3973,6 +4235,7 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::ArbitrumOne, genesis: false, home_network: false, listen_addr: None, @@ -3990,6 +4253,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -4076,6 +4342,7 @@ mod tests { OsString::from("/var/log/safenode/safenode1"), OsString::from("--owner"), OsString::from("discord_username"), + OsString::from("evm-arbitrum-one"), ], autostart: true, contents: None, @@ -4132,6 +4399,7 @@ mod tests { auto_restart: true, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::ArbitrumOne, genesis: false, home_network: false, listen_addr: None, @@ -4149,6 +4417,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -4184,6 +4455,182 @@ mod tests { Ok(()) } + #[tokio::test] + async fn upgrade_should_retain_evm_network_settings() -> Result<()> { + let current_version = "0.1.0"; + let target_version = "0.2.0"; + + let tmp_data_dir = assert_fs::TempDir::new()?; + let current_install_dir = tmp_data_dir.child("safenode_install"); + current_install_dir.create_dir_all()?; + + let current_node_bin = current_install_dir.child("safenode"); + current_node_bin.write_binary(b"fake safenode binary")?; + let target_node_bin = tmp_data_dir.child("safenode"); + target_node_bin.write_binary(b"fake safenode binary")?; + + let mut mock_service_control = MockServiceControl::new(); + let mut mock_rpc_client = MockRpcClient::new(); + + // before binary upgrade + mock_service_control + .expect_get_process_pid() + .with(eq(current_node_bin.to_path_buf().clone())) + .times(1) + .returning(|_| Ok(1000)); + mock_service_control + .expect_stop() + .with(eq("safenode1"), eq(false)) + .times(1) + .returning(|_, _| Ok(())); + + // after binary upgrade + mock_service_control + .expect_uninstall() + .with(eq("safenode1"), eq(false)) + .times(1) + .returning(|_, _| Ok(())); + mock_service_control + .expect_install() + .with( + eq(ServiceInstallCtx { + args: vec![ + OsString::from("--rpc"), + OsString::from("127.0.0.1:8081"), + OsString::from("--root-dir"), + OsString::from("/var/safenode-manager/services/safenode1"), + OsString::from("--log-output-dest"), + OsString::from("/var/log/safenode/safenode1"), + OsString::from("--owner"), + OsString::from("discord_username"), + OsString::from("evm-custom"), + OsString::from("--rpc-url"), + OsString::from("http://localhost:8545/"), + OsString::from("--payment-token-address"), + OsString::from("0x5FbDB2315678afecb367f032d93F642f64180aa3"), + OsString::from("--data-payments-address"), + OsString::from("0x8464135c8F25Da09e49BC8782676a84730C318bC"), + ], + autostart: true, + contents: None, + environment: None, + label: "safenode1".parse()?, + program: current_node_bin.to_path_buf(), + username: Some("safe".to_string()), + working_directory: None, + }), + eq(false), + ) + .times(1) + .returning(|_, _| Ok(())); + + // after service restart + mock_service_control + .expect_start() + .with(eq("safenode1"), eq(false)) + .times(1) + .returning(|_, _| Ok(())); + mock_service_control + .expect_wait() + .with(eq(3000)) + .times(1) + .returning(|_| ()); + mock_service_control + .expect_get_process_pid() + .with(eq(current_node_bin.to_path_buf().clone())) + .times(1) + .returning(|_| Ok(100)); + + mock_rpc_client.expect_node_info().times(1).returning(|| { + Ok(NodeInfo { + pid: 2000, + peer_id: PeerId::from_str("12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR")?, + data_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + log_path: PathBuf::from("/var/log/safenode/safenode1"), + version: target_version.to_string(), + uptime: std::time::Duration::from_secs(1), // the service was just started + wallet_balance: 0, + }) + }); + mock_rpc_client + .expect_network_info() + .times(1) + .returning(|| { + Ok(NetworkInfo { + connected_peers: Vec::new(), + listeners: Vec::new(), + }) + }); + + let mut service_data = NodeServiceData { + auto_restart: true, + connected_peers: None, + data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), + genesis: false, + home_network: false, + listen_addr: None, + local: false, + log_dir_path: PathBuf::from("/var/log/safenode/safenode1"), + log_format: None, + max_archived_log_files: None, + max_log_files: None, + metrics_port: None, + node_ip: None, + node_port: None, + number: 1, + owner: Some("discord_username".to_string()), + peer_id: Some(PeerId::from_str( + "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", + )?), + pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, + reward_balance: Some(AttoTokens::zero()), + + rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), + safenode_path: current_node_bin.to_path_buf(), + service_name: "safenode1".to_string(), + status: ServiceStatus::Running, + upnp: false, + user: Some("safe".to_string()), + user_mode: false, + version: current_version.to_string(), + }; + let service = NodeService::new(&mut service_data, Box::new(mock_rpc_client)); + + let mut service_manager = ServiceManager::new( + service, + Box::new(mock_service_control), + VerbosityLevel::Normal, + ); + + service_manager + .upgrade(UpgradeOptions { + auto_restart: true, + bootstrap_peers: Vec::new(), + env_variables: None, + force: false, + start_service: true, + target_bin_path: target_node_bin.to_path_buf(), + target_version: Version::parse(target_version).unwrap(), + }) + .await?; + + assert!(service_manager.service.service_data.auto_restart,); + + Ok(()) + } + #[tokio::test] async fn upgrade_should_use_dynamic_startup_delay_if_set() -> Result<()> { let current_version = "0.1.0"; @@ -4231,6 +4678,7 @@ mod tests { OsString::from("--log-output-dest"), OsString::from("/var/log/safenode/safenode1"), OsString::from("--upnp"), + OsString::from("evm-arbitrum-one"), ], autostart: false, contents: None, @@ -4290,6 +4738,7 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::ArbitrumOne, genesis: false, home_network: false, listen_addr: None, @@ -4307,6 +4756,9 @@ mod tests { "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), pid: Some(1000), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: current_node_bin.to_path_buf(), @@ -4364,6 +4816,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: data_dir.to_path_buf(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -4379,6 +4840,9 @@ mod tests { owner: None, pid: None, peer_id: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: safenode_bin.to_path_buf(), @@ -4423,6 +4887,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -4440,6 +4913,9 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -4498,6 +4974,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: PathBuf::from("/var/safenode-manager/services/safenode1"), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -4515,6 +5000,9 @@ mod tests { peer_id: Some(PeerId::from_str( "12D3KooWS2tpXGGTmg2AHFiDh57yPQnat49YHnyqoggzXZWpqkCR", )?), + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: PathBuf::from("/var/safenode-manager/services/safenode1/safenode"), @@ -4565,6 +5053,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: data_dir.to_path_buf(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -4580,6 +5077,9 @@ mod tests { owner: None, pid: None, peer_id: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: safenode_bin.to_path_buf(), @@ -4630,6 +5130,15 @@ mod tests { auto_restart: false, connected_peers: None, data_dir_path: data_dir.to_path_buf(), + evm_network: EvmNetwork::Custom(CustomNetwork { + rpc_url_http: "http://localhost:8545".parse()?, + payment_token_address: RewardsAddress::from_str( + "0x5FbDB2315678afecb367f032d93F642f64180aa3", + )?, + data_payments_address: RewardsAddress::from_str( + "0x8464135c8F25Da09e49BC8782676a84730C318bC", + )?, + }), genesis: false, home_network: false, listen_addr: None, @@ -4645,6 +5154,9 @@ mod tests { owner: None, pid: None, peer_id: None, + rewards_address: RewardsAddress::from_str( + "0x03B770D9cD32077cC0bF330c13C114a87643B124", + )?, reward_balance: Some(AttoTokens::zero()), rpc_socket_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8081), safenode_path: safenode_bin.to_path_buf(), diff --git a/sn_node_manager/src/local.rs b/sn_node_manager/src/local.rs index e718d3dad6..5796cda354 100644 --- a/sn_node_manager/src/local.rs +++ b/sn_node_manager/src/local.rs @@ -313,7 +313,7 @@ pub async fn run_network( .nodes .iter() .find_map(|n| n.listen_addr.clone()) - .ok_or_else(|| eyre!("Unable to obtain a peer to connect to"))?; + .ok_or_eyre("Unable to obtain a peer to connect to")?; (peer, 1) } } else { @@ -474,7 +474,7 @@ pub async fn run_node( run_options.owner.clone(), run_options.rpc_socket_addr, run_options.rewards_address, - run_options.evm_network, + run_options.evm_network.clone(), )?; launcher.wait(run_options.interval); @@ -492,6 +492,7 @@ pub async fn run_node( auto_restart: false, connected_peers, data_dir_path: node_info.data_path, + evm_network: run_options.evm_network.unwrap_or(EvmNetwork::ArbitrumOne), genesis: run_options.genesis, home_network: false, listen_addr: Some(listen_addrs), @@ -507,6 +508,7 @@ pub async fn run_node( owner: run_options.owner, peer_id: Some(peer_id), pid: Some(node_info.pid), + rewards_address: run_options.rewards_address, reward_balance: None, rpc_socket_addr: run_options.rpc_socket_addr, safenode_path: launcher.get_safenode_path(), diff --git a/sn_node_manager/src/rpc.rs b/sn_node_manager/src/rpc.rs index b9fc50ced8..57147ccce4 100644 --- a/sn_node_manager/src/rpc.rs +++ b/sn_node_manager/src/rpc.rs @@ -66,6 +66,7 @@ pub async fn restart_node_service( bootstrap_peers: node_registry.bootstrap_peers.clone(), data_dir_path: current_node_clone.data_dir_path.clone(), env_variables: node_registry.environment_variables.clone(), + evm_network: current_node_clone.evm_network.clone(), genesis: current_node_clone.genesis, home_network: current_node_clone.home_network, local: current_node_clone.local, @@ -78,6 +79,7 @@ pub async fn restart_node_service( name: current_node_clone.service_name.clone(), node_ip: current_node_clone.node_ip, node_port: current_node_clone.get_safenode_port(), + rewards_address: current_node_clone.rewards_address, rpc_socket_addr: current_node_clone.rpc_socket_addr, safenode_path: current_node_clone.safenode_path.clone(), service_user: current_node_clone.user.clone(), @@ -184,6 +186,7 @@ pub async fn restart_node_service( bootstrap_peers: node_registry.bootstrap_peers.clone(), data_dir_path: data_dir_path.clone(), env_variables: node_registry.environment_variables.clone(), + evm_network: current_node_clone.evm_network.clone(), genesis: current_node_clone.genesis, home_network: current_node_clone.home_network, local: current_node_clone.local, @@ -196,6 +199,7 @@ pub async fn restart_node_service( node_ip: current_node_clone.node_ip, node_port: None, owner: None, + rewards_address: current_node_clone.rewards_address, rpc_socket_addr: current_node_clone.rpc_socket_addr, safenode_path: safenode_path.clone(), service_user: current_node_clone.user.clone(), @@ -210,6 +214,7 @@ pub async fn restart_node_service( auto_restart: current_node_clone.auto_restart, connected_peers: None, data_dir_path, + evm_network: current_node_clone.evm_network, genesis: current_node_clone.genesis, home_network: current_node_clone.home_network, listen_addr: None, @@ -225,6 +230,7 @@ pub async fn restart_node_service( owner: None, peer_id: None, pid: None, + rewards_address: current_node_clone.rewards_address, reward_balance: current_node_clone.reward_balance, rpc_socket_addr: current_node_clone.rpc_socket_addr, safenode_path, diff --git a/sn_service_management/src/node.rs b/sn_service_management/src/node.rs index ee109cc15c..fce50b00a5 100644 --- a/sn_service_management/src/node.rs +++ b/sn_service_management/src/node.rs @@ -11,7 +11,7 @@ use async_trait::async_trait; use libp2p::{multiaddr::Protocol, Multiaddr, PeerId}; use serde::{de::Error as DeError, Deserialize, Deserializer, Serialize, Serializer}; use service_manager::{ServiceInstallCtx, ServiceLabel}; -use sn_evm::AttoTokens; +use sn_evm::{AttoTokens, EvmNetwork, RewardsAddress}; use sn_logging::LogFormat; use sn_protocol::get_port_from_multiaddr; use std::{ @@ -126,6 +126,16 @@ impl<'a> ServiceStateActions for NodeService<'a> { args.push(OsString::from(peers_str)); } + args.push(OsString::from(self.service_data.evm_network.to_string())); + if let EvmNetwork::Custom(custom_network) = &self.service_data.evm_network { + args.push(OsString::from("--rpc-url")); + args.push(OsString::from(custom_network.rpc_url_http.to_string())); + args.push(OsString::from("--payment-token-address")); + args.push(OsString::from(custom_network.payment_token_address.to_string())); + args.push(OsString::from("--data-payments-address")); + args.push(OsString::from(custom_network.data_payments_address.to_string())); + } + Ok(ServiceInstallCtx { args, autostart: options.auto_restart, @@ -269,6 +279,7 @@ pub struct NodeServiceData { )] pub connected_peers: Option>, pub data_dir_path: PathBuf, + pub evm_network: EvmNetwork, pub genesis: bool, pub home_network: bool, pub listen_addr: Option>, @@ -292,6 +303,7 @@ pub struct NodeServiceData { )] pub peer_id: Option, pub pid: Option, + pub rewards_address: RewardsAddress, pub reward_balance: Option, pub rpc_socket_addr: SocketAddr, pub safenode_path: PathBuf,