rust-testing

star 123

Patterns for Rust testing in Axone CosmWasm contracts. Use when adding unit tests, integration tests, data-driven cases, or coverage-oriented test scenarios.

axone-protocol By axone-protocol schedule Updated 3/28/2026

name: rust-testing description: Patterns for Rust testing in Axone CosmWasm contracts. Use when adding unit tests, integration tests, data-driven cases, or coverage-oriented test scenarios. license: BSD-3-Clause metadata: author: axone.xyz version: "1.0"

Rust Testing

Coverage Targets

Component Target
Handlers 100%
State operations 100%
Error paths 90%+
Message parsing 80%+
Overall 90%+

Minimum Cases to Cover

  • For handlers: cover the happy path, parameter variations, error paths, and resulting state changes.
  • For queries: cover empty state, populated state, pagination behavior, and non-existent items.
  • For state transitions: cover initial state, updates after execute, and persistence across operations.

Running Tests

# Run all unit tests
cargo make test-unit

# Run all tests (includes integration)
cargo make test

# Run tests with coverage
cargo make test-coverage

# Run specific test
cargo test test_name -- --nocapture

Coverage output is written to lcov.info.

Viewing Coverage

# Generate HTML report (requires lcov)
genhtml lcov.info --output-directory coverage/

# Or use cargo-llvm-cov directly
cargo llvm-cov --html --open

Test Design Rules

  1. Isolate tests. Each test should set up its own environment.
  2. Test contract behavior, not framework internals.
  3. Assert exact errors when possible.
  4. Cover edge cases such as zero values, empty strings, and upper bounds.
  5. Prefer descriptive test names without a test_ prefix.
  6. Use tuple-driven cases for simple matrices and structs only when the case shape needs named fields.

References

  • For cw-orch integration harness patterns and common integration scenarios, read integration-patterns.
  • For naming and data-driven test examples, read test-style.
Install via CLI
npx skills add https://github.com/axone-protocol/contracts --skill rust-testing
Repository Details
star Stars 123
call_split Forks 20
navigation Branch main
article Path SKILL.md
More from Creator
axone-protocol
axone-protocol Explore all skills →