Skip to main content
Mollusk is a lightweight test harness for Solana programs written in Rust. It provides a simple interface for testing Solana program executions in a minified Solana Virtual Machine (SVM) environment.
Mollusk is designed for Rust-only testing. For multi-language testing, see [LiteSVMtesting/litesvm).

Overview

Mollusk takes a minimalist approach to testing:
It creates a minimal SVM environment by provisioning:
  • Program cache
  • Transaction context
  • Invoke context
These components directly execute your program’s ELF using the BPF Loader, without the overhead of a full validator.

Key Features

  • Exceptionally Fast - No validator overhead, direct program execution
  • Explicit Account Management - You provide all accounts needed
  • Configurable Environment - Adjust compute budget, features, and sysvars
  • Built-in Assertions - Ergonomic Check API for validating results
  • Instruction Chains - Test sequences of instructions
  • Compute Unit Benchmarking - Built-in CU usage tracking

When to Use Mollusk

Mollusk is ideal for:
  • Pure Rust testing - When your test suite is entirely in Rust
  • Unit tests - Testing individual instructions in isolation
  • Compute unit optimization - Benchmarking and tracking CU usage
  • Fast CI/CD - Minimal dependencies and fast compilation
  • Anchor programs - Testing with or without Anchor test templates

Installation

Add Mollusk to your test dependencies:
You can also initialize an Anchor project with Mollusk tests:

Basic Usage

Single Instruction Test

Here’s a simple test that processes one instruction:

With Validation Checks

Mollusk provides a Check API for ergonomic result validation:
Mollusk::default() creates an instance without loading custom programs, but includes default builtin programs. Use Mollusk::new() to load your program.

Testing Anchor Programs

When testing Anchor programs, you’ll work with the compiled program binary:

Instruction Chains

Mollusk can process sequences of instructions, useful for testing workflows:

Validated Instruction Chains

You can validate state after each instruction in a chain:
Instruction chains in Mollusk are not equivalent to Solana transactions. They don’t enforce transaction constraints like account limits or size restrictions.

Compute Unit Benchmarking

Mollusk includes a built-in bencher for tracking compute unit usage:
This generates a markdown file with compute unit usage:
To run the benchmark:
Add this to your Cargo.toml:

Check API Reference

The Check enum provides several validation methods:

Advanced Configuration

Compute Budget

Feature Set

Sysvars

Testing Best Practices

  1. Test one instruction at a time - Keep tests focused and isolated
  2. Use descriptive test names - Make test failures easy to understand
  3. Set up minimal accounts - Only include accounts needed for the test
  4. Validate expected outcomes - Use Check API for comprehensive validation
  5. Benchmark critical paths - Track compute units for expensive operations
  6. Test error cases - Verify your program fails correctly

Example: Full Anchor Test Suite

Limitations

  • Rust only - No TypeScript or Python support
  • Explicit accounts - Must provide all accounts manually
  • No RPC - Direct program execution only
  • Minimal validator behavior - Doesn’t simulate full validator

Comparison with Other Frameworks

Next Steps

  • Explore [LiteSVMtesting/litesvm) for multi-language testing
  • Read [Testing Overviewtesting/overview) for testing strategies
  • Check out Mollusk GitHub for more examples
  • Learn about [Compute Unitsreferences/compute-units) optimization