diff --git a/cmd/crates/soroban-test/tests/it/help.rs b/cmd/crates/soroban-test/tests/it/help.rs index 53773c08a8..6d4680e772 100644 --- a/cmd/crates/soroban-test/tests/it/help.rs +++ b/cmd/crates/soroban-test/tests/it/help.rs @@ -1,101 +1,80 @@ -use std::path::PathBuf; - +use soroban_cli::commands::contract; use soroban_test::TestEnv; use crate::util::{invoke_custom as invoke, CUSTOM_TYPES}; -fn invoke_custom(e: &TestEnv, func: &str) -> assert_cmd::Command { - invoke(e, "1", func, [PathBuf::from("--wasm"), CUSTOM_TYPES.path()]) +async fn invoke_custom(func: &str, args: &str) -> Result { + let e = &TestEnv::default(); + invoke(e, "1", func, args, &CUSTOM_TYPES.path()).await } -#[test] -fn generate_help() { - invoke_custom(&TestEnv::default(), "strukt_hel") - .arg("--help") - .assert() - .success() - .stdout(predicates::str::contains( - "Example contract method which takes a struct", - )); +#[tokio::test] +async fn generate_help() { + assert!(invoke_custom("strukt_hel", "--help") + .await + .unwrap() + .contains("Example contract method which takes a struct")); } -#[test] -fn vec_help() { - invoke_custom(&TestEnv::default(), "vec") - .arg("--help") - .assert() - .success() - .stdout(predicates::str::contains("Array")); + +#[tokio::test] +async fn vec_help() { + assert!(invoke_custom("vec", "--help") + .await + .unwrap() + .contains("Array")); } -#[test] -fn tuple_help() { - invoke_custom(&TestEnv::default(), "tuple") - .arg("--help") - .assert() - .success() - .stdout(predicates::str::contains("Tuple")); +#[tokio::test] +async fn tuple_help() { + assert!(invoke_custom("tuple", "--help") + .await + .unwrap() + .contains("Tuple")); } -#[test] -fn strukt_help() { - invoke_custom(&TestEnv::default(), "strukt") - .arg("--help") - .assert() - .stdout(predicates::str::contains( - "--strukt '{ \"a\": 1, \"b\": true, \"c\": \"hello\" }'", - )) - .stdout(predicates::str::contains( - "This is from the rust doc above the struct Test", - )); +#[tokio::test] +async fn strukt_help() { + let output = invoke_custom("strukt", "--help").await.unwrap(); + assert!(output.contains("--strukt '{ \"a\": 1, \"b\": true, \"c\": \"hello\" }'",)); + assert!(output.contains("This is from the rust doc above the struct Test",)); } -#[test] -fn complex_enum_help() { - invoke_custom(&TestEnv::default(), "complex") - .arg("--help") - .assert() - .stdout(predicates::str::contains( - r#"--complex '{"Struct":{ "a": 1, "b": true, "c": "hello" }}"#, - )) - .stdout(predicates::str::contains( - r#"{"Tuple":[{ "a": 1, "b": true, "c": "hello" }"#, - )) - .stdout(predicates::str::contains( - r#"{"Enum":"First"|"Second"|"Third"}"#, - )) - .stdout(predicates::str::contains( - r#"{"Asset":["GDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCR4W4", "-100"]}"#, - )) - .stdout(predicates::str::contains(r#""Void"'"#)); +#[tokio::test] +async fn complex_enum_help() { + let output = invoke_custom("complex", "--help").await.unwrap(); + assert!(output.contains(r#"--complex '{"Struct":{ "a": 1, "b": true, "c": "hello" }}"#,)); + assert!(output.contains(r#"{"Tuple":[{ "a": 1, "b": true, "c": "hello" }"#,)); + assert!(output.contains(r#"{"Enum":"First"|"Second"|"Third"}"#,)); + assert!(output.contains( + r#"{"Asset":["GDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCR4W4", "-100"]}"#, + )); + assert!(output.contains(r#""Void"'"#)); } -#[test] -fn multi_arg_failure() { - invoke_custom(&TestEnv::default(), "multi_args") - .arg("--b") - .assert() - .failure() - .stderr("error: Missing argument a\n"); +#[tokio::test] +async fn multi_arg_failure() { + assert!(matches!( + invoke_custom("multi_args", "--b").await.unwrap_err(), + contract::invoke::Error::MissingArgument(_) + )); } -#[test] -fn handle_arg_larger_than_i32_failure() { - invoke_custom(&TestEnv::default(), "i32_") - .arg("--i32_") - .arg(u32::MAX.to_string()) - .assert() - .failure() - .stderr(predicates::str::contains("value is not parseable")); +#[tokio::test] +async fn handle_arg_larger_than_i32_failure() { + let res = invoke_custom("i32_", &format!("--i32_={}", u32::MAX)).await; + assert!(matches!( + res, + Err(contract::invoke::Error::CannotParseArg { .. }) + )); } -#[test] -fn handle_arg_larger_than_i64_failure() { - invoke_custom(&TestEnv::default(), "i64_") - .arg("--i64_") - .arg(u64::MAX.to_string()) - .assert() - .failure() - .stderr(predicates::str::contains("value is not parseable")); +#[tokio::test] +async fn handle_arg_larger_than_i64_failure() { + let res = invoke_custom("i64_", &format!("--i64_={}", u64::MAX)).await; + assert!(matches!( + res, + Err(contract::invoke::Error::CannotParseArg { .. }) + )); } #[test] diff --git a/cmd/crates/soroban-test/tests/it/util.rs b/cmd/crates/soroban-test/tests/it/util.rs index 3225093c4f..ad5dacc7d1 100644 --- a/cmd/crates/soroban-test/tests/it/util.rs +++ b/cmd/crates/soroban-test/tests/it/util.rs @@ -1,7 +1,9 @@ use std::path::Path; -use assert_cmd::Command; -use soroban_cli::commands::config::{locator::KeyType, secret::Secret}; +use soroban_cli::commands::{ + config::{locator::KeyType, secret::Secret}, + contract, +}; use soroban_test::{TestEnv, Wasm}; pub const CUSTOM_TYPES: &Wasm = &Wasm::Custom("test-wasms", "test_custom_types"); @@ -43,22 +45,16 @@ pub const DEFAULT_SEED_PHRASE: &str = "coral light army gather adapt blossom school alcohol coral light army giggle"; #[allow(dead_code)] -pub fn invoke_custom(sandbox: &TestEnv, id: &str, func: &str, args: I) -> Command -where - I: IntoIterator, - S: AsRef, -{ - let mut s = sandbox.new_assert_cmd("contract"); - s.env("SOROBAN_RPC_URL", "http://localhost:8000") - .env( - "SOROBAN_NETWORK_PASSPHRASE", - "Standalone Network ; February 2017", - ) - .arg("invoke") - .arg("--id") - .arg(id) - .args(args) - .arg("--") - .arg(func); - s +pub async fn invoke_custom( + sandbox: &TestEnv, + id: &str, + func: &str, + arg: &str, + wasm: &Path, +) -> Result { + let mut i: contract::invoke::Cmd = sandbox.cmd_arr(&["--id", id, "--", func, arg]); + i.wasm = Some(wasm.to_path_buf()); + i.config.network.network = Some("futurenet".to_owned()); + i.invoke(&soroban_cli::commands::global::Args::default()) + .await } diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index ebd7457f13..ed1a8d623c 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -44,7 +44,7 @@ pub struct Cmd { #[arg(long = "id", env = "SOROBAN_CONTRACT_ID")] pub contract_id: String, /// WASM file of the contract to invoke (if using sandbox will deploy this file) - #[arg(long)] + #[arg(skip)] pub wasm: Option, /// Output the cost execution to stderr