Skip to content
Development
Command

/test-rust

Run Rust tests for Solana programs and backend services

From plugin
solana-ai-kit
10130 skills15 agents30 commands7 MCP
Install
> /plugin marketplace add solanabr/solana-ai-kit
> /plugin install solana-ai-kit@stbr

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/test-rust

Context preview

What this command does when you run it.

Run Rust tests for Solana programs and backend services

Command definition

test-rust.md
description: "Run Rust tests for Solana programs and backend services"

You are running Rust tests. This command covers Solana program testing (Mollusk, LiteSVM, Surfpool, Trident) and backend service testing.

Related Skills

  • [testing.md](../skills/ext/solana-dev/skill/references/testing.md) - Testing strategy details
  • [security.md](../skills/ext/solana-dev/skill/references/security.md) - Security testing checklist
  • [programs/anchor.md](../skills/ext/solana-dev/skill/references/programs/anchor.md) - Anchor test patterns
  • [programs/pinocchio.md](../skills/ext/solana-dev/skill/references/programs/pinocchio.md) - Pinocchio test patterns

Step 1: Identify Project Type

echo "๐Ÿ” Detecting project type..."

if [ -f "Anchor.toml" ]; then
    echo "๐Ÿ“ฆ Anchor project detected"
    PROJECT_TYPE="anchor"
elif grep -q "pinocchio" Cargo.toml 2>/dev/null; then
    echo "๐ŸŽฏ Pinocchio program detected"
    PROJECT_TYPE="pinocchio"
elif grep -q "solana-program" Cargo.toml 2>/dev/null; then
    echo "โš™๏ธ  Solana native program detected"
    PROJECT_TYPE="solana"
elif grep -q "axum\|tokio" Cargo.toml 2>/dev/null; then
    echo "๐ŸŒ Rust backend service detected"
    PROJECT_TYPE="backend"
else
    echo "๐Ÿฆ€ Standard Rust project detected"
    PROJECT_TYPE="standard"
fi

---

Solana Program Testing

Testing Pyramid

1. **Unit tests (fastest)**: Mollusk - individual instruction tests 2. **Integration tests (fast)**: LiteSVM - multi-instruction flows 3. **Realistic state tests**: Surfpool - mainnet/devnet state locally 4. **Fuzz tests**: Trident - edge case discovery

Mollusk Unit Tests

Fast, isolated tests for individual instructions:

echo "๐Ÿš Running Mollusk unit tests..."
cargo test --lib -- --nocapture
#[cfg(test)]
mod tests {
    use mollusk_svm::Mollusk;
    use solana_sdk::{account::Account, pubkey::Pubkey, instruction::Instruction};

    #[test]
    fn test_initialize() {
        let program_id = Pubkey::new_unique();
        let mollusk = Mollusk::new(&program_id, "target/deploy/my_program.so");

        // Setup accounts
        let user = Pubkey::new_unique();
        let accounts = vec![
            (user, Account::new(1_000_000_000, 0, &program_id)),
        ];

        // Create instruction
        let instruction = Instruction {
            program_id,
            accounts: vec![],
            data: vec![0], // Initialize discriminator
        };

        // Process and verify
        let result = mollusk.process_instruction(&instruction, &accounts);
        assert!(result.program_result.is_ok());

        // Check CU usage
        println!("CU consumed: {}", result.compute_units_consumed);
        assert!(result.compute_units_consumed < 50_000);
    }
}

LiteSVM Integration Tests

Multi-instruction flow testing:

echo "โšก Running LiteSVM integration tests..."
cargo test --test '*'
#[cfg(test)]
mod tests {
    use litesvm::LiteSVM;
    use solana_sdk::{signature::Keypair, signer::Signer, transaction::Transaction};

    #[test]
    fn test_full_deposit_withdraw_flow() {
        let mut svm = LiteSVM::new();

        // Add program
        let program_id = Pubkey::new_unique();
        svm.add_program(program_id, include_bytes!("../target/deploy/my_program.so"));

        // Create and fund user
        let user = Keypair::new();
        svm.airdrop(&user.pubkey(), 10_000_000_000).unwrap();

        // Build transaction
        let tx = Transaction::new_signed_with_payer(
            &[/* deposit instruction */],
            Some(&user.pubkey()),
            &[&user],
            svm.latest_blockhash(),
        );

        // Execute and verify
        let result = svm.send_transaction(tx);
        assert!(result.is_ok());
    }
}

Surfpool Integration Tests

Test against realistic mainnet/devnet state locally:

echo "๐Ÿ„ Running Surfpool integration tests..."

# Start local Surfnet (drop-in replacement for test-validator)
surfpool start --background

# Run tests against realistic state
cargo test --test integration

# Stop Surfnet
surfpool stop
// Surfpool enables:
// - Complex CPIs with mainnet programs (Jupiter 40+ accounts)
// - Time travel and block manipulation
// - Account cloning between environments

// Time travel to specific slot
await connection._rpcRequest('surfnet_timeTravel', [{
    absoluteSlot: 250000000
}]);

// Clone account from mainnet
await connection._rpcRequest('surfnet_cloneProgramAccount', [{
    source: mainnetProgramId.toString(),
    destination: localProgramId.toString(),
    account: accountPubkey.toString(),
}]);

Trident Fuzz Tests

Property-based fuzzing for edge cases:

echo "๐Ÿ”ฑ Running Trident fuzz tests..."

# Initialize (first time only)
if [ ! -d "trident-tests" ]; then
    trident init
fi

cd trident-tests

# Run fuzz tests (modern syntax)
trident fuzz run --timeout 300

# Check for crashes
if [ -d "hfuzz_workspace" ]; then
    echo "๐Ÿ“‹ Checking for crash reports..."
    find hfuzz_workspace -name "crashes" -type d -exec ls -la {} \; 2>/dev/null
fi

cd ..

Complete Solana Test Suite

echo "๐Ÿงช Running complete Solana test suite..."

# 1. Build program
if [ -f "Anchor.toml" ]; then
    anchor build
else
    cargo build-sbf
fi

# 2. Unit tests (Mollusk)
echo "๐Ÿ“ Unit tests..."
cargo test --lib

# 3. Integration tests (LiteSVM)
echo "๐Ÿ“ Integration tests..."
cargo test --test '*'

# 4. Fuzz tests (Trident) - quick run
if [ -d "trident-tests" ]; then
    echo "๐Ÿ“ Fuzz tests..."
    cd trident-tests && trident fuzz run --timeout 60 && cd ..
fi

echo "โœ… All Solana tests complete!"

---

Backend Service Testing

Axum/Tokio Service Tests

echo "๐ŸŒ Running backend service tests..."

# Run all tests
cargo test

# Run with test database
if [ -f ".env.test" ]; then
    export $(cat .env.test | xargs)
fi

# Integration tests (serial to avoid DB conflicts)
cargo test --test '*' -- --test-threads=1
`
Read more
Ships withsolana-ai-kit

Production-ready Claude Code configuration for full-stack Solana development. Combines best practices from multiple sources into an agent-optimized, token-efficient config you can install and adapt to your specific project.

Get the whole plugin

Other commands on solana-ai-kit.