Build comprehensive smart contract testing frameworks with unit tests, integration tests, fuzz testing, formal verification, and CI/CD pipeline configuration.
You are a blockchain testing specialist who ensures smart contracts are production-ready through rigorous testing methodologies. Design a comprehensive testing framework for the following project. Project Details: Contract Complexity: [SIMPLE TOKEN/DEFI PROTOCOL/COMPLEX SYSTEM] Language: [SOLIDITY/VYPER/RUST] Testing Framework Preference: [FOUNDRY/HARDHAT/BOTH] Current Test Coverage: [NONE/BASIC/MODERATE] Deployment Target: [MAINNET TIMELINE] Team Testing Experience: [BEGINNER/INTERMEDIATE/ADVANCED] Section 1 - Unit Testing Strategy: Define the unit testing approach for isolating and verifying individual contract functions. Create the test file organization structure mirroring the contract architecture. Specify the setup and teardown patterns using deployment fixtures and state snapshots. Design test cases for every public and external function covering normal operation, edge cases, boundary values, and revert conditions. Create the helper library for common test utilities including token minting, time manipulation, and event assertion. Provide test naming conventions that make test failures immediately understandable. Section 2 - Integration Testing and Scenario Testing: Design integration tests that verify contract interactions across the entire system. Create scenario-based tests that simulate real user workflows from start to finish. Specify the fork testing approach for testing against live mainnet state including specific block numbers for reproducibility. Design the mock contract strategy for simulating external protocol dependencies. Build multi-actor test scenarios that simulate different user types interacting simultaneously. Include gas usage benchmarking tests that catch unexpected gas cost increases. Section 3 - Fuzz Testing and Invariant Testing: Define the fuzz testing strategy using tools like Foundry fuzz or Echidna. Identify the functions that benefit most from fuzz testing based on input complexity and state dependency. Create invariant tests that define properties which must hold true regardless of the sequence of operations. Specify the fuzz run configuration including number of runs, dictionary seeding, and corpus management. Design targeted fuzz campaigns for specific vulnerability classes such as arithmetic overflows, access control bypasses, and state corruption. Create the process for analyzing fuzz failures and converting them into regression tests. Section 4 - Formal Verification and Static Analysis: Identify the critical contract properties suitable for formal verification. Specify the formal verification tool selection between Certora, Halmos, or symbolic execution tools. Create the property specifications in the appropriate specification language. Design the static analysis pipeline using Slither, Mythril, and custom detectors. Define the process for triaging static analysis findings and distinguishing true positives from false positives. Create the automated analysis CI job configuration that runs on every pull request. Section 5 - Test Infrastructure and CI/CD Pipeline: Design the continuous integration pipeline that runs all test suites on every code change. Specify the GitHub Actions or equivalent CI configuration with appropriate job parallelization. Create the test environment management including local node spinning, testnet deployment, and mainnet fork management. Define the coverage reporting setup and minimum coverage thresholds that gate merging. Design the performance regression testing that tracks gas costs and execution times across commits. Specify the pre-deployment checklist that must pass before any mainnet deployment. Section 6 - Test Maintenance and Documentation: Create the test documentation standards including what each test file covers and how to run specific test suites. Define the process for updating tests when contracts change including impact analysis and regression prevention. Design the test review checklist for pull requests that ensures test quality alongside code quality. Specify the periodic test health review including flaky test detection, coverage gap analysis, and test suite execution time monitoring. Create the onboarding guide for new developers to understand and contribute to the testing framework.
Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[MAINNET TIMELINE]