Skip to content

Commit

Permalink
Feat!(CLI): remove sandbox (stellar#997)
Browse files Browse the repository at this point in the history
* feat!: remove run_in_sandbox
* fix: reorganize tests that rely on network and ignore outside of go test
* fix: use feature instead of cfg so that cargo test --list can find tests
* fix: move common tests to single functions to skip setup time
* feat!: skip wasm in invoke
* fix: fully remove all sandbox related types and args
  • Loading branch information
willemneal committed Oct 19, 2023
1 parent 35d33ee commit 37379dd
Show file tree
Hide file tree
Showing 34 changed files with 1,036 additions and 2,511 deletions.
3 changes: 3 additions & 0 deletions cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ fs_extra = "1.3.0"
serde_json = "1.0.93"
which = { workspace = true }
tokio = "1.28.1"

[features]
integration = []
11 changes: 6 additions & 5 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
/// });
/// ```
///
Expand Down Expand Up @@ -122,7 +122,7 @@ impl TestEnv {
}

/// A convenience method for using the invoke command.
pub fn invoke<I: AsRef<str>>(&self, command_str: &[I]) -> Result<String, invoke::Error> {
pub async fn invoke<I: AsRef<str>>(&self, command_str: &[I]) -> Result<String, invoke::Error> {
let cmd = contract::invoke::Cmd::parse_arg_vec(
&command_str
.iter()
Expand All @@ -131,13 +131,13 @@ impl TestEnv {
.collect::<Vec<_>>(),
)
.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<String, invoke::Error> {
pub async fn invoke_cmd(&self, mut cmd: invoke::Cmd) -> Result<String, invoke::Error> {
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,
Expand All @@ -148,6 +148,7 @@ impl TestEnv {
very_verbose: false,
list: false,
})
.await
}

/// Reference to current directory of the `TestEnv`.
Expand Down
24 changes: 2 additions & 22 deletions cmd/crates/soroban-test/tests/it/config.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 37379dd

Please sign in to comment.