Track which Omnipair program instructions are tested by litesvm test suite.
# Run tests with coverage report
yarn test-coverageOutput shows:
π INSTRUCTION COVERAGE REPORT
ββββββββββββββββββββββββββββββββ
β
Covered Instructions: 2/16 (12.50%)
β initFutarchyAuthority [1 test(s)]
ββ should calculate correct PDA
β viewPairData [1 test(s)]
β Untested Instructions: 14/16
β swap
β addCollateral
β borrow
... (14 more)
Coverage: 12.50% | Tests: 2/16
ββββββββββββββββββββββββββββββββ
The coverage tracker monitors which Omnipair instructions tests exercise:
import { trackInstruction, getCoverageReport } from "./utils/instruction-coverage.js";it("should execute a swap", async () => {
trackInstruction("swap", "should execute a swap");
// Your test code
const result = await program.methods.swap(...).rpc();
});Reports are displayed automatically after tests run, showing:
- β Covered instructions with test counts
- β Untested instructions
- Overall percentage coverage
The tracker monitors all 16 Omnipair instructions:
| Instruction | Category | Status |
|---|---|---|
viewPairData |
View | - |
viewUserPositionData |
View | - |
initFutarchyAuthority |
Governance | - |
updateFutarchyAuthority |
Governance | - |
claimProtocolFees |
Governance | - |
distributeTokens |
Governance | - |
initialize |
Liquidity | - |
addLiquidity |
Liquidity | - |
removeLiquidity |
Liquidity | - |
swap |
Swap | - |
addCollateral |
Lending | - |
removeCollateral |
Lending | - |
borrow |
Lending | - |
repay |
Lending | - |
liquidate |
Lending | - |
flashloan |
Lending | - |
it("should swap tokens", async () => {
trackInstruction("swap");
// Test swap instruction
});it("should handle slippage", async () => {
trackInstruction("swap", "should handle slippage");
// Test with explicit slippage checking
});it("should execute a complex transaction", async () => {
trackInstruction("addCollateral", "complex transaction");
trackInstruction("borrow", "complex transaction");
// Test both instructions together
});Update the ALL_INSTRUCTIONS array in tests/utils/instruction-coverage.ts:
const ALL_INSTRUCTIONS = [
"viewPairData",
// ... existing instructions
"myNewInstruction",
];Add coverage tracking to every test file:
import { trackInstruction, getCoverageReport } from "./utils/instruction-coverage.js";describe("My Feature", () => {
it("should do something", async () => {
trackInstruction("myInstruction", "should do something");
// test
});
});after(() => {
getCoverageReport();
});// Track an instruction
trackInstruction("swap");
// Track with test name for better reporting
trackInstruction("swap", "should handle slippage");// Display formatted coverage report
getCoverageReport();
// Returns coverage data
// {
// covered: 5,
// total: 16,
// percentage: "31.25",
// testedInstructions: ["swap", "addCollateral", ...],
// untestedInstructions: ["borrow", "repay", ...]
// }// Get coverage as object (without printing)
const data = getCoverageData();
console.log(`Coverage: ${data.percentage}%`);// Clear all tracking (useful between test suites)
resetCoverage(); Omnipair Program - Swap Tests
β Tested: swap
β should swap tokens with exact amount
Omnipair Program - Lending Tests
β Tested: addCollateral
β Tested: borrow
β Tested: repay
β should add collateral and borrow
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π INSTRUCTION COVERAGE REPORT
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Covered Instructions: 4/16 (25.00%)
β swap [1 test(s)]
ββ should swap tokens with exact amount
β addCollateral [1 test(s)]
ββ should add collateral and borrow
β borrow [1 test(s)]
ββ should add collateral and borrow
β repay [1 test(s)]
ββ should add collateral and borrow
β Untested Instructions: 12/16
β viewPairData
β viewUserPositionData
β initialize
... (9 more)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Coverage: 25.00% | Tests: 4/16
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- β 2/16 instructions tested (12.50%)
- Identify untested instructions from the report
- Create tests for high-priority instructions:
initialize- Core liquidity pool setupswap- Core DEX functionalityaddCollateral- Core lending functionality
- Re-run
yarn test-coverageto see improvement
- Level 1: 25% coverage (4/16 instructions)
- Level 2: 50% coverage (8/16 instructions)
- Level 3: 75% coverage (12/16 instructions)
- Level 4: 100% coverage (16/16 instructions)
# Run tests with coverage
yarn test-coverage
# Run specific test file with coverage
yarn test-litesvm -- tests/swap.test.ts
# Run with grep pattern
yarn test-litesvm -- --grep "swap"- Coverage reports show after each test file runs
- Each test file displays its own coverage report
- Total coverage accumulates across all test files
- Use
trackInstruction()in every test that exercises an instruction - Include test names for better debugging and tracking
tests/utils/instruction-coverage.ts- Implementationtests/basic.test.ts- Example usagetests/futarchy.test.ts- Example usagetests/README.md- General testing guide
Last Updated: October 2024
Tool: Custom instruction tracker
Coverage Type: Instruction coverage
Supported Instructions: 16 Omnipair program instructions