audit-infra
Infrastructure-first security audit โ secrets, supply chain, CI/CD, LLM/skill security, OWASP, STRIDE. Complements /audit-solana (program-level)
Run Rust tests for Solana programs and backend services
> /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.
/test-rustContext preview
What this command does when you run it.
Run Rust tests for Solana programs and backend services
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.
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---
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
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);
}
}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());
}
}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(),
}]);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 ..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!"---
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
`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.
Repo: solanabr/solana-ai-kit
Infrastructure-first security audit โ secrets, supply chain, CI/CD, LLM/skill security, OWASP, STRIDE. Complements /audit-solana (program-level)
Benchmark CU usage and compare against baseline for regression detection