audit-infra
Infrastructure-first security audit โ secrets, supply chain, CI/CD, LLM/skill security, OWASP, STRIDE. Complements /audit-solana (program-level)
Run TypeScript tests for Solana frontends and Anchor programs
> /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-tsContext preview
What this command does when you run it.
Run TypeScript tests for Solana frontends and Anchor programs
description: "Run TypeScript tests for Solana frontends and Anchor programs"
You are running TypeScript tests. This command covers Anchor program tests, frontend component tests, and integration tests.
echo "๐ Detecting TypeScript test configuration..."
# Check for Anchor tests
if [ -f "Anchor.toml" ] && [ -d "tests" ]; then
echo "โ Anchor TypeScript tests detected"
fi
# Check for Vitest
if grep -q "vitest" package.json 2>/dev/null; then
echo "โก Vitest configured"
fi
# Check for Jest
if grep -q "jest" package.json 2>/dev/null; then
echo "๐ Jest configured"
fi
# Check for Playwright
if grep -q "playwright" package.json 2>/dev/null; then
echo "๐ญ Playwright E2E tests configured"
fi---
echo "โ Running Anchor TypeScript tests..." # Build first anchor build # Run all tests anchor test # Skip rebuild (faster iteration) anchor test --skip-build # Run specific test file anchor test tests/vault.ts # Run with logs RUST_LOG=debug anchor test
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { MyProgram } from "../target/types/my_program";
import { expect } from "chai";
describe("my_program", () => {
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const program = anchor.workspace.MyProgram as Program<MyProgram>;
it("initializes vault", async () => {
const [vaultPda] = anchor.web3.PublicKey.findProgramAddressSync(
[Buffer.from("vault"), provider.wallet.publicKey.toBuffer()],
program.programId
);
await program.methods
.initialize()
.accounts({
vault: vaultPda,
authority: provider.wallet.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();
const vault = await program.account.vault.fetch(vaultPda);
expect(vault.authority.toString()).to.equal(
provider.wallet.publicKey.toString()
);
});
it("deposits funds", async () => {
const [vaultPda] = anchor.web3.PublicKey.findProgramAddressSync(
[Buffer.from("vault"), provider.wallet.publicKey.toBuffer()],
program.programId
);
const depositAmount = new anchor.BN(1_000_000_000); // 1 SOL
await program.methods
.deposit(depositAmount)
.accounts({
vault: vaultPda,
authority: provider.wallet.publicKey,
})
.rpc();
const vault = await program.account.vault.fetch(vaultPda);
expect(vault.balance.toNumber()).to.equal(depositAmount.toNumber());
});
it("fails with insufficient funds", async () => {
const [vaultPda] = anchor.web3.PublicKey.findProgramAddressSync(
[Buffer.from("vault"), provider.wallet.publicKey.toBuffer()],
program.programId
);
try {
await program.methods
.withdraw(new anchor.BN(999_000_000_000)) // More than balance
.accounts({
vault: vaultPda,
authority: provider.wallet.publicKey,
})
.rpc();
expect.fail("Should have thrown");
} catch (err) {
expect(err.message).to.include("InsufficientFunds");
}
});
});For faster tests without validator:
npm install --save-dev litesvm
import { LiteSVM } from 'litesvm';
import { PublicKey, Transaction, Keypair } from '@solana/web3.js';
describe("litesvm tests", () => {
let svm: LiteSVM;
const programId = new PublicKey("YourProgramId...");
beforeAll(() => {
svm = new LiteSVM();
svm.addProgramFromFile(programId, "target/deploy/program.so");
});
it("processes instruction", () => {
const payer = Keypair.generate();
svm.airdrop(payer.publicKey, 1_000_000_000);
const tx = new Transaction();
tx.recentBlockhash = svm.latestBlockhash();
tx.add(/* your instruction */);
tx.sign(payer);
const result = svm.sendTransaction(tx);
expect(result.err).toBeNull();
});
});---
echo "โก Running Vitest tests..." npm run test # or npx vitest run
// components/__tests__/WalletButton.test.tsx
import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { WalletButton } from '../WalletButton';
// Mock wallet hooks
vi.mock('@solana/wallet-adapter-react', () => ({
useWallet: () => ({
connected: false,
connect: vi.fn(),
disconnect: vi.fn(),
publicKey: null,
}),
}));
describe('WalletButton', () => {
it('renders connect button when not connected', () => {
render(<WalletButton />);
expect(screen.getByText('Connect Wallet')).toBeInTheDocument();
});
it('calls connect on click', async () => {
const { useWallet } = await import('@solana/wallet-adapter-react');
const mockConnect = vi.fn();
vi.mocked(useWallet).mockReturnValue({
connected: false,
connect: mockConnect,
disconnect: vi.fn(),
publicKey: null,
});
render(<WalletButton />);
fireEvent.click(screen.getByText('Connect Wallet'));
expect(mockConnect).toHaveBeenCalled();
});
});// hooks/__tests__/useBalance.test.tsx
import { renderHook, waitFor } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { useBalance } from '../useBalance';
describe('useBalance', () => {
it('fetches balance for address', async () => {
const mockAddress = 'So11111111111111Production-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