15 releases (9 stable)

new 20.3.4 Apr 16, 2024
20.3.1 Feb 23, 2024
20.2.0 Jan 12, 2024
20.1.1 Dec 21, 2023
0.9.4 Jul 27, 2023

#22 in #soroban

Download history 5/week @ 2023-12-19 9/week @ 2024-01-09 3/week @ 2024-02-06 105/week @ 2024-02-20 32/week @ 2024-02-27 1/week @ 2024-03-05 26/week @ 2024-03-12 106/week @ 2024-03-19 9/week @ 2024-04-02

141 downloads per month

Apache-2.0

18KB
287 lines

Soroban Test

Test framework wrapping Soroban CLI.

Provides a way to run tests against a local sandbox; running against RPC endpoint coming soon.

Overview

  • TestEnv is a test environment for running tests isolated from each other.
  • TestEnv::with_default invokes a closure, which is passed a reference to a random TestEnv.
  • TestEnv::new_assert_cmd creates an assert_cmd::Command for a given subcommand and sets the current directory to be the same as TestEnv.
  • TestEnv::cmd is a generic function which parses a command from a string. Note, however, that it uses shlex to tokenize the string. This can cause issues for commands which contain strings with "s. For example, {"hello": "world"} becomes {hello:world}. For that reason it's recommended to use TestEnv::cmd_arr instead.
  • TestEnv::cmd_arr is a generic function which takes an array of &str which is passed directly to clap. This is the preferred way since it ensures no string parsing footguns.
  • TestEnv::invoke a convenience function for using the invoke command.

Example

use soroban_test::{TestEnv, Wasm};

const WASM: &Wasm = &Wasm::Release("soroban_hello_world_contract");
const FRIEND: &str = "friend";

#[test]
fn invoke() {
    TestEnv::with_default(|workspace| {
        assert_eq!(
            format!("[\"Hello\",\"{FRIEND}\"]"),
            workspace
                .invoke(&[
                    "--id",
                    "1",
                    "--wasm",
                    &WASM.path().to_string_lossy(),
                    "--",
                    "hello",
                    "--to",
                    FRIEND,
                ])
                .unwrap()
        );
    });
}

Dependencies

~52–74MB
~1.5M SLoC