Design a complete testing strategy for smart contracts covering unit tests, integration tests, fuzz testing, formal verification, and mainnet fork testing.
## ROLE
You are a smart contract QA engineer who has built testing frameworks for protocols managing billions in TVL. You believe that tests are the first line of defense against exploits and that untested code is broken code waiting to be found.
## OBJECTIVE
Create a testing strategy that provides maximum confidence in contract correctness while being practical to implement and maintain.
## TASK
**STEP 1: TESTING PYRAMID**
| Layer | Coverage Target | Tools | Purpose |
|-------|----------------|-------|---------|
| Unit Tests | >95% line coverage | Foundry/Hardhat | Individual function correctness |
| Integration Tests | All contract interactions | Foundry/Hardhat | Cross-contract behavior |
| Fuzz Tests | Critical paths | Foundry fuzz / Echidna | Edge case finding |
| Invariant Tests | Core invariants | Foundry invariant | Property verification |
| Fork Tests | Mainnet interactions | Foundry fork | Real-world integration |
| Formal Verification | Critical math | Certora / Halmos | Mathematical proof |
**STEP 2: UNIT TEST PLAN**
For each contract function, define:
| Function | Happy Path | Error Cases | Edge Cases | Gas Snapshot |
|----------|-----------|-------------|-----------|-------------|
| deposit() | Standard deposit | Zero amount, paused | Max uint, dust | Yes |
| withdraw() | Standard withdraw | Insufficient balance | Full withdraw | Yes |
| {function_1} | | | | |
| {function_2} | | | | |
**STEP 3: FUZZ TESTING STRATEGY**
- Identify all functions accepting user input
- Define input ranges and constraints
- Set minimum runs (10,000 for standard, 100,000 for critical)
- Define failure conditions (reverts, incorrect state, invariant breaks)
- Example invariant: totalSupply == sum of all balances
**STEP 4: INTEGRATION TEST SCENARIOS**
- Multi-user interaction sequences
- Time-dependent behavior (using vm.warp)
- Oracle price movement simulations
- Governance proposal execution flow
- Emergency pause and recovery procedures
- Upgrade and migration processes
**STEP 5: MAINNET FORK TESTING**
- Fork mainnet at specific block for reproducibility
- Test against real token contracts and AMMs
- Simulate whale-sized transactions
- Verify oracle integration with real price feeds
- Test gas costs under realistic network conditions
**STEP 6: CI/CD INTEGRATION**
- Run unit and integration tests on every PR
- Run fuzz tests nightly (extended runs)
- Gas snapshot comparison on every PR
- Coverage report generation and threshold enforcement
- Automated deployment to testnet on merge to main
## INPUT
**Contract Suite**: {contract_names}
**Testing Framework**: {framework}
**Current Test Coverage**: {current_coverage}
**Critical Invariants**: {invariants}
**Team Testing Experience**: {experience_level}Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
{function_1}{function_2}{contract_names}{framework}{current_coverage}{invariants}{experience_level}