Local-testing mode
It is possible (and encouraged during development) to compile Soroban contracts natively (eg. as x86-64 or AArch64 code) and link against the host environment directly, such that the contract is not a guest running in a Wasm virtual machine at all: it is simply one native library calling another — its host — and both host and contract are linked together as a single program, together with a test harness. This configuration is referred to as “local-testing mode” and since it eliminates the Wasm virtual machine from the debugging experience it has many advantages:- Tests run much faster since there is no VM interpreting them, and will execute in parallel by default on multiple threads.
- Tests can use numerous standard testing and debugging techniques:
- The standard Rust
#[test]harness, including push-button IDE support for running and re-running single tests. - Standard IDE-supported debuggers, including IDE support for setting breakpoints and inspecting values in both contract and host.
- Lightweight debugging via standard logging or tracing.
- Systematic testing such as fuzzing, property-testing, or even model checking or formal verification.
- The simplest of all debugging approaches, printing to standard error.
- The standard Rust
Wasm mode
If on the other hand you wish to compile for deployment, you must tell cargo to build for the Wasm target. Building for Wasm will disable many of the debugging facilities described above, typically for one of three reasons:- The Wasm VM simply can’t (or the VM we’ve chosen doesn’t) provide them.
- The Wasm VM could provide them but doing so would violate constraints of the contract Rust dialect.
- The Wasm VM could provide them but doing so would make the resulting Wasm code impractically large.
- A “sandbox” host with a mock-ledger that can read and write
CONTRACT_DATAledger entries to the local filesystem. - A general logging system that allows contracts to log values of the shared host/guest “value” type, even in production.
- User-extensible
Errorcodes that can be returned from any contract call to indicate problems.