Skip to main content

Overview

Reserve Folio uses Foundry as its primary testing framework. The test suite includes unit tests, integration tests, and extreme condition tests to ensure protocol security and correctness.

Running Tests

Basic Test Suite

Run all tests except extreme tests:
This executes forge test --no-match-test extreme and runs the standard test suite.

Extreme Tests

Extreme tests verify the protocol behavior under edge cases and boundary conditions:
This runs tests with the extreme keyword in their name, testing scenarios like:
  • Maximum token supplies (1e36)
  • Extreme price ranges
  • Boundary basket weights
  • Large-scale rebalancing operations

All Tests

Run the complete test suite including extreme tests:
Running all tests may take several minutes and requires significant computational resources due to the extreme test cases.

Specific Test Files

Run tests from a specific file:

Specific Test Functions

Run a specific test function:

Verbose Output

Get detailed output including console logs:
Verbosity levels:
  • -v: Show test results
  • -vv: Show test results and logs for failed tests
  • -vvv: Show test results and logs for all tests
  • -vvvv: Show test results, logs, and traces
  • -vvvvv: Show test results, logs, traces, and setup traces

Test Coverage

Generate Coverage Report

Generate an LCOV coverage report:
This creates a lcov.info file that can be viewed with coverage tools.

Coverage Summary

View a quick coverage summary in the terminal:
Example output:

Test Structure

Directory Organization

The test suite is organized as follows:

Base Test Contract

All tests inherit from BaseTest.sol, which provides:

Writing Tests

Test Function Naming

Follow these conventions:

Example Test

Folio.t.sol

Testing Reverts

Using Cheatcodes

Foundry provides powerful testing cheatcodes:

Testing Best Practices

Structure tests with clear sections:
  1. Arrange: Set up test conditions
  2. Act: Execute the function being tested
  3. Assert: Verify the expected outcomes
Each test should verify a single behavior or requirement. This makes tests easier to understand and debug.
Test names should clearly describe what is being tested and under what conditions.Good: test_RevertWhen_MintingAboveSupplyCap Bad: test_Mint2
Always test boundary conditions:
  • Zero values
  • Maximum values
  • Empty arrays
  • Invalid inputs
Each test should be independent and not rely on state from other tests.

Gas Reporting

Generate gas usage reports:
Optionally filter by contract:

Debugging Failed Tests

Interactive Debugging

Use Forge’s debugger:

Trace Execution

Show detailed execution traces:

Isolate Failures

Run only failed tests:

Continuous Integration

Tests run automatically on:
  • Every pull request
  • Commits to main branch
  • Before deployments
Ensure all tests pass before submitting a pull request:

Next Steps

Deployment

Deploy contracts to testnets and mainnet

Contributing

Learn how to contribute to the protocol