Test Suite
PRISM ships a Mocha + Chai integration suite that exercises every instruction end-to-end againstsolana-test-validator. Tests are not a checkbox — they are the primary defense against silent capital corruption in a multi-tranche credit system.
The most recent localnet run is 25 passing in ~34 seconds, plus Rust unit tests for the Q64.64 math module.
Coverage Summary
| Suite | Tests | Focus | File |
|---|---|---|---|
prism-core | 14 | Vault lifecycle, deposits, yield waterfall, default cascade, withdraw | tests/prism-core.ts |
prism-amm | 6 | Pool initialization, add/remove liquidity, swap pricing, slippage | tests/prism-amm.ts |
ika-collateral | 5 | Attach → verify (real ed25519 precompile) → disburse → repay → release / liquidate | tests/ika-collateral.ts |
| Q64.64 math | Embedded | NAV, deposit shares, withdraw payout, edge cases | programs/prism-core/src/math/q.rs |
Run Locally
Install the toolchain
Required versions:
- Anchor 0.30.1
- Solana CLI 1.18.x
- Node 20+
- Yarn 1.22+
Start a clean local validator
--reset flag wipes all prior state. Leave this running in a separate terminal. anchor test will start its own validator if you skip this step, but a long-lived validator is faster across iterations.Run the full suite
anchor test builds, deploys, and runs Mocha against a fresh validator. For iterative work, skip the rebuild:Run a single file or test
-t 1000000 timeout is generous — Solana RPC calls and program loads can be slow on cold starts.What’s Validated
The Four Invariants
Every test asserts these four invariants on every state transition:| Invariant | Check | Why it matters |
|---|---|---|
| Capital preservation | Σreserves + Σloans + Σloss_bucket == Σdeposits + Σinterest | No phantom USDC created or destroyed across the system |
| NAV consistency | nav_per_share_q == (total_assets × Q64_ONE) / total_supply | Off-chain NAV calculation always matches on-chain state |
| Waterfall integrity | Prime fills to its target before any yield reaches Core | Junior tranches cannot front-run senior payouts |
| Risk priority | Alpha and Core deplete to zero before any loss touches Prime | Subordination is enforced — Prime protection is real |
prism-core Test Cases
prism-amm Test Cases
ika-collateral Test Cases
verify_ika_collateral.rs and the TypeScript helper buildAttestationMessage produce byte-identical output, proven by the suite passing.
Telemetry Layers
Every test prints a structured trace so you can audit capital flow without reading transaction logs:Layer 1: Narrative
Layer 2: PDAs and parameters
Layer 3: Balance deltas
Debugging Failed Tests
| Failure | Likely cause | Fix |
|---|---|---|
Stack overflow (os error 2) | Anchor account too large for stack | Wrap in Box<Account<...>> |
ConstraintSeeds | PDA seeds in test don’t match Rust | Re-derive using SDK helpers, never hand-hash |
ConstraintHasOne | Wrong signer for an admin instruction | Check config.admin matches your test’s admin keypair |
BorrowerMismatch | Wrong borrower for accrue_yield or repay_loan | Use the exact pubkey stored on the loan |
EmptyTrancheNav | Withdraw or deposit on a tranche before init | Initialize tranche first |
OracleSignatureInvalid | Test oracle key doesn’t match the registered key | Re-attach with the correct key |
CI Integration
Run the suite in GitHub Actions or any CI provider:solana-test-validator and tears it down on exit — no extra orchestration needed.
Adding New Tests
The harness exposes helpers intests/_helpers.ts (or inline) for common setup: airdrop, mint USDC, derive PDAs, compute expected NAVs. Pattern for a new test:
§4.3 for yield, §4.5 for default cascade) — math correctness is the highest-risk failure mode.
Devnet Smoke Test
For an end-to-end sanity check against the deployed devnet binary, walk the manual test plan indocs/ika-frontend-test-plan.md. It exercises:
- Loan application via
localStoragequeue - On-chain origination through admin panel
- IKA collateral attach (Pending status)
- Verify with the local test oracle (Pending → Locked)
- Disburse against locked collateral
- Repay loan in full (state →
Repaid) - Release collateral (Locked → Released)
What’s Next
Connect to Devnet
Wire the SDK to a Solana RPC.
Deployed Addresses
Program IDs, PDAs, and tokens.
