Mollusk is designed for Rust-only testing. For multi-language testing, see [LiteSVMtesting/litesvm).
Overview
Mollusk takes a minimalist approach to testing:- Program cache
- Transaction context
- Invoke context
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
CheckAPI 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:Basic Usage
Single Instruction Test
Here’s a simple test that processes one instruction:With Validation Checks
Mollusk provides aCheck 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:Cargo.toml:
Check API Reference
TheCheck enum provides several validation methods:
Advanced Configuration
Compute Budget
Feature Set
Sysvars
Testing Best Practices
- Test one instruction at a time - Keep tests focused and isolated
- Use descriptive test names - Make test failures easy to understand
- Set up minimal accounts - Only include accounts needed for the test
- Validate expected outcomes - Use
CheckAPI for comprehensive validation - Benchmark critical paths - Track compute units for expensive operations
- 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