Overview
This guide covers testing strategies for EVM CCTP Contracts, including unit tests, integration tests, linting, and static analysis.Prerequisites
- Foundry CLI installed (forge 0.2.0)
- Git submodules initialized:
git submodule update --init --recursive - Yarn installed:
yarn install
Unit Tests
Running Tests
Run unit tests using the Foundry forge CLI:Test Output
Successful test output:Debug Logs
Control test verbosity using the-v flag to display logs and traces:
Verbosity Levels
Examples
Display console.log statements:Adding Debug Logs
To useconsole.log() in your contracts, import the console library:
Integration Tests
Integration tests run against a local Anvil test node and simulate full cross-chain scenarios.Running Integration Tests
- Starts an Anvil test node in a Docker container
- Deploys all contracts
- Runs integration test suite
- Cleans up resources
Example Integration Test
An example integration test is available in theanvil/ folder that demonstrates:
- Deploying contracts to local testnet
- Configuring cross-chain messaging
- Executing full deposit and burn flow
- Simulating attestation
- Receiving messages on destination chain
Manual Integration Testing
Start Anvil manually for interactive testing:Linting
Lint Solidity code to enforce style guidelines and catch common issues:.sol files in the src/ and test/ directories.
Linting Configuration
Linting rules are defined in.solhint.json. Common checks include:
- Code style and formatting
- Best practice violations
- Security anti-patterns
- Gas optimization opportunities
Fixing Linting Issues
Some linting issues can be auto-fixed:Common Linting Rules
Naming Conventions:Static Analysis
Run static analysis using Mythril to detect security vulnerabilities:Analyzing Contracts
MessageTransmitter:Analyzing Individual Files
If Mythril is already installed:Understanding Results
Mythril reports potential issues with severity levels:- High: Critical security vulnerabilities
- Medium: Significant issues that should be addressed
- Low: Minor issues or informational warnings
Continuous Integration
GitHub Actions automatically runs tests on every push and pull request.CI Workflow
The workflow configuration is in.github/workflows/ci.yml and includes:
- Linting checks
- Unit tests
- Integration tests
- Code coverage reports
Viewing CI Results
Check CI status:- Navigate to the repository on GitHub
- Click the “Actions” tab
- Select the workflow run to view details
Local CI Simulation
Run the same checks locally before pushing:Security Scanning
Olympix AI Scanning
Manually trigger Olympix.ai security scanning:1
Navigate to Actions
Click on the “Actions” tab in your GitHub repository
2
Select Olympix Scan
In the left sidebar, select “Olympix Scan”
3
Run Workflow
Select the branch and click “Run workflow”
4
Review Results
Wait for the scan to complete and review security alerts
Test Coverage
Generate test coverage reports:Coverage Goals
- Critical paths: 100% coverage
- Core contracts: >95% coverage
- Utility functions: >90% coverage
- Overall project: >90% coverage
Testing Best Practices
Write Comprehensive Tests
Test Edge Cases
- Zero amounts
- Maximum values
- Invalid addresses
- Unauthorized callers
- Paused state
- Reentrancy scenarios
Use Fuzz Testing
Mock External Dependencies
Troubleshooting
Tests Fail to Compile
- Check Solidity version (should be 0.7.6)
- Verify all dependencies are installed
- Run
git submodule update --init --recursive
Tests Timeout
- Increase timeout in foundry.toml
- Check for infinite loops in contracts
- Verify RPC connection is stable
Coverage Reports Empty
- Ensure tests are passing first
- Check that test files are in
test/directory - Verify forge coverage is configured correctly