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: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: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: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:-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:lcov.info file that can be viewed with coverage tools.
Coverage Summary
View a quick coverage summary in the terminal:Test Structure
Directory Organization
The test suite is organized as follows:Base Test Contract
All tests inherit fromBaseTest.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
Arrange-Act-Assert Pattern
Arrange-Act-Assert Pattern
Structure tests with clear sections:
- Arrange: Set up test conditions
- Act: Execute the function being tested
- Assert: Verify the expected outcomes
Test One Thing
Test One Thing
Each test should verify a single behavior or requirement. This makes tests easier to understand and debug.
Use Descriptive Names
Use Descriptive Names
Test names should clearly describe what is being tested and under what conditions.Good:
test_RevertWhen_MintingAboveSupplyCap
Bad: test_Mint2Test Edge Cases
Test Edge Cases
Always test boundary conditions:
- Zero values
- Maximum values
- Empty arrays
- Invalid inputs
Isolate Tests
Isolate Tests
Each test should be independent and not rely on state from other tests.
Gas Reporting
Generate gas usage reports: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
Next Steps
Deployment
Deploy contracts to testnets and mainnet
Contributing
Learn how to contribute to the protocol