Testing Guide
Overview
This guide covers testing strategies for the Gelap shielded pool system, including unit tests, integration tests, and security testing.
Test Structure
test/
├── Deposit.t.sol # Deposit function tests
├── Transact.t.sol # Private transaction tests
├── Withdraw.t.sol # Withdrawal tests
├── MerkleTree.t.sol # Merkle tree logic tests (TODO)
├── Integration.t.sol # End-to-end tests (TODO)
└── mocks/
└── MockSP1Verifier.sol # Mock verifier for testingRunning Tests
Run All Tests
forge testRun Specific Test File
forge test --match-path test/Deposit.t.solRun Specific Test Function
Run with Verbosity
Run with Gas Report
Unit Tests
Deposit Tests
File: test/Deposit.t.sol
Tests cover:
✅ Merkle root updates after deposit
✅ Leaf index incrementation
✅ Token transfers
✅ Event emission
✅ Correct leaf storage
Run:
Expected Output:
Transaction Tests
File: test/Transact.t.sol
Tests cover:
✅ Merkle root updates
✅ Nullifier tracking
✅ Double-spend prevention
✅ Event emission for commitments
Run:
Withdrawal Tests
File: test/Withdraw.t.sol
Tests cover:
✅ Successful withdrawals
✅ Token transfers to receiver
✅ Double-spend prevention
✅ Receiver mismatch protection
Run:
Integration Tests
End-to-End Flow Test
Create test/Integration.t.sol:
Run:
Fuzz Testing
Deposit Fuzz Test
Run:
Invariant Testing
Invariant: Total Supply Conservation
Run:
Gas Benchmarking
Create Gas Report
Optimize Gas Usage
Compare gas costs before and after optimization:
Coverage Analysis
Generate Coverage Report
Detailed Coverage
Open coverage/index.html in browser.
Security Testing
Static Analysis with Slither
Mythril Analysis
Aderyn Analysis
Continuous Integration
GitHub Actions Workflow
Create .github/workflows/test.yml:
Test Checklist
Before deployment:
Common Test Patterns
Expect Revert
Expect Event
Time Manipulation
Prank (Impersonate)
Troubleshooting
Test Fails with "Out of Gas"
Mock Verifier Not Working
Check that MockSP1Verifier implements ISP1Verifier correctly.
Events Not Emitted
Use -vvvv to see detailed logs:
Next Steps
Add more edge case tests
Implement property-based testing
Add stress tests
Test with real SP1 proofs
Perform security audit
Last updated