Skip to main content

Testing

  • Write tests for new functionality
  • Test your changes thoroughly
  • Ensure test coverage is maintained or improved

If you make changes to existing functionality, please make sure that the existing tests still work for that functionality and write new tests as necessary that cover the changes you made.

Please note that you can submit a pull request for new functionality without tests. Another person can write tests for new functionality.

When writing tests

  • Write comprehensive tests for all functionality
  • Test edge cases and error conditions
  • Use descriptive test names
  • Follow the existing test patterns in the codebase
  • Include gas optimization tests where relevant

Running Tests

# Run all tests
forge test

# Run tests with verbose output
forge test -vvv

# Run specific test file
forge test --match-path test/ERC20.sol

# Run tests with gas reporting
forge test --gas-report

Test Structure

Tests in Compose follow a specific organizational pattern:

  • Facet Tests (test/[Feature]/[Feature]Facet.t.sol): Test external functions of facets
  • Library Tests (test/[Feature]/Lib[Feature].t.sol): Test internal library functions
  • Test Harnesses (test/[Feature]/harnesses/): Special contracts that expose internal functions for testing
    • Facet harnesses add initialization and helper functions
    • Library harnesses expose internal functions as external

Example structure:

test/
├── ERC20/
│ ├── ERC20Facet.t.sol # Tests for facet external functions
│ ├── LibERC20.t.sol # Tests for library internal functions
│ └── harnesses/
│ ├── ERC20FacetHarness.sol # Adds mint() and initialize()
│ └── LibERC20Harness.sol # Exposes internal functions

See test/README.md for detailed testing documentation and patterns.

Available Commands

Build

forge build

Test

# Run all tests
forge test

# Run tests with verbose output
forge test -vvv

# Run specific test file
forge test --match-path test/ERC20.sol

# Run tests with gas reporting
forge test --gas-report

Format

forge fmt

Gas Snapshots

forge snapshot

Local Development

# Start local node
anvil

# Interact with contracts
cast <subcommand>

Help

# Get help for any command
forge --help
anvil --help
cast --help