From 61e1c612b0b8cabe0dab829b659bea52a1f41ab6 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 30 Apr 2024 14:43:25 -0400 Subject: [PATCH] fix: tests --- cmd/crates/soroban-test/src/lib.rs | 8 +++----- .../soroban-test/tests/it/integration/hello_world.rs | 12 ++++++------ cmd/crates/soroban-test/tests/it/integration/wrap.rs | 7 ++++--- cmd/crates/stellar-config/src/network.rs | 11 ++++++++--- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/cmd/crates/soroban-test/src/lib.rs b/cmd/crates/soroban-test/src/lib.rs index 509aa56e7..c24385afa 100644 --- a/cmd/crates/soroban-test/src/lib.rs +++ b/cmd/crates/soroban-test/src/lib.rs @@ -29,7 +29,7 @@ use assert_cmd::{assert::Assert, Command}; use assert_fs::{fixture::FixtureError, prelude::PathChild, TempDir}; use fs_extra::dir::CopyOptions; -use config::network; +use config::network::{self, passphrase}; use soroban_cli::{ commands::{contract::invoke, global, keys, NetworkRunnable}, @@ -41,8 +41,6 @@ pub use wasm::Wasm; pub const TEST_ACCOUNT: &str = "test"; -pub const LOCAL_NETWORK_PASSPHRASE: &str = "Standalone Network ; February 2017"; - #[derive(thiserror::Error, Debug)] pub enum Error { #[error(transparent)] @@ -127,7 +125,7 @@ impl TestEnv { cmd.arg(subcommand) .env("SOROBAN_ACCOUNT", TEST_ACCOUNT) .env("SOROBAN_RPC_URL", &self.rpc_url) - .env("SOROBAN_NETWORK_PASSPHRASE", LOCAL_NETWORK_PASSPHRASE) + .env("SOROBAN_NETWORK_PASSPHRASE", passphrase::LOCAL) .env("XDG_CONFIG_HOME", self.temp_dir.as_os_str()) .current_dir(&self.temp_dir); cmd @@ -227,7 +225,7 @@ impl TestEnv { let config = config::Args { network: network::Args { rpc_url: Some(self.rpc_url.clone()), - network_passphrase: Some(LOCAL_NETWORK_PASSPHRASE.to_string()), + network_passphrase: Some(passphrase::LOCAL.to_string()), network: None, }, source_account: account.to_string(), diff --git a/cmd/crates/soroban-test/tests/it/integration/hello_world.rs b/cmd/crates/soroban-test/tests/it/integration/hello_world.rs index 671d2edff..29e0e099c 100644 --- a/cmd/crates/soroban-test/tests/it/integration/hello_world.rs +++ b/cmd/crates/soroban-test/tests/it/integration/hello_world.rs @@ -1,10 +1,10 @@ use predicates::boolean::PredicateBooleanExt; -use soroban_cli::commands::{ - config::{locator, secret}, - contract::{self, fetch}, -}; + +use config::{locator, network::passphrase, secret}; + +use soroban_cli::commands::contract::{self, fetch}; use soroban_rpc::GetLatestLedgerResponse; -use soroban_test::{AssertExt, TestEnv, LOCAL_NETWORK_PASSPHRASE}; +use soroban_test::{AssertExt, TestEnv}; use crate::integration::util::extend_contract; @@ -323,7 +323,7 @@ async fn fetch(sandbox: &TestEnv, id: &str) { "--rpc-url", &sandbox.rpc_url, "--network-passphrase", - LOCAL_NETWORK_PASSPHRASE, + passphrase::LOCAL, "--id", id, "--out-file", diff --git a/cmd/crates/soroban-test/tests/it/integration/wrap.rs b/cmd/crates/soroban-test/tests/it/integration/wrap.rs index aa356ce99..8ad52fc19 100644 --- a/cmd/crates/soroban-test/tests/it/integration/wrap.rs +++ b/cmd/crates/soroban-test/tests/it/integration/wrap.rs @@ -1,11 +1,12 @@ +use config::network::passphrase; use soroban_cli::utils::contract_id_hash_from_asset; -use soroban_test::{AssertExt, TestEnv, LOCAL_NETWORK_PASSPHRASE}; +use soroban_test::{AssertExt, TestEnv}; #[tokio::test] #[ignore] async fn burn() { let sandbox = &TestEnv::new(); - let network_passphrase = LOCAL_NETWORK_PASSPHRASE.to_string(); + let network_passphrase = passphrase::LOCAL; let address = sandbox .new_assert_cmd("keys") .arg("address") @@ -24,7 +25,7 @@ async fn burn() { .success(); // wrap_cmd(&asset).run().await.unwrap(); let asset = soroban_cli::utils::parsing::parse_asset(&asset).unwrap(); - let hash = contract_id_hash_from_asset(&asset, &network_passphrase).unwrap(); + let hash = contract_id_hash_from_asset(&asset, network_passphrase).unwrap(); let id = stellar_strkey::Contract(hash.0).to_string(); println!("{id}, {address}"); sandbox diff --git a/cmd/crates/stellar-config/src/network.rs b/cmd/crates/stellar-config/src/network.rs index 0ace81ea6..f9a924f14 100644 --- a/cmd/crates/stellar-config/src/network.rs +++ b/cmd/crates/stellar-config/src/network.rs @@ -112,9 +112,14 @@ impl Network { let rpc_uri = Uri::from_str(&self.rpc_url) .map_err(|_| Error::InvalidUrl(self.rpc_url.to_string()))?; if self.network_passphrase.as_str() == passphrase::LOCAL { - let auth = rpc_uri.authority().ok_or_else(|| Error::MissingAuthority(self.rpc_url.clone()))?.clone(); - let scheme = rpc_uri.scheme_str().ok_or_else(|| Error::MissingScheme(self.rpc_url.clone()))?; - + let auth = rpc_uri + .authority() + .ok_or_else(|| Error::MissingAuthority(self.rpc_url.clone()))? + .clone(); + let scheme = rpc_uri + .scheme_str() + .ok_or_else(|| Error::MissingScheme(self.rpc_url.clone()))?; + Ok(Uri::builder() .authority(auth) .scheme(scheme)