Goal: Write reliable tests and iterate quickly.

Cover: Anchor TS tests (primary), fixtures, deterministic keys, CI basics. (Rust solana-program-test optional/advanced note below)

Activity: Unit + integration tests for your Anchor program; CI script to run them.

Takeaway: “I can prove behavior and prevent regressions.”


1) Module overview

We standardize on Anchor TypeScript tests running against localnet for fast, production-like feedback. You’ll learn fixtures, deterministic keys, clean isolation between tests, and set up a minimal CI.

Optional/advanced: Rust solana-program-test can validate low-level logic, but it’s currently marked deprecated in docs; treat it as extra credit rather than your primary path.


2) Plain‑English explainer


3) Anchor TS test harness (copy/paste)

Deterministic key helper + airdrop (no BigInt):

import * as anchor from "@coral-xyz/anchor";
import { Keypair, PublicKey, LAMPORTS_PER_SOL, SystemProgram } from "@solana/web3.js";
import { createHash } from "crypto";

function seedKey(name: string) {
  const h = createHash("sha256").update(name).digest();
  return Keypair.fromSeed(h.subarray(0, 32)); // 32 bytes
}

describe("notes", () => {
  const provider = anchor.AnchorProvider.local(); // points to [localhost](<http://localhost>)
  anchor.setProvider(provider);
  const program = anchor.workspace.Notes as anchor.Program;

  const authority = seedKey("user-1");

  before(async () => {
    await provider.connection.requestAirdrop(authority.publicKey, 2 * LAMPORTS_PER_SOL);
  });

  it("create → update → close", async () => {
    const [notePda] = PublicKey.findProgramAddressSync(
      [Buffer.from("note"), authority.publicKey.toBuffer()],
      program.programId
    );

    await program.methods.create("hello").accounts({
      note: notePda,
      authority: authority.publicKey,
      systemProgram: SystemProgram.programId,
    }).signers([authority]).rpc();

    await program.methods.update("gm solana").accounts({
      note: notePda,
      authority: authority.publicKey,
    }).signers([authority]).rpc();

    await program.methods.close().accounts({
      note: notePda,
      authority: authority.publicKey,
    }).signers([authority]).rpc();
  });
});

Run locally:

solana-test-validator
solana config set -ul
anchor test