diff --git a/cmd/crates/soroban-test/tests/it/integration.rs b/cmd/crates/soroban-test/tests/it/integration.rs index ec002c424..b25d47313 100644 --- a/cmd/crates/soroban-test/tests/it/integration.rs +++ b/cmd/crates/soroban-test/tests/it/integration.rs @@ -1,6 +1,7 @@ mod bindings; mod custom_types; mod dotenv; +mod fund; mod hello_world; mod tx; mod util; diff --git a/cmd/crates/soroban-test/tests/it/integration/fund.rs b/cmd/crates/soroban-test/tests/it/integration/fund.rs new file mode 100644 index 000000000..b9a99e783 --- /dev/null +++ b/cmd/crates/soroban-test/tests/it/integration/fund.rs @@ -0,0 +1,19 @@ +use soroban_test::TestEnv; + +#[tokio::test] +#[allow(clippy::too_many_lines)] +async fn fund() { + let sandbox = &TestEnv::new(); + sandbox + .new_assert_cmd("keys") + .arg("generate") + .arg("test") + .assert() + .success(); + sandbox + .new_assert_cmd("keys") + .arg("fund") + .arg("test") + .assert() + .stderr(predicates::str::contains("funding failed")); +} 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 1c766095f..25e00f093 100644 --- a/cmd/crates/soroban-test/tests/it/integration/hello_world.rs +++ b/cmd/crates/soroban-test/tests/it/integration/hello_world.rs @@ -32,12 +32,6 @@ async fn invoke() { let sandbox = &TestEnv::new(); let c = soroban_rpc::Client::new(&sandbox.rpc_url).unwrap(); let GetLatestLedgerResponse { sequence, .. } = c.get_latest_ledger().await.unwrap(); - sandbox - .new_assert_cmd("keys") - .arg("fund") - .arg("test") - .assert() - .stderr(predicates::str::contains("Account already exists")); sandbox .new_assert_cmd("keys") .arg("fund") diff --git a/cmd/soroban-cli/src/config/network.rs b/cmd/soroban-cli/src/config/network.rs index 958150cd7..d332fa904 100644 --- a/cmd/soroban-cli/src/config/network.rs +++ b/cmd/soroban-cli/src/config/network.rs @@ -31,8 +31,8 @@ pub enum Error { FailedToParseJSON(String, serde_json::Error), #[error("Invalid URL {0}")] InvalidUrl(String), - #[error("Inproper response {0}")] - InproperResponse(String), + #[error("funding failed: {0}")] + FundingFailed(String), } #[derive(Debug, clap::Args, Clone, Default)] @@ -149,16 +149,16 @@ impl Network { return Err(Error::InvalidUrl(uri.to_string())); } }; + let request_successful = response.status().is_success(); let body = hyper::body::to_bytes(response.into_body()).await?; let res = serde_json::from_slice::(&body) .map_err(|e| Error::FailedToParseJSON(uri.to_string(), e))?; tracing::debug!("{res:#?}"); - if let Some(detail) = res.get("detail").and_then(Value::as_str) { - if detail.contains("createAccountAlreadyExist") { - eprintln!("Account already exists"); + if !request_successful { + if let Some(detail) = res.get("detail").and_then(Value::as_str) { + return Err(Error::FundingFailed(detail.to_string())); } - } else if res.get("successful").is_none() { - return Err(Error::InproperResponse(res.to_string())); + return Err(Error::FundingFailed("unknown cause".to_string())); } Ok(()) }