33 releases (stable)
| 22.5.0 | Mar 12, 2025 |
|---|---|
| 22.2.0 | Jan 9, 2025 |
| 22.1.0 | Dec 18, 2024 |
| 22.0.0 | Nov 19, 2024 |
| 0.9.4 |
|
#4 in #command-string
1,939 downloads per month
68KB
359 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
TestEnvis a test environment for running tests isolated from each other.TestEnv::with_defaultinvokes a closure, which is passed a reference to a randomTestEnv.TestEnv::new_assert_cmdcreates anassert_cmd::Commandfor a given subcommand and sets the current directory to be the same asTestEnv.TestEnv::cmdis a generic function which parses a command from a string. Note, however, that it usesshlexto 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 useTestEnv::cmd_arrinstead.TestEnv::cmd_arris a generic function which takes an array of&strwhich is passed directly to clap. This is the preferred way since it ensures no string parsing footguns.TestEnv::invokea 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()
);
});
}
Integration tests in Crate
Currently all tests that require an RPC server are hidden behind a it feature, found here. To allow Rust-Analyzer to see the tests in vscode, .vscode/settings.json. Without RA, you can't follow through definitions and more importantly see errors before running tests.
Dependencies
~69–94MB
~1.5M SLoC