From 9c6a647bd12d402e88a96ecb931ff4ed1bbbe2df Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 3 Oct 2023 16:49:21 -0400 Subject: [PATCH] fix: reorganize tests that rely on network and ignore outside of go test --- cmd/crates/soroban-test/src/lib.rs | 11 +- cmd/crates/soroban-test/tests/it/config.rs | 24 +- .../soroban-test/tests/it/hello_world.rs | 461 ------------------ .../soroban-test/tests/it/integration.rs | 4 + .../it/{ => integration}/custom_types.rs | 181 +++---- .../tests/it/{ => integration}/dotenv.rs | 35 +- .../tests/it/integration/hello_world.rs | 379 ++++++++++++++ .../soroban-test/tests/it/integration/util.rs | 100 ++++ .../tests/it/integration_and_sandbox.rs | 222 --------- cmd/crates/soroban-test/tests/it/main.rs | 7 +- cmd/crates/soroban-test/tests/it/util.rs | 103 +--- .../src/commands/contract/invoke.rs | 15 +- cmd/soroban-cli/src/commands/contract/read.rs | 4 +- .../src/commands/contract/restore.rs | 1 - .../src/commands/lab/token/wrap.rs | 3 +- cmd/soroban-rpc/internal/test/cli_test.go | 3 +- 16 files changed, 614 insertions(+), 939 deletions(-) create mode 100644 cmd/crates/soroban-test/tests/it/integration.rs rename cmd/crates/soroban-test/tests/it/{ => integration}/custom_types.rs (76%) rename cmd/crates/soroban-test/tests/it/{ => integration}/dotenv.rs (67%) create mode 100644 cmd/crates/soroban-test/tests/it/integration/hello_world.rs create mode 100644 cmd/crates/soroban-test/tests/it/integration/util.rs delete mode 100644 cmd/crates/soroban-test/tests/it/integration_and_sandbox.rs diff --git a/cmd/crates/soroban-test/src/lib.rs b/cmd/crates/soroban-test/src/lib.rs index 7cf95c5b64..8ec628bf79 100644 --- a/cmd/crates/soroban-test/src/lib.rs +++ b/cmd/crates/soroban-test/src/lib.rs @@ -71,7 +71,7 @@ impl TestEnv { /// ```rust,no_run /// use soroban_test::TestEnv; /// TestEnv::with_default(|env| { - /// env.invoke(&["--id", "1", "--", "hello", "--world=world"]).unwrap(); + /// env.new_assert_cmd("contract").args(&["invoke", "--id", "1", "--", "hello", "--world=world"]).assert().success(); /// }); /// ``` /// @@ -122,7 +122,7 @@ impl TestEnv { } /// A convenience method for using the invoke command. - pub fn invoke>(&self, command_str: &[I]) -> Result { + pub async fn invoke>(&self, command_str: &[I]) -> Result { let cmd = contract::invoke::Cmd::parse_arg_vec( &command_str .iter() @@ -131,13 +131,13 @@ impl TestEnv { .collect::>(), ) .unwrap(); - self.invoke_cmd(cmd) + self.invoke_cmd(cmd).await } /// Invoke an already parsed invoke command - pub fn invoke_cmd(&self, mut cmd: invoke::Cmd) -> Result { + pub async fn invoke_cmd(&self, mut cmd: invoke::Cmd) -> Result { cmd.set_pwd(self.dir()); - cmd.run_in_sandbox(&global::Args { + cmd.run_against_rpc_server(&global::Args { locator: config::locator::Args { global: false, config_dir: None, @@ -148,6 +148,7 @@ impl TestEnv { very_verbose: false, list: false, }) + .await } /// Reference to current directory of the `TestEnv`. diff --git a/cmd/crates/soroban-test/tests/it/config.rs b/cmd/crates/soroban-test/tests/it/config.rs index 80bb0a574f..a0a240af18 100644 --- a/cmd/crates/soroban-test/tests/it/config.rs +++ b/cmd/crates/soroban-test/tests/it/config.rs @@ -1,8 +1,8 @@ use assert_fs::TempDir; -use soroban_test::{temp_ledger_file, TestEnv}; +use soroban_test::TestEnv; use std::{fs, path::Path}; -use crate::util::{add_identity, add_test_id, SecretKind, DEFAULT_SEED_PHRASE, HELLO_WORLD}; +use crate::util::{add_identity, add_test_id, SecretKind, DEFAULT_SEED_PHRASE}; use soroban_cli::commands::config::network; const NETWORK_PASSPHRASE: &str = "Local Sandbox Stellar Network ; September 2022"; @@ -205,26 +205,6 @@ fn seed_phrase() { .stdout("test_seed\n"); } -#[test] -fn use_different_ledger_file() { - let sandbox = TestEnv::default(); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id=1") - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .arg("--ledger-file") - .arg(temp_ledger_file()) - .arg("--") - .arg("hello") - .arg("--world=world") - .assert() - .stdout("[\"Hello\",\"world\"]\n") - .success(); - assert!(fs::read(sandbox.dir().join(".soroban/ledger.json")).is_err()); -} - #[test] fn read_address() { let sandbox = TestEnv::default(); diff --git a/cmd/crates/soroban-test/tests/it/hello_world.rs b/cmd/crates/soroban-test/tests/it/hello_world.rs index 30ee8c907b..38b78ee38a 100644 --- a/cmd/crates/soroban-test/tests/it/hello_world.rs +++ b/cmd/crates/soroban-test/tests/it/hello_world.rs @@ -11,427 +11,12 @@ use crate::util::{ TEST_SALT, }; -#[test] -fn install_wasm_then_deploy_contract() { - let sandbox = TestEnv::default(); - assert_eq!(deploy_hello(&sandbox), TEST_CONTRACT_ID); -} - -const TEST_CONTRACT_ID: &str = "CBVTIVBYWAO2HNPNGKDCZW4OZYYESTKNGD7IPRTDGQSFJS4QBDQQJX3T"; - -fn deploy_hello(sandbox: &TestEnv) -> String { - let hash = HELLO_WORLD.hash().unwrap(); - sandbox - .new_assert_cmd("contract") - .arg("install") - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .assert() - .success() - .stdout(format!("{hash}\n")); - - let mut cmd: &mut assert_cmd::Command = &mut sandbox.new_assert_cmd("contract"); - - cmd = cmd.arg("deploy").arg("--wasm-hash").arg(&format!("{hash}")); - if is_rpc() { - cmd = cmd.arg("--salt").arg(TEST_SALT); - } else { - cmd = cmd.arg("--id").arg(TEST_CONTRACT_ID); - } - cmd.assert() - .success() - .stdout(format!("{TEST_CONTRACT_ID}\n")); - TEST_CONTRACT_ID.to_string() -} - -#[test] -fn deploy_contract_with_wasm_file() { - if is_rpc() { - return; - } - TestEnv::default() - .new_assert_cmd("contract") - .arg("deploy") - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .arg("--id=1") - .assert() - .success() - .stdout("CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM\n"); -} - -#[test] -fn invoke_hello_world_with_deploy_first() { - let sandbox = TestEnv::default(); - let id = deploy_hello(&sandbox); - println!("{id}"); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--") - .arg("hello") - .arg("--world=world") - .assert() - .stdout("[\"Hello\",\"world\"]\n") - .success(); -} - -#[test] -fn invoke_hello_world() { - let sandbox = TestEnv::default(); - let id = deploy_hello(&sandbox); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .arg("--") - .arg("hello") - .arg("--world=world") - .assert() - .stdout("[\"Hello\",\"world\"]\n") - .success(); -} - -#[test] -fn invoke_hello_world_from_file() { - let sandbox = TestEnv::default(); - let tmp_file = sandbox.temp_dir.join("world.txt"); - std::fs::write(&tmp_file, "world").unwrap(); - let id = deploy_hello(&sandbox); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .arg("--") - .arg("hello") - .arg("--world-file-path") - .arg(&tmp_file) - .assert() - .stdout("[\"Hello\",\"world\"]\n") - .success(); -} - -#[test] -fn invoke_hello_world_from_file_fail() { - let sandbox = TestEnv::default(); - let tmp_file = sandbox.temp_dir.join("world.txt"); - std::fs::write(&tmp_file, "world").unwrap(); - let id = deploy_hello(&sandbox); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .arg("--") - .arg("hello") - .arg("--world-file-path") - .arg(&tmp_file) - .arg("--world=hello") - .assert() - .stderr(predicates::str::contains("error: the argument '--world-file-path ' cannot be used with '--world '")) - .failure(); -} - -#[test] -fn invoke_hello_world_with_lib() { - TestEnv::with_default(|e| { - let id = deploy_hello(e); - let mut cmd = contract::invoke::Cmd { - contract_id: id, - slop: vec!["hello".into(), "--world=world".into()], - ..Default::default() - }; - - cmd.config.network.rpc_url = rpc_url(); - cmd.config.network.network_passphrase = network_passphrase(); - - let res = e.invoke_cmd(cmd).unwrap(); - assert_eq!(res, r#"["Hello","world"]"#); - }); -} - -#[test] -fn invoke_hello_world_with_lib_two() { - TestEnv::with_default(|e| { - let id = deploy_hello(e); - let hello_world = HELLO_WORLD.to_string(); - let mut invoke_args = vec!["--id", &id, "--wasm", hello_world.as_str()]; - let args = vec!["--", "hello", "--world=world"]; - let res = if let (Some(rpc), Some(network_passphrase)) = - (rpc_url_arg(), network_passphrase_arg()) - { - invoke_args.push(&rpc); - invoke_args.push(&network_passphrase); - e.invoke(&[invoke_args, args].concat()).unwrap() - } else { - e.invoke(&[invoke_args, args].concat()).unwrap() - }; - assert_eq!(res, r#"["Hello","world"]"#); - }); -} -// #[test] -// fn invoke_hello_world_with_lib_three() { -// let sandbox = TestEnv::default(); -// let builder = invoke::CmdBuilder::new().contract_id("1").wasm(HELLO_WORLD.path()).function("hello").slop(["--hello=world"]).build(); -// std::env::set_current_dir(sandbox.dir()).unwrap(); -// assert_eq!(res.run_in_sandbox().unwrap(), r#"["Hello","world"]"#); -// } - -#[test] -fn invoke_auth() { - let sandbox = TestEnv::default(); - let id = &deploy_hello(&sandbox); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .arg("--") - .arg("auth") - .arg(&format!("--addr={DEFAULT_PUB_KEY}")) - .arg("--world=world") - .assert() - .stdout(format!("\"{DEFAULT_PUB_KEY}\"\n")) - .success(); - - // Invoke it again without providing the contract, to exercise the deployment - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--") - .arg("auth") - .arg(&format!("--addr={DEFAULT_PUB_KEY}")) - .arg("--world=world") - .assert() - .stdout(format!("\"{DEFAULT_PUB_KEY}\"\n")) - .success(); -} - -#[tokio::test] -async fn invoke_auth_with_identity() { - let sandbox = TestEnv::default(); - sandbox - .cmd::("test -d ") - .run() - .await - .unwrap(); - let id = deploy_hello(&sandbox); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .arg("--") - .arg("auth") - .arg("--addr=test") - .arg("--world=world") - .assert() - .stdout(format!("\"{DEFAULT_PUB_KEY}\"\n")) - .success(); -} - -#[test] -fn invoke_auth_with_different_test_account() { - let sandbox = TestEnv::default(); - let id = deploy_hello(&sandbox); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--hd-path=1") - .arg("--id") - .arg(id) - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .arg("--") - .arg("auth") - .arg(&format!("--addr={DEFAULT_PUB_KEY_1}")) - .arg("--world=world") - .assert() - .stdout(format!("\"{DEFAULT_PUB_KEY_1}\"\n")) - .success(); -} -#[test] -fn contract_data_read_failure() { - let sandbox = TestEnv::default(); - let id = deploy_hello(&sandbox); - sandbox - .new_assert_cmd("contract") - .arg("read") - .arg("--id") - .arg(id) - .arg("--key=COUNTER") - .arg("--durability=persistent") - .assert() - .failure() - .stderr( - "error: no matching contract data entries were found for the specified contract id\n", - ); -} - -#[test] -fn contract_data_read() { - let sandbox = TestEnv::default(); - let id = &deploy_hello(&sandbox); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--") - .arg("inc") - .assert() - .success(); - sandbox - .new_assert_cmd("contract") - .arg("read") - .arg("--id") - .arg(id) - .arg("--key=COUNTER") - .arg("--durability=persistent") - .assert() - .success() - .stdout("COUNTER,1,4096\n"); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--") - .arg("inc") - .assert() - .success(); - - sandbox - .new_assert_cmd("contract") - .arg("read") - .arg("--id") - .arg(id) - .arg("--key=COUNTER") - .arg("--durability=persistent") - .assert() - .success() - .stdout("COUNTER,2,4096\n"); -} -#[test] -fn invoke_auth_with_different_test_account_fail() { - let sandbox = TestEnv::default(); - let id = &deploy_hello(&sandbox); - let res = sandbox.invoke(&[ - "--hd-path=1", - "--id", - id, - "--wasm", - HELLO_WORLD.path().to_str().unwrap(), - &rpc_url_arg().unwrap_or_default(), - &network_passphrase_arg().unwrap_or_default(), - "--", - "auth", - &format!("--addr={DEFAULT_PUB_KEY}"), - "--world=world", - ]); - assert!(res.is_err()); - if let Err(e) = res { - assert!( - matches!(e, contract::invoke::Error::Host(_)), - "Expected host error got {e:?}" - ); - }; -} - -#[test] -fn invoke_hello_world_with_seed() { - let sandbox = TestEnv::default(); - let identity = add_test_seed(sandbox.dir()); - invoke_with_source(&sandbox, &identity); -} - -#[test] -fn invoke_with_seed() { - let sandbox = TestEnv::default(); - invoke_with_source(&sandbox, DEFAULT_SEED_PHRASE); -} - -#[test] -fn invoke_with_id() { - let sandbox = TestEnv::default(); - let identity = add_test_seed(sandbox.dir()); - invoke_with_source(&sandbox, &identity); -} - -#[test] -fn invoke_with_sk() { - let sandbox = TestEnv::default(); - invoke_with_source(&sandbox, DEFAULT_SECRET_KEY); -} - -fn invoke_with_source(sandbox: &TestEnv, source: &str) { - let id = &deploy_hello(sandbox); - let cmd = sandbox.invoke(&[ - "--source-account", - source, - "--id", - id, - "--wasm", - HELLO_WORLD.path().to_str().unwrap(), - &rpc_url_arg().unwrap_or_default(), - &network_passphrase_arg().unwrap_or_default(), - "--", - "hello", - "--world=world", - ]); - assert_eq!(cmd.unwrap(), "[\"Hello\",\"world\"]"); - - // Invoke it again without providing the contract, to exercise the deployment - let cmd = sandbox.invoke(&[ - "--source-account", - source, - "--id", - id, - "--", - "hello", - "--world=world", - ]); - assert_eq!(cmd.unwrap(), "[\"Hello\",\"world\"]"); -} - -#[test] -fn handles_kebab_case() { - let e = TestEnv::default(); - let id = deploy_hello(&e); - assert!(e - .invoke(&[ - "--id", - &id, - "--wasm", - HELLO_WORLD.path().to_str().unwrap(), - "--", - "multi-word-cmd", - "--contract-owner=world", - ]) - .is_ok()); -} #[tokio::test] async fn fetch() { @@ -445,49 +30,3 @@ async fn fetch() { cmd.run().await.unwrap(); assert!(f.exists()); } - -#[test] -fn build() { - let sandbox = TestEnv::default(); - - let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let hello_world_contract_path = - cargo_dir.join("tests/fixtures/test-wasms/hello_world/Cargo.toml"); - sandbox - .new_assert_cmd("contract") - .arg("build") - .arg("--manifest-path") - .arg(hello_world_contract_path) - .arg("--profile") - .arg("test-wasms") - .arg("--package") - .arg("test_hello_world") - .assert() - .success(); -} - -#[test] -fn invoke_prng_u64_in_range_test() { - let sandbox = TestEnv::default(); - let res = sandbox - .new_assert_cmd("contract") - .arg("deploy") - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .assert() - .success(); - let stdout = String::from_utf8(res.get_output().stdout.clone()).unwrap(); - let id = stdout.trim_end(); - println!("{id}"); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--") - .arg("prng_u64_in_range") - .arg("--low=0") - .arg("--high=100") - .assert() - .success(); -} diff --git a/cmd/crates/soroban-test/tests/it/integration.rs b/cmd/crates/soroban-test/tests/it/integration.rs new file mode 100644 index 0000000000..d196ce07b5 --- /dev/null +++ b/cmd/crates/soroban-test/tests/it/integration.rs @@ -0,0 +1,4 @@ +mod custom_types; +mod dotenv; +mod hello_world; +mod util; diff --git a/cmd/crates/soroban-test/tests/it/custom_types.rs b/cmd/crates/soroban-test/tests/it/integration/custom_types.rs similarity index 76% rename from cmd/crates/soroban-test/tests/it/custom_types.rs rename to cmd/crates/soroban-test/tests/it/integration/custom_types.rs index 839b326f58..66692fbc45 100644 --- a/cmd/crates/soroban-test/tests/it/custom_types.rs +++ b/cmd/crates/soroban-test/tests/it/integration/custom_types.rs @@ -3,7 +3,7 @@ use serde_json::json; use soroban_cli::commands; use soroban_test::TestEnv; -use crate::util::{invoke, invoke_with_roundtrip, CUSTOM_TYPES}; +use super::util::{invoke, invoke_with_roundtrip, CUSTOM_TYPES}; #[test] fn symbol() { @@ -18,14 +18,14 @@ fn symbol() { ); } -#[test] -fn string_with_quotes() { - invoke_with_roundtrip("string", json!("hello world")); +#[tokio::test] +async fn string_with_quotes() { + invoke_with_roundtrip("string", json!("hello world")).await; } -#[test] -fn symbol_with_quotes() { - invoke_with_roundtrip("hello", json!("world")); +#[tokio::test] +async fn symbol_with_quotes() { + invoke_with_roundtrip("hello", json!("world")).await; } #[test] @@ -72,9 +72,9 @@ fn bytes_as_file() { .stdout("\"0000000000000000007374656c6c6172\"\n"); } -#[test] -fn map() { - invoke_with_roundtrip("map", json!({"0": true, "1": false})); +#[tokio::test] +async fn map() { + invoke_with_roundtrip("map", json!({"0": true, "1": false})).await; } #[test] @@ -86,9 +86,9 @@ fn map_help() { .stdout(predicates::str::contains("Map")); } -#[test] -fn vec_() { - invoke_with_roundtrip("vec", json!([0, 1])); +#[tokio::test] +async fn vec_() { + invoke_with_roundtrip("vec", json!([0, 1])).await; } #[test] @@ -100,13 +100,13 @@ fn vec_help() { .stdout(predicates::str::contains("Array")); } -#[test] -fn tuple() { - invoke_with_roundtrip("tuple", json!(["hello", 0])); +#[tokio::test] +async fn tuple() { + invoke_with_roundtrip("tuple", json!(["hello", 0])).await; } -#[test] -fn tuple_help() { +#[tokio::test] +async fn tuple_help() { invoke(&TestEnv::default(), "tuple") .arg("--help") .assert() @@ -114,17 +114,18 @@ fn tuple_help() { .stdout(predicates::str::contains("Tuple")); } -#[test] -fn strukt() { - invoke_with_roundtrip("strukt", json!({"a": 42, "b": true, "c": "world"})); +#[tokio::test] +async fn strukt() { + invoke_with_roundtrip("strukt", json!({"a": 42, "b": true, "c": "world"})).await; } -#[test] -fn tuple_strukt() { +#[tokio::test] +async fn tuple_strukt() { invoke_with_roundtrip( "tuple_strukt", json!([{"a": 42, "b": true, "c": "world"}, "First"]), - ); + ) + .await; } #[test] @@ -160,44 +161,46 @@ fn complex_enum_help() { .stdout(predicates::str::contains(r#""Void"'"#)); } -#[test] -fn enum_2_str() { - invoke_with_roundtrip("simple", json!("First")); +#[tokio::test] +async fn enum_2_str() { + invoke_with_roundtrip("simple", json!("First")).await; } -#[test] -fn e_2_s_enum() { - invoke_with_roundtrip("complex", json!({"Enum": "First"})); +#[tokio::test] +async fn e_2_s_enum() { + invoke_with_roundtrip("complex", json!({"Enum": "First"})).await; } -#[test] -fn asset() { +#[tokio::test] +async fn asset() { invoke_with_roundtrip( "complex", json!({"Asset": ["CB64D3G7SM2RTH6JSGG34DDTFTQ5CFDKVDZJZSODMCX4NJ2HV2KN7OHT", "100" ]}), - ); + ) + .await; } fn complex_tuple() -> serde_json::Value { json!({"Tuple": [{"a": 42, "b": true, "c": "world"}, "First"]}) } -#[test] -fn e_2_s_tuple() { - invoke_with_roundtrip("complex", complex_tuple()); +#[tokio::test] +async fn e_2_s_tuple() { + invoke_with_roundtrip("complex", complex_tuple()).await; } -#[test] -fn e_2_s_strukt() { +#[tokio::test] +async fn e_2_s_strukt() { invoke_with_roundtrip( "complex", json!({"Struct": {"a": 42, "b": true, "c": "world"}}), - ); + ) + .await; } -#[test] -fn number_arg() { - invoke_with_roundtrip("u32_", 42); +#[tokio::test] +async fn number_arg() { + invoke_with_roundtrip("u32_", 42).await; } #[test] @@ -210,28 +213,28 @@ fn number_arg_return_ok() { .stdout("1\n"); } -#[test] -fn number_arg_return_err() { - TestEnv::with_default(|sandbox| { - // matches!(res, commands::invoke::Error) - let p = CUSTOM_TYPES.path(); - let wasm = p.to_str().unwrap(); - let res = sandbox - .invoke(&[ - "--id=1", - "--wasm", - wasm, - "--", - "u32_fail_on_even", - "--u32_=2", - ]) - .unwrap_err(); - if let commands::contract::invoke::Error::ContractInvoke(name, doc) = &res { - assert_eq!(name, "NumberMustBeOdd"); - assert_eq!(doc, "Please provide an odd number"); - }; - println!("{res:#?}"); - }); +#[tokio::test] +async fn number_arg_return_err() { + let sandbox = &TestEnv::default(); + + let p = CUSTOM_TYPES.path(); + let wasm = p.to_str().unwrap(); + let res = sandbox + .invoke(&[ + "--id=1", + "--wasm", + wasm, + "--", + "u32_fail_on_even", + "--u32_=2", + ]) + .await + .unwrap_err(); + if let commands::contract::invoke::Error::ContractInvoke(name, doc) = &res { + assert_eq!(name, "NumberMustBeOdd"); + assert_eq!(doc, "Please provide an odd number"); + }; + println!("{res:#?}"); } #[test] @@ -252,9 +255,9 @@ fn val() { .stderr(""); } -#[test] -fn i32() { - invoke_with_roundtrip("i32_", 42); +#[tokio::test] +async fn i32() { + invoke_with_roundtrip("i32_", 42).await; } #[test] @@ -277,45 +280,47 @@ fn handle_arg_larger_than_i64_failure() { .stderr(predicates::str::contains("value is not parseable")); } -#[test] -fn i64() { - invoke_with_roundtrip("i64_", i64::MAX); +#[tokio::test] +async fn i64() { + invoke_with_roundtrip("i64_", i64::MAX).await; } -#[test] -fn negative_i32() { - invoke_with_roundtrip("i32_", -42); +#[tokio::test] +async fn negative_i32() { + invoke_with_roundtrip("i32_", -42).await; } -#[test] -fn negative_i64() { - invoke_with_roundtrip("i64_", i64::MIN); +#[tokio::test] +async fn negative_i64() { + invoke_with_roundtrip("i64_", i64::MIN).await; } -#[test] -fn account_address() { +#[tokio::test] +async fn account_address() { invoke_with_roundtrip( "addresse", json!("GD5KD2KEZJIGTC63IGW6UMUSMVUVG5IHG64HUTFWCHVZH2N2IBOQN7PS"), - ); + ) + .await; } -#[test] -fn contract_address() { +#[tokio::test] +async fn contract_address() { invoke_with_roundtrip( "addresse", json!("CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE"), - ); + ) + .await; } -#[test] -fn bytes() { - invoke_with_roundtrip("bytes", json!("7374656c6c6172")); +#[tokio::test] +async fn bytes() { + invoke_with_roundtrip("bytes", json!("7374656c6c6172")).await; } -#[test] -fn const_enum() { - invoke_with_roundtrip("card", "11"); +#[tokio::test] +async fn const_enum() { + invoke_with_roundtrip("card", "11").await; } #[test] diff --git a/cmd/crates/soroban-test/tests/it/dotenv.rs b/cmd/crates/soroban-test/tests/it/integration/dotenv.rs similarity index 67% rename from cmd/crates/soroban-test/tests/it/dotenv.rs rename to cmd/crates/soroban-test/tests/it/integration/dotenv.rs index eb7b5a68f7..5d7aa102e3 100644 --- a/cmd/crates/soroban-test/tests/it/dotenv.rs +++ b/cmd/crates/soroban-test/tests/it/integration/dotenv.rs @@ -1,19 +1,6 @@ use soroban_test::TestEnv; -use crate::util::HELLO_WORLD; - -const SOROBAN_CONTRACT_ID: &str = "SOROBAN_CONTRACT_ID=1"; - -fn deploy(e: &TestEnv, id: &str) { - e.new_assert_cmd("contract") - .arg("deploy") - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .arg("--id") - .arg(id) - .assert() - .success(); -} +use super::util::{deploy_hello, TEST_CONTRACT_ID}; fn write_env_file(e: &TestEnv, contents: &str) { let env_file = e.dir().join(".env"); @@ -21,11 +8,15 @@ fn write_env_file(e: &TestEnv, contents: &str) { assert_eq!(contents, std::fs::read_to_string(env_file).unwrap()); } +fn contract_id() -> String { + format!("SOROBAN_CONTRACT_ID={TEST_CONTRACT_ID}") +} + #[test] fn can_read_file() { TestEnv::with_default(|e| { - deploy(e, "1"); - write_env_file(e, SOROBAN_CONTRACT_ID); + deploy_hello(e); + write_env_file(e, &contract_id()); e.new_assert_cmd("contract") .arg("invoke") .arg("--") @@ -40,8 +31,8 @@ fn can_read_file() { #[test] fn current_env_not_overwritten() { TestEnv::with_default(|e| { - deploy(e, "1"); - write_env_file(e, SOROBAN_CONTRACT_ID); + deploy_hello(e); + write_env_file(e, &contract_id()); e.new_assert_cmd("contract") .env("SOROBAN_CONTRACT_ID", "2") @@ -57,13 +48,13 @@ fn current_env_not_overwritten() { #[test] fn cli_args_have_priority() { TestEnv::with_default(|e| { - deploy(e, "2"); - write_env_file(e, SOROBAN_CONTRACT_ID); + deploy_hello(e); + write_env_file(e, &contract_id()); e.new_assert_cmd("contract") - .env("SOROBAN_CONTRACT_ID", "3") + .env("SOROBAN_CONTRACT_ID", "2") .arg("invoke") .arg("--id") - .arg("2") + .arg(TEST_CONTRACT_ID) .arg("--") .arg("hello") .arg("--world=world") diff --git a/cmd/crates/soroban-test/tests/it/integration/hello_world.rs b/cmd/crates/soroban-test/tests/it/integration/hello_world.rs new file mode 100644 index 0000000000..01b548e21a --- /dev/null +++ b/cmd/crates/soroban-test/tests/it/integration/hello_world.rs @@ -0,0 +1,379 @@ +use soroban_cli::commands::{ + config::identity, + contract::{self, fetch}, +}; +use soroban_test::TestEnv; + +use crate::util::DEFAULT_SEED_PHRASE; + +use super::util::{ + add_test_seed, deploy_hello, network_passphrase, network_passphrase_arg, rpc_url, rpc_url_arg, + DEFAULT_PUB_KEY, DEFAULT_PUB_KEY_1, DEFAULT_SECRET_KEY, HELLO_WORLD, TEST_CONTRACT_ID, +}; + +#[test] +fn install_wasm_then_deploy_contract() { + let sandbox = TestEnv::default(); + assert_eq!(deploy_hello(&sandbox), TEST_CONTRACT_ID); +} + +#[test] +fn invoke_hello_world() { + let sandbox = TestEnv::default(); + let id = deploy_hello(&sandbox); + println!("{id}"); + sandbox + .new_assert_cmd("contract") + .arg("invoke") + .arg("--id") + .arg(id) + .arg("--") + .arg("hello") + .arg("--world=world") + .assert() + .stdout("[\"Hello\",\"world\"]\n") + .success(); +} + +#[tokio::test] +async fn invoke_hello_world_with_lib() { + let e = &TestEnv::default(); + let id = deploy_hello(e); + let mut cmd = contract::invoke::Cmd { + contract_id: id, + slop: vec!["hello".into(), "--world=world".into()], + ..Default::default() + }; + + cmd.config.network.rpc_url = rpc_url(); + cmd.config.network.network_passphrase = network_passphrase(); + + let res = e.invoke_cmd(cmd).await.unwrap(); + assert_eq!(res, r#"["Hello","world"]"#); +} + +#[tokio::test] +async fn invoke_hello_world_with_lib_two() { + let e = &TestEnv::default(); + let id = deploy_hello(e); + let hello_world = HELLO_WORLD.to_string(); + let mut invoke_args = vec!["--id", &id, "--wasm", hello_world.as_str()]; + let args = vec!["--", "hello", "--world=world"]; + let res = + if let (Some(rpc), Some(network_passphrase)) = (rpc_url_arg(), network_passphrase_arg()) { + invoke_args.push(&rpc); + invoke_args.push(&network_passphrase); + e.invoke(&[invoke_args, args].concat()).await.unwrap() + } else { + e.invoke(&[invoke_args, args].concat()).await.unwrap() + }; + assert_eq!(res, r#"["Hello","world"]"#); +} + +#[test] +fn invoke_auth() { + let sandbox = TestEnv::default(); + let id = &deploy_hello(&sandbox); + sandbox + .new_assert_cmd("contract") + .arg("invoke") + .arg("--id") + .arg(id) + .arg("--wasm") + .arg(HELLO_WORLD.path()) + .arg("--") + .arg("auth") + .arg(&format!("--addr={DEFAULT_PUB_KEY}")) + .arg("--world=world") + .assert() + .stdout(format!("\"{DEFAULT_PUB_KEY}\"\n")) + .success(); + + // Invoke it again without providing the contract, to exercise the deployment + sandbox + .new_assert_cmd("contract") + .arg("invoke") + .arg("--id") + .arg(id) + .arg("--") + .arg("auth") + .arg(&format!("--addr={DEFAULT_PUB_KEY}")) + .arg("--world=world") + .assert() + .stdout(format!("\"{DEFAULT_PUB_KEY}\"\n")) + .success(); +} + +#[tokio::test] +async fn invoke_auth_with_identity() { + let sandbox = TestEnv::default(); + sandbox + .cmd::("test -d ") + .run() + .await + .unwrap(); + let id = deploy_hello(&sandbox); + sandbox + .new_assert_cmd("contract") + .arg("invoke") + .arg("--id") + .arg(id) + .arg("--wasm") + .arg(HELLO_WORLD.path()) + .arg("--") + .arg("auth") + .arg("--addr=test") + .arg("--world=world") + .assert() + .stdout(format!("\"{DEFAULT_PUB_KEY}\"\n")) + .success(); +} + +#[test] +fn invoke_auth_with_different_test_account() { + let sandbox = TestEnv::default(); + let id = deploy_hello(&sandbox); + sandbox + .new_assert_cmd("contract") + .arg("invoke") + .arg("--hd-path=1") + .arg("--id") + .arg(id) + .arg("--wasm") + .arg(HELLO_WORLD.path()) + .arg("--") + .arg("auth") + .arg(&format!("--addr={DEFAULT_PUB_KEY_1}")) + .arg("--world=world") + .assert() + .stdout(format!("\"{DEFAULT_PUB_KEY_1}\"\n")) + .success(); +} + +#[tokio::test] +async fn invoke_auth_with_different_test_account_fail() { + let sandbox = TestEnv::default(); + let id = &deploy_hello(&sandbox); + let res = sandbox + .invoke(&[ + "--hd-path=1", + "--id", + id, + "--wasm", + HELLO_WORLD.path().to_str().unwrap(), + &rpc_url_arg().unwrap_or_default(), + &network_passphrase_arg().unwrap_or_default(), + "--", + "auth", + &format!("--addr={DEFAULT_PUB_KEY}"), + "--world=world", + ]) + .await; + let e = res.unwrap_err(); + assert!( + matches!(e, contract::invoke::Error::Host(_)), + "Expected host error got {e:?}" + ); +} + +#[test] +fn contract_data_read_failure() { + let sandbox = TestEnv::default(); + let id = deploy_hello(&sandbox); + + sandbox + .new_assert_cmd("contract") + .arg("read") + .arg("--id") + .arg(id) + .arg("--key=COUNTER") + .arg("--durability=persistent") + .assert() + .failure() + .stderr( + "error: no matching contract data entries were found for the specified contract id\n", + ); +} + +#[test] +fn contract_data_read() { + let sandbox = TestEnv::default(); + let id = &deploy_hello(&sandbox); + + sandbox + .new_assert_cmd("contract") + .arg("invoke") + .arg("--id") + .arg(id) + .arg("--") + .arg("inc") + .assert() + .success(); + + sandbox + .new_assert_cmd("contract") + .arg("read") + .arg("--id") + .arg(id) + .arg("--key=COUNTER") + .arg("--durability=persistent") + .assert() + .success() + .stdout(predicates::str::starts_with("COUNTER,1")); + + sandbox + .new_assert_cmd("contract") + .arg("invoke") + .arg("--id") + .arg(id) + .arg("--") + .arg("inc") + .assert() + .success(); + + sandbox + .new_assert_cmd("contract") + .arg("read") + .arg("--id") + .arg(id) + .arg("--key=COUNTER") + .arg("--durability=persistent") + .assert() + .success() + .stdout(predicates::str::starts_with("COUNTER,2")); +} + +#[tokio::test] +async fn invoke_hello_world_with_seed() { + let sandbox = TestEnv::default(); + let identity = add_test_seed(sandbox.dir()); + invoke_with_source(&sandbox, &identity).await; +} + +#[tokio::test] +async fn invoke_with_seed() { + let sandbox = TestEnv::default(); + invoke_with_source(&sandbox, DEFAULT_SEED_PHRASE).await; +} + +#[tokio::test] +async fn invoke_with_id() { + let sandbox = TestEnv::default(); + let identity = add_test_seed(sandbox.dir()); + invoke_with_source(&sandbox, &identity).await; +} + +#[tokio::test] +async fn invoke_with_sk() { + let sandbox = TestEnv::default(); + invoke_with_source(&sandbox, DEFAULT_SECRET_KEY).await; +} + +async fn invoke_with_source(sandbox: &TestEnv, source: &str) { + let id = &deploy_hello(sandbox); + let cmd = sandbox + .invoke(&[ + "--source-account", + source, + "--id", + id, + "--wasm", + HELLO_WORLD.path().to_str().unwrap(), + &rpc_url_arg().unwrap_or_default(), + &network_passphrase_arg().unwrap_or_default(), + "--", + "hello", + "--world=world", + ]) + .await + .unwrap(); + assert_eq!(cmd, "[\"Hello\",\"world\"]"); + + // Invoke it again without providing the contract, to exercise the deployment + let cmd = sandbox + .invoke(&[ + "--source-account", + source, + "--id", + id, + "--", + "hello", + "--world=world", + ]) + .await + .unwrap(); + assert_eq!(cmd, "[\"Hello\",\"world\"]"); +} + +#[tokio::test] +async fn handles_kebab_case() { + let e = TestEnv::default(); + let id = deploy_hello(&e); + assert!(e + .invoke(&[ + "--id", + &id, + "--wasm", + HELLO_WORLD.path().to_str().unwrap(), + "--", + "multi-word-cmd", + "--contract-owner=world", + ]) + .await + .is_ok()); +} + +#[tokio::test] +async fn fetch() { + let e = TestEnv::default(); + let f = e.dir().join("contract.wasm"); + let id = deploy_hello(&e); + let cmd = e.cmd_arr::(&["--id", &id, "--out-file", f.to_str().unwrap()]); + cmd.run().await.unwrap(); + assert!(f.exists()); +} + +#[test] +fn build() { + let sandbox = TestEnv::default(); + let cargo_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let hello_world_contract_path = + cargo_dir.join("tests/fixtures/test-wasms/hello_world/Cargo.toml"); + sandbox + .new_assert_cmd("contract") + .arg("build") + .arg("--manifest-path") + .arg(hello_world_contract_path) + .arg("--profile") + .arg("test-wasms") + .arg("--package") + .arg("test_hello_world") + .assert() + .success(); +} + +#[test] +fn invoke_prng_u64_in_range_test() { + let sandbox = TestEnv::default(); + let res = sandbox + .new_assert_cmd("contract") + .arg("deploy") + .arg("--wasm") + .arg(HELLO_WORLD.path()) + .assert() + .success(); + let stdout = String::from_utf8(res.get_output().stdout.clone()).unwrap(); + let id = stdout.trim_end(); + println!("{id}"); + sandbox + .new_assert_cmd("contract") + .arg("invoke") + .arg("--id") + .arg(id) + .arg("--") + .arg("prng_u64_in_range") + .arg("--low=0") + .arg("--high=100") + .assert() + .success(); +} diff --git a/cmd/crates/soroban-test/tests/it/integration/util.rs b/cmd/crates/soroban-test/tests/it/integration/util.rs new file mode 100644 index 0000000000..f228a09aa9 --- /dev/null +++ b/cmd/crates/soroban-test/tests/it/integration/util.rs @@ -0,0 +1,100 @@ +use std::{fmt::Display, path::Path}; + +use assert_cmd::Command; +use soroban_test::{TestEnv, Wasm}; + +use crate::util::{add_identity, SecretKind}; + +pub const HELLO_WORLD: &Wasm = &Wasm::Custom("test-wasms", "test_hello_world"); +pub const CUSTOM_TYPES: &Wasm = &Wasm::Custom("test-wasms", "test_custom_types"); + +pub fn add_test_seed(dir: &Path) -> String { + let name = "test_seed"; + add_identity( + dir, + name, + SecretKind::Seed, + "coral light army gather adapt blossom school alcohol coral light army giggle", + ); + name.to_owned() +} + +pub fn invoke(sandbox: &TestEnv, func: &str) -> Command { + let mut s = sandbox.new_assert_cmd("contract"); + s.arg("invoke") + .arg("--id=1") + .arg("--wasm") + .arg(CUSTOM_TYPES.path()) + .arg("--") + .arg(func); + s +} + +pub async fn invoke_with_roundtrip(func: &str, data: D) +where + D: Display, +{ + let e = TestEnv::default(); + let data = data.to_string(); + println!("{data}"); + let res = e + .invoke(&[ + "--id=1", + "--wasm", + &CUSTOM_TYPES.to_string(), + "--", + func, + &format!("--{func}"), + &data, + ]) + .await + .unwrap(); + assert_eq!(res, data); +} + +pub const DEFAULT_PUB_KEY: &str = "GDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCR4W4"; +pub const DEFAULT_SECRET_KEY: &str = "SC36BWNUOCZAO7DMEJNNKFV6BOTPJP7IG5PSHLUOLT6DZFRU3D3XGIXW"; + +pub const DEFAULT_PUB_KEY_1: &str = "GCKZUJVUNEFGD4HLFBUNVYM2QY2P5WQQZMGRA3DDL4HYVT5MW5KG3ODV"; +pub const TEST_SALT: &str = "f55ff16f66f43360266b95db6f8fec01d76031054306ae4a4b380598f6cfd114"; +pub const TEST_CONTRACT_ID: &str = "CBVTIVBYWAO2HNPNGKDCZW4OZYYESTKNGD7IPRTDGQSFJS4QBDQQJX3T"; + +pub fn rpc_url() -> Option { + std::env::var("SOROBAN_RPC_URL").ok() +} + +pub fn rpc_url_arg() -> Option { + rpc_url().map(|url| format!("--rpc-url={url}")) +} + +pub fn network_passphrase() -> Option { + std::env::var("SOROBAN_NETWORK_PASSPHRASE").ok() +} + +pub fn network_passphrase_arg() -> Option { + network_passphrase().map(|p| format!("--network-passphrase={p}")) +} + +pub fn deploy_hello(sandbox: &TestEnv) -> String { + let hash = HELLO_WORLD.hash().unwrap(); + sandbox + .new_assert_cmd("contract") + .arg("install") + .arg("--wasm") + .arg(HELLO_WORLD.path()) + .assert() + .success() + .stdout(format!("{hash}\n")); + + sandbox + .new_assert_cmd("contract") + .arg("deploy") + .arg("--wasm-hash") + .arg(&format!("{hash}")) + .arg("--salt") + .arg(TEST_SALT) + .assert() + .success() + .stdout(format!("{TEST_CONTRACT_ID}\n")); + TEST_CONTRACT_ID.to_string() +} diff --git a/cmd/crates/soroban-test/tests/it/integration_and_sandbox.rs b/cmd/crates/soroban-test/tests/it/integration_and_sandbox.rs deleted file mode 100644 index 5536966c5b..0000000000 --- a/cmd/crates/soroban-test/tests/it/integration_and_sandbox.rs +++ /dev/null @@ -1,222 +0,0 @@ -use soroban_cli::commands::{config::identity, contract::fetch}; -use soroban_test::TestEnv; - -use crate::util::{ - add_test_seed, deploy_hello, is_rpc, network_passphrase_arg, rpc_url_arg, DEFAULT_PUB_KEY, - DEFAULT_SECRET_KEY, DEFAULT_SEED_PHRASE, HELLO_WORLD, -}; - -#[test] -fn invoke_hello_world_with_lib_two() { - TestEnv::with_default(|e| { - let id = deploy_hello(e); - let hello_world = HELLO_WORLD.to_string(); - let mut invoke_args = vec!["--id", &id, "--wasm", hello_world.as_str()]; - let args = vec!["--", "hello", "--world=world"]; - let res = if let (Some(rpc), Some(network_passphrase)) = - (rpc_url_arg(), network_passphrase_arg()) - { - invoke_args.push(&rpc); - invoke_args.push(&network_passphrase); - e.invoke(&[invoke_args, args].concat()).unwrap() - } else { - e.invoke(&[invoke_args, args].concat()).unwrap() - }; - assert_eq!(res, r#"["Hello","world"]"#); - }); -} - -#[test] -fn invoke_auth() { - let sandbox = TestEnv::default(); - let id = &deploy_hello(&sandbox); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .arg("--") - .arg("auth") - .arg(&format!("--addr={DEFAULT_PUB_KEY}")) - .arg("--world=world") - .assert() - .stdout(format!("\"{DEFAULT_PUB_KEY}\"\n")) - .success(); - - // Invoke it again without providing the contract, to exercise the deployment - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--") - .arg("auth") - .arg(&format!("--addr={DEFAULT_PUB_KEY}")) - .arg("--world=world") - .assert() - .stdout(format!("\"{DEFAULT_PUB_KEY}\"\n")) - .success(); -} - -#[tokio::test] -async fn invoke_auth_with_identity() { - let sandbox = TestEnv::default(); - sandbox - .cmd::("test -d ") - .run() - .await - .unwrap(); - let id = deploy_hello(&sandbox); - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .arg("--") - .arg("auth") - .arg("--addr=test") - .arg("--world=world") - .assert() - .stdout(format!("\"{DEFAULT_PUB_KEY}\"\n")) - .success(); -} - -#[test] -fn contract_data_read_failure() { - let sandbox = TestEnv::default(); - let id = deploy_hello(&sandbox); - - sandbox - .new_assert_cmd("contract") - .arg("read") - .arg("--id") - .arg(id) - .arg("--key=COUNTER") - .arg("--durability=persistent") - .assert() - .failure() - .stderr( - "error: no matching contract data entries were found for the specified contract id\n", - ); -} - -#[test] -fn contract_data_read() { - let sandbox = TestEnv::default(); - let id = &deploy_hello(&sandbox); - - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--") - .arg("inc") - .assert() - .success(); - - sandbox - .new_assert_cmd("contract") - .arg("read") - .arg("--id") - .arg(id) - .arg("--key=COUNTER") - .arg("--durability=persistent") - .assert() - .success() - .stdout(predicates::str::starts_with("COUNTER,1")); - - sandbox - .new_assert_cmd("contract") - .arg("invoke") - .arg("--id") - .arg(id) - .arg("--") - .arg("inc") - .assert() - .success(); - - sandbox - .new_assert_cmd("contract") - .arg("read") - .arg("--id") - .arg(id) - .arg("--key=COUNTER") - .arg("--durability=persistent") - .assert() - .success() - .stdout(predicates::str::starts_with("COUNTER,2")); -} - -#[test] -fn invoke_hello_world_with_seed() { - let sandbox = TestEnv::default(); - let identity = add_test_seed(sandbox.dir()); - invoke_with_source(&sandbox, &identity); -} - -#[test] -fn invoke_with_seed() { - let sandbox = TestEnv::default(); - invoke_with_source(&sandbox, DEFAULT_SEED_PHRASE); -} - -#[test] -fn invoke_with_id() { - let sandbox = TestEnv::default(); - let identity = add_test_seed(sandbox.dir()); - invoke_with_source(&sandbox, &identity); -} - -#[test] -fn invoke_with_sk() { - let sandbox = TestEnv::default(); - invoke_with_source(&sandbox, DEFAULT_SECRET_KEY); -} - -fn invoke_with_source(sandbox: &TestEnv, source: &str) { - let id = &deploy_hello(sandbox); - let cmd = sandbox.invoke(&[ - "--source-account", - source, - "--id", - id, - "--wasm", - HELLO_WORLD.path().to_str().unwrap(), - &rpc_url_arg().unwrap_or_default(), - &network_passphrase_arg().unwrap_or_default(), - "--", - "hello", - "--world=world", - ]); - assert_eq!(cmd.unwrap(), "[\"Hello\",\"world\"]"); - - // Invoke it again without providing the contract, to exercise the deployment - let cmd = sandbox.invoke(&[ - "--source-account", - source, - "--id", - id, - "--", - "hello", - "--world=world", - ]); - assert_eq!(cmd.unwrap(), "[\"Hello\",\"world\"]"); -} - -#[tokio::test] -async fn fetch() { - if !is_rpc() { - return; - } - let e = TestEnv::default(); - let f = e.dir().join("contract.wasm"); - let id = deploy_hello(&e); - let cmd = e.cmd_arr::(&["--id", &id, "--out-file", f.to_str().unwrap()]); - cmd.run().await.unwrap(); - assert!(f.exists()); -} diff --git a/cmd/crates/soroban-test/tests/it/main.rs b/cmd/crates/soroban-test/tests/it/main.rs index e822b7740d..424ea37122 100644 --- a/cmd/crates/soroban-test/tests/it/main.rs +++ b/cmd/crates/soroban-test/tests/it/main.rs @@ -1,10 +1,7 @@ mod arg_parsing; mod config; - -mod custom_types; -mod dotenv; -mod hello_world; -mod integration_and_sandbox; +#[cfg(ignore)] +mod integration; mod lab; mod plugin; mod util; diff --git a/cmd/crates/soroban-test/tests/it/util.rs b/cmd/crates/soroban-test/tests/it/util.rs index 68c2e31acb..75389c8a4b 100644 --- a/cmd/crates/soroban-test/tests/it/util.rs +++ b/cmd/crates/soroban-test/tests/it/util.rs @@ -1,10 +1,8 @@ -use std::{fmt::Display, path::Path}; +use std::path::Path; -use assert_cmd::Command; use soroban_cli::commands::config::{locator::KeyType, secret::Secret}; -use soroban_test::{TestEnv, Wasm}; +use soroban_test::Wasm; -pub const HELLO_WORLD: &Wasm = &Wasm::Custom("test-wasms", "test_hello_world"); pub const CUSTOM_TYPES: &Wasm = &Wasm::Custom("test-wasms", "test_custom_types"); #[derive(Clone)] @@ -40,102 +38,5 @@ pub fn add_test_id(dir: &Path) -> String { name.to_owned() } -pub fn add_test_seed(dir: &Path) -> String { - let name = "test_seed"; - add_identity( - dir, - name, - SecretKind::Seed, - "coral light army gather adapt blossom school alcohol coral light army giggle", - ); - name.to_owned() -} - -pub fn invoke(sandbox: &TestEnv, func: &str) -> Command { - let mut s = sandbox.new_assert_cmd("contract"); - s.arg("invoke") - .arg("--id=1") - .arg("--wasm") - .arg(CUSTOM_TYPES.path()) - .arg("--") - .arg(func); - s -} - -pub fn invoke_with_roundtrip(func: &str, data: D) -where - D: Display, -{ - TestEnv::with_default(|e| { - let data = data.to_string(); - println!("{data}"); - let res = e - .invoke(&[ - "--id=1", - "--wasm", - &CUSTOM_TYPES.to_string(), - "--", - func, - &format!("--{func}"), - &data, - ]) - .unwrap(); - assert_eq!(res, data); - }); -} - -pub fn is_rpc() -> bool { - std::env::var("SOROBAN_RPC_URL").is_ok() -} - pub const DEFAULT_SEED_PHRASE: &str = "coral light army gather adapt blossom school alcohol coral light army giggle"; - -pub const DEFAULT_PUB_KEY: &str = "GDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCR4W4"; -pub const DEFAULT_SECRET_KEY: &str = "SC36BWNUOCZAO7DMEJNNKFV6BOTPJP7IG5PSHLUOLT6DZFRU3D3XGIXW"; - -pub const DEFAULT_PUB_KEY_1: &str = "GCKZUJVUNEFGD4HLFBUNVYM2QY2P5WQQZMGRA3DDL4HYVT5MW5KG3ODV"; -pub const TEST_SALT: &str = "f55ff16f66f43360266b95db6f8fec01d76031054306ae4a4b380598f6cfd114"; - -pub fn rpc_url() -> Option { - std::env::var("SOROBAN_RPC_URL").ok() -} - -pub fn rpc_url_arg() -> Option { - rpc_url().map(|url| format!("--rpc-url={url}")) -} - -pub fn network_passphrase() -> Option { - std::env::var("SOROBAN_NETWORK_PASSPHRASE").ok() -} - -pub fn network_passphrase_arg() -> Option { - network_passphrase().map(|p| format!("--network-passphrase={p}")) -} - -pub const TEST_CONTRACT_ID: &str = "CBVTIVBYWAO2HNPNGKDCZW4OZYYESTKNGD7IPRTDGQSFJS4QBDQQJX3T"; - -pub fn deploy_hello(sandbox: &TestEnv) -> String { - let hash = HELLO_WORLD.hash().unwrap(); - sandbox - .new_assert_cmd("contract") - .arg("install") - .arg("--wasm") - .arg(HELLO_WORLD.path()) - .assert() - .success() - .stdout(format!("{hash}\n")); - - let mut cmd: &mut assert_cmd::Command = &mut sandbox.new_assert_cmd("contract"); - - cmd = cmd.arg("deploy").arg("--wasm-hash").arg(&format!("{hash}")); - if is_rpc() { - cmd = cmd.arg("--salt").arg(TEST_SALT); - } else { - cmd = cmd.arg("--id").arg(TEST_CONTRACT_ID); - } - cmd.assert() - .success() - .stdout(format!("{TEST_CONTRACT_ID}\n")); - TEST_CONTRACT_ID.to_string() -} diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index afdfa17257..d84e72fed6 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -10,16 +10,15 @@ use clap::{arg, command, value_parser, Parser}; use ed25519_dalek::SigningKey; use heck::ToKebabCase; - use soroban_env_host::{ xdr::{ - self, Error as XdrError, Hash, HostFunction, InvokeContractArgs, - InvokeHostFunctionOp, LedgerEntryData, LedgerFootprint, Memo, - MuxedAccount, Operation, OperationBody, Preconditions, ScAddress, ScSpecEntry, - ScSpecFunctionV0, ScSpecTypeDef, ScVal, ScVec, SequenceNumber, - SorobanAuthorizationEntry, SorobanResources, Transaction, - TransactionExt, Uint256, VecM, - }, HostError, + self, Error as XdrError, Hash, HostFunction, InvokeContractArgs, InvokeHostFunctionOp, + LedgerEntryData, LedgerFootprint, Memo, MuxedAccount, Operation, OperationBody, + Preconditions, ScAddress, ScSpecEntry, ScSpecFunctionV0, ScSpecTypeDef, ScVal, ScVec, + SequenceNumber, SorobanAuthorizationEntry, SorobanResources, Transaction, TransactionExt, + Uint256, VecM, + }, + HostError, }; use soroban_spec::read::FromWasmError; diff --git a/cmd/soroban-cli/src/commands/contract/read.rs b/cmd/soroban-cli/src/commands/contract/read.rs index 8199c10dce..ab2686b0bd 100644 --- a/cmd/soroban-cli/src/commands/contract/read.rs +++ b/cmd/soroban-cli/src/commands/contract/read.rs @@ -6,8 +6,8 @@ use std::{ use clap::{command, Parser, ValueEnum}; use soroban_env_host::{ xdr::{ - ContractDataEntry, Error as XdrError, LedgerEntryData, LedgerKey, - LedgerKeyContractData, ScVal, WriteXdr, + ContractDataEntry, Error as XdrError, LedgerEntryData, LedgerKey, LedgerKeyContractData, + ScVal, WriteXdr, }, HostError, }; diff --git a/cmd/soroban-cli/src/commands/contract/restore.rs b/cmd/soroban-cli/src/commands/contract/restore.rs index cd13c1719c..e709ebf7a3 100644 --- a/cmd/soroban-cli/src/commands/contract/restore.rs +++ b/cmd/soroban-cli/src/commands/contract/restore.rs @@ -176,7 +176,6 @@ impl Cmd { } parse_operations(&operations).ok_or(Error::MissingOperationResult) } - } fn parse_operations(ops: &[OperationMeta]) -> Option { diff --git a/cmd/soroban-cli/src/commands/lab/token/wrap.rs b/cmd/soroban-cli/src/commands/lab/token/wrap.rs index a49f8ddf9a..b2f878ca2b 100644 --- a/cmd/soroban-cli/src/commands/lab/token/wrap.rs +++ b/cmd/soroban-cli/src/commands/lab/token/wrap.rs @@ -5,7 +5,8 @@ use soroban_env_host::{ Error as XdrError, Hash, HostFunction, InvokeHostFunctionOp, LedgerKey::ContractData, LedgerKeyContractData, Memo, MuxedAccount, Operation, OperationBody, Preconditions, ScAddress, ScVal, SequenceNumber, Transaction, TransactionExt, Uint256, VecM, - }, HostError, + }, + HostError, }; use std::convert::Infallible; use std::{array::TryFromSliceError, fmt::Debug, num::ParseIntError}; diff --git a/cmd/soroban-rpc/internal/test/cli_test.go b/cmd/soroban-rpc/internal/test/cli_test.go index bb3a789acc..186428ecbc 100644 --- a/cmd/soroban-rpc/internal/test/cli_test.go +++ b/cmd/soroban-rpc/internal/test/cli_test.go @@ -27,13 +27,14 @@ func cargoTest(t *testing.T, name string) { c.Env = append(os.Environ(), fmt.Sprintf("SOROBAN_RPC_URL=http://localhost:%d/", sorobanRPCPort), fmt.Sprintf("SOROBAN_NETWORK_PASSPHRASE=%s", StandaloneNetworkPassphrase), + "IGNORED=1", ) res := icmd.RunCmd(c) require.NoError(t, res.Error, res.Stdout(), res.Stderr()) } func TestCLICargoTest(t *testing.T) { - names := icmd.RunCmd(icmd.Command("cargo", "-q", "test", "integration_and_sandbox::", "--package", "soroban-test", "--", "--list")) + names := icmd.RunCmd(icmd.Command("cargo", "-q", "test", "integration::", "--package", "soroban-test", "--", "--list")) input := names.Stdout() lines := strings.Split(input, "\n") for _, line := range lines {