Testing Guide
Testing Guide
Unit · Integration · Fuzz · Formal Verification · Load · Chaos · CI/CD · Module-Aware
Complete testing methodology for all five on-chain programs deployed by Groovy Company, Inc. across the three production modules — Equities (Module 1), Real Estate (Module 2), and CORECM — Carbon Ore, Rare Earth, and Critical Minerals (Module 3). This guide defines test strategy, coverage targets, execution procedures, fixture data, and CI/CD pipeline configuration. Required reading for contributors, auditors verifying test coverage, and the QA team executing pre-deployment validation.
The same test apparatus exercises all three modules. Module-specific test scenarios (Module 2 NAV-deviation enforcement, Module 3 federal-action freeze coordination) sit alongside cross-module scenarios (custody, holding period across Reg D / Reg S / Reg CF, OFAC, AML).
Table of Contents
Testing Strategy
Environment Setup
Unit Tests
Integration Tests
Fuzz Testing
Formal Verification (Certora)
Load Testing
Chaos Testing
Test Fixtures and Data
Coverage Requirements
CI/CD Pipeline
Pre-Deployment Checklist
Troubleshooting
1. Testing Strategy
1.1 Testing Pyramid
1.2 Coverage Targets
Unit
cargo test
100% control logic; 100% module-aware extensions
<60 seconds
Every commit
Integration
anchor test
All 42 controls E2E across Module 1, 2, and 3
<5 minutes
Every PR
Fuzz
cargo fuzz
Transfer Hook, CPMM, NAV oracle, Classification oracle
100,000+ runs
Weekly + pre-release
Formal verification
Certora Prover
6 invariants — E.4 covers module-aware extensions
~30 minutes
Pre-release
Load
Custom generator
600 TPS sustained across all modules
~15 minutes
Pre-release
Chaos
Failure injection
All fail-safe paths across 7 oracle categories
~30 minutes
Monthly + pre-release
1.3 What Gets Tested Where
Transfer Hook (42 controls)
Each control individually
Full 42-control execution per module
Random inputs
E.1, E.2, E.4, E.6
600 TPS with hooks
Oracle failure
All modules
CPMM arithmetic
calculate_output_amount
Buy/sell/fee flows
u128 overflow
E.5 (fee accuracy)
Concurrent swaps
—
All modules
Global Pool
Deposit function
Fee routing across modules
Extraction attempts
E.3 (non-extract)
Fee accumulation
—
All modules
Custody Oracle
Signature verification
Attestation flow
Malformed payloads
E.1, E.2
Per-block update
Relay killed
All modules
Circuit Breakers
Trigger/reset logic
Price impact + volume halt + NAV deviation + Classification stale
Boundary values
E.6 (correctness)
Sustained load
TWAP stale
All modules + M2 + M3
Holding Period
Timer logic across Reg D / Reg S / Reg CF
Lock/unlock lifecycle per regime
Timestamp edge cases
—
—
—
All modules
Governance
Proposal/vote/execute
Timelock enforcement; module-specific param adjustments
—
—
—
—
All modules
NAV Oracle
Signature verification + deviation math
Module 2 NAV-deviation lifecycle
Malformed appraisal payloads
E.4 (covered)
NAV updates per cycle
Relay killed; deviation injection
Module 2
Classification Oracle
Federal-action state transitions
Module 3 federal-action freeze E2E
Malformed federal-action payloads
E.4 (covered)
Federal-action storms
Relay killed; federal-action injection
Module 3
2. Environment Setup
2.1 Test Dependencies
2.2 Local Test Validator
2.3 Test Configuration
3. Unit Tests
3.1 Running Unit Tests
3.2 Transfer Hook Unit Tests
Each of the 42 controls has dedicated unit tests covering pass, fail, and boundary conditions. Module-aware extensions (Module 2 CB-21 NAV-deviation; Module 3 REG-42 federal-action) have additional dedicated test modules.
Test Pattern (Wallet Limit, Cross-Module)
Module 2 — NAV-Deviation Unit Tests
Module 3 — Federal-Action Freeze Unit Tests
Control Test Matrix (Module-Aware)
CV-01 (Custody)
Supply = balance
Supply > balance
Supply = balance + 1
Asset class per module
CV-02 (Oracle fresh)
Slot age = 0
Slot age = 5
Slot age = 1
All modules
SC-30 (OFAC sender)
Wallet not on SDN
Wallet on SDN
—
All modules
IV-09 (AML)
Score = 25
Score = 75
Score = 30, 31, 70, 71
Module 3 enhanced KYC depth
PL-16 (Wallet limit)
4.50% post (M1/M3)
5.01% post (M1/M3)
4.99% exactly
Module 2 cap up to 9.99%
CB-20 (Price halt)
8% move in 5 min
12% move in 5 min
10.0% exactly
All modules
CB-21 (Price impact)
1.5% impact
3.0% impact
2.0% exactly
Module 2: NAV deviation also checked
HP-24 (Holding period)
Reg D 7 mo elapsed
Reg D 5 mo elapsed
Reg D 6 mo exactly
Reg D / Reg S / Reg CF variants
REG-42 (Reg freeze)
Not paused
Paused by authority
—
Module 3: federal-action variant
3.3 CPMM Arithmetic Unit Tests
3.4 Holding Period Unit Tests — Reg D / Reg S / Reg CF
4. Integration Tests
4.1 Running Integration Tests
4.2 Full Lifecycle Test — Module 1 (Equities)
The most important integration test for Module 1 — verifies the complete ST22 token lifecycle from mint to secondary trade.
4.3 Module 2 — Real Estate Lifecycle Test
4.4 Module 3 — CORECM Federal-Action Lifecycle Test
4.5 Circuit Breaker Integration Tests (Cross-Module)
4.6 Key Integration Test Scenarios
Module 1 happy path: full lifecycle
e2e/full-lifecycle-module1.ts
All 42
Mint → transfer → hold → trade
M1
Module 2 happy path: NAV lifecycle
e2e/full-lifecycle-module2.ts
All 42 + NAV ext
Mint → NAV init → trade → reappraisal
M2
Module 3 happy path: federal-action lifecycle
e2e/full-lifecycle-module3.ts
All 42 + federal-action ext
Mint → classification init → freeze → resume
M3
Custody discrepancy halt
e2e/full-lifecycle-module1.ts
CV-01 to CV-06
Error 6001, all transfers halt
All
OFAC sender blocked
transfer-hook.ts
SC-30 to SC-32
Error 6003
All
AML high risk rejected
transfer-hook.ts
IV-09
Error 6006
All
Wallet limit M1 enforced (4.99%)
transfer-hook.ts
PL-16
Error 6020 at 5.00%
M1
Wallet limit M2 enforced (9.99%)
transfer-hook.ts
PL-16
Error 6020 at 10.00%
M2
Price impact blocked
e2e/circuit-breaker.ts
CB-21
Error 6021 at >2%
All
Volume halt triggered
e2e/circuit-breaker.ts
CB-23
Error 6037 at >30% daily
All
NAV deviation circuit breaker
e2e/full-lifecycle-module2.ts
CB-21 NAV variant
Error 6021 (NAV)
M2
NAV stale pause
e2e/full-lifecycle-module2.ts
CB-21 NAV stale
Error 6021 (stale)
M2
Federal-action freeze
e2e/full-lifecycle-module3.ts
REG-42 federal variant
Error 6042 (federal)
M3
Holding period: Reg D locked
transfer-hook.ts
HP-24
Error 6024 within 6 months
All
Holding period: Reg D unlocked
transfer-hook.ts
HP-24
Success after 6 months
All
Holding period: Reg S 12mo
transfer-hook.ts
HP-24
Error 6024 within 12 months
All
Holding period: Reg CF 12mo
transfer-hook.ts
HP-24
Error 6024 within 12 months
All
Regulatory freeze (cross-module)
governance.ts
REG-42
Error 6042, transfers halt
All
Fee distribution accuracy
amm.ts
—
5% total, 0.44% to Global Pool
All
LP burn verification
liquidity-pool.ts
—
LP supply = 0, no withdrawal possible
All
Global Pool only grows
liquidity-pool.ts
—
Balance increases with every trade
All
Governance timelock
governance.ts
RK-41
Proposal blocked before 48h
All
5. Fuzz Testing
5.1 Setup
5.2 Transfer Hook Fuzz Target
5.3 CPMM Arithmetic Fuzz Target
5.4 NAV Deviation Fuzz Target (Module 2)
5.5 Classification Oracle Fuzz Target (Module 3)
5.6 Running Fuzz Tests
5.7 Fuzz Coverage Targets
check_wallet_limit
u64 × 3 + u16
100,000
1,000,000
All
calculate_output_amount
u64 × 3 + u16
100,000
1,000,000
All
enforce_holding_period
i64 × 3 + bool + regime
100,000
1,000,000
All (Reg D / Reg S / Reg CF)
verify_custody_oracle
u64 × 4 + bool × 2
50,000
500,000
All
check_price_impact
u64 × 3 + u16
50,000
500,000
All
compute_nav_deviation_bps
u128 × 2 + u16
50,000
500,000
Module 2
check_classification_freshness
i64 × 2 + bool
50,000
500,000
Module 3
6. Formal Verification (Certora)
6.1 Six Invariants
E.1
No unauthorized minting
no_unauthorized_minting.spec
transfer_hook
All modules
E.2
Custody ratio maintained
custody_ratio.spec
transfer_hook
All modules
E.3
Global Pool non-extractable
pool_non_extractability.spec
liquidity_pool
All modules — single shared pool
E.4
Transfer Hook completeness
hook_completeness.spec
transfer_hook
All modules — verifies module-aware extensions cannot be removed
E.5
Fee accuracy (≤ 1 lamport)
fee_accuracy.spec
amm
All modules
E.6
Circuit breaker correctness
circuit_breaker.spec
transfer_hook
All modules; covers Module 2 NAV-deviation variant
E.4 covers the module-aware extensions explicitly — any program upgrade that would remove the Module 2 NAV-deviation enforcement or the Module 3 federal-action freeze coordination fails E.4 verification. There are no separate per-module invariants.
6.2 Running Certora
6.3 Verification Requirement
All 6 invariants must PASS before any deployment (devnet or mainnet). A FAIL on any invariant is a release blocker — no exceptions. This applies regardless of whether the deployment includes only Module 1 mints, only Module 2 mints, only Module 3 mints, or any combination — the same six invariants protect every module.
7. Load Testing
7.1 Target
600 TPS sustained with full 42-control Transfer Hook verification on every transaction. The target applies to combined load across modules; module-specific load tests verify each module independently.
7.2 Load Generator
7.3 Metrics Collected
Sustained TPS
≥ 600
< 500
All modules combined
p50 latency
< 500 ms
> 800 ms
All
p99 latency
< 2000 ms
> 5000 ms
All
Error rate
< 0.1%
> 1%
All
CU per swap (M1)
< 800,000
> 1,000,000
M1
CU per swap (M2)
< 820,000
> 1,000,000
M2
CU per swap (M3)
< 830,000
> 1,000,000
M3
Custody oracle update latency
< 200 ms
> 500 ms
All
NAV oracle update latency
< 1 s
> 5 s
M2
Classification oracle federal-action SLA
< 60 min
> 60 min
M3
8. Chaos Testing
8.1 Failure Injection Scenarios
Kill custody relay
pm2 stop custody-relay
Transfers halt after 1 slot. Error 6002.
All
Empire API 500
Mock error response
Relay retries 3x, then stale. Halt.
All
Inject custody discrepancy
Write custodied_balance ≠ supply
Error 6001. P0 alert.
All
Kill OFAC indexer
pm2 stop ofac-indexer
Cache <24h. Halt >48h.
All
Both AML providers timeout
Network partition
Cache <6h. New wallets blocked.
All
Pyth feed stale
Mock stale data
Breaker disabled >5 min. P2.
All
RPC primary down
Block Helius endpoint
Failover to Triton. P2.
All
Kill NAV relay
pm2 stop nav-relay
Affected M2 mints pause when staleness exceeded
M2
NAV deviation injection
Inject NAV value triggering deviation
Affected mint paused. Error 6021. P1.
M2
Kill Classification relay
pm2 stop classification-relay
M3 mints enter enhanced review on staleness. P2.
M3
Federal-action injection
Inject federal-action event
P0 incident. Control 42 freeze within 60 min.
M3
8.2 Running Chaos Tests
9. Test Fixtures and Data
9.1 Standard Test Accounts
9.2 SecurityConfig Fixtures (Per Module)
10. Coverage Requirements
10.1 Generating Coverage
10.2 Minimum Coverage
Transfer Hook control logic (all 42)
100%
Yes — release blocker
Module 2 NAV-deviation extension
100%
Yes — release blocker
Module 3 federal-action freeze extension
100%
Yes — release blocker
CPMM arithmetic
100%
Yes — release blocker
Error code paths
100%
Yes — release blocker
Cross-module oracle verification
95%+
Yes — release blocker
Module 2 NAV oracle verification
95%+
Yes — release blocker
Module 3 Classification oracle verification
95%+
Yes — release blocker
Governance proposal logic (incl. module-specific param adjustments)
90%+
No
SDK TypeScript
80%+
No
11. CI/CD Pipeline
11.1 GitHub Actions Workflow
11.2 PR Merge Gates
Unit tests pass
Yes
Yes
Integration tests pass — all three modules
Yes
Yes
Coverage ≥ 95%
Yes
Yes
cargo fmt clean
Yes
Yes
cargo clippy zero warnings
Yes
Yes
Code review (1+ approver)
Yes
Yes
Fuzz tests (main branch only)
Main only
Yes for release
Certora (pre-release only)
Release only
Yes for release
12. Pre-Deployment Checklist
13. Troubleshooting
anchor test timeout
Validator slow to start
Increase startup_wait in Anchor.toml
cargo test linker errors
Missing system deps
sudo apt install libudev-dev pkg-config libssl-dev
Fuzz target won't compile
Nightly required
rustup default nightly for fuzz directory
Coverage below threshold
Untested error paths
Add explicit error-path unit tests
Integration test: AccountNotFound
PDAs not initialized
Check test setup initializes all required accounts including module-specific PDAs (NAVOracle for M2, ClassificationOracle for M3)
Module 2 test: NAV deviation not triggering
Pool price helper not reaching threshold
Use forcePoolPrice helper to set deterministic deviation
Module 3 test: federal-action freeze not applying
Classification oracle not initialized before federal-action injection
Initialize ClassificationOracle with federalActionFreezeEnabled: true before injecting
Reg CF test: jurisdiction not recognized
Older Anchor IDL cached
anchor build to regenerate IDL with Jurisdiction::RegCF variant
Load test: TransactionExpired
Localnet too slow
Use devnet for load tests, or increase validator slots
Related Documentation
Smart Contract Reference — Program instructions, error codes, module-aware program behavior.
Deployment Guide — Pre-deployment checklist references this guide; module-specific oracle initialization.
Security Model — Formal verification invariants; module-specific threat surfaces.
Oracle Integration Guide — Custody, OFAC, AML, TWAP, EDGAR (M1), NAV (M2), Classification (M3) relay architecture and chaos test scenarios.
Transfer Hook Reference — Standalone reference for the 42 controls including module-aware extensions.
Incident Response Playbook — P0 through P3 runbooks; Module 3 federal-action freeze runbook.
RWA Tokens · Testing Guide · Groovy Company, Inc.
Last updated
Was this helpful?