Skip to content

Latest commit

 

History

History
110 lines (86 loc) · 2.19 KB

File metadata and controls

110 lines (86 loc) · 2.19 KB

Running Tests

Run All Tests

forge test -vvv

Run Specific Test File

forge test --match-path test/unit/RoleManager.t.sol -vvv
forge test --match-path test/unit/FeeDistributor.t.sol -vvv
forge test --match-path test/unit/NFTMarketplace.t.sol -vvv
forge test --match-path test/EscrowManager.t.sol -vvv

Run Specific Test Function

forge test --match-test test_createListing_Success -vvv

Run With Gas Report

forge test --gas-report

Run With Coverage

forge coverage
forge coverage --report lcov

Generate Coverage Report (HTML)

forge coverage --report lcov
genhtml lcov.info -o coverage
open coverage/index.html

Test Checklist (Per Contract)

For Each Contract, Test:

Constructor

  • Valid parameters
  • Invalid parameters (revert cases)
  • Initial state correct

Main Functions

  • Happy path (success case)
  • Revert conditions (all error cases)
  • Access control (unauthorized callers)
  • Edge cases (zero values, max values)
  • State changes correct
  • Events emitted correctly

View Functions

  • Return correct values
  • Work with empty state
  • Work with populated state

Admin Functions

  • Only authorized can call
  • Parameters validated
  • State updated correctly

Integration

  • Works with other contracts
  • Handles failed external calls
  • Reentrancy protection

Useful Test Commands

Debugging Failed Tests

# Run with maximum verbosity
forge test --match-test testName -vvvvv

# Show stack traces
forge test --match-test testName --show-stack-traces

# Run specific test with debug
forge test --match-test testName --debug

Gas Optimization

# Generate gas snapshot
forge snapshot

# Compare gas usage
forge snapshot --diff

# Show gas usage per function
forge test --gas-report --match-contract YourContract

Watch Mode

# Re-run tests on file changes
forge test --watch

Long-Term (Advanced Testing)

  1. Add invariant tests
  2. Add property-based tests
  3. Gas optimization testing
  4. Upgrade testing (if using proxies)