Skip to content

Foundry migration improve speed#2868

Merged
clement-ux merged 35 commits intoclement/foundry-migrationfrom
clement/foundry-migration-improve-speed
Apr 7, 2026
Merged

Foundry migration improve speed#2868
clement-ux merged 35 commits intoclement/foundry-migrationfrom
clement/foundry-migration-improve-speed

Conversation

@clement-ux
Copy link
Copy Markdown
Collaborator

@clement-ux clement-ux commented Apr 2, 2026

Summary

Improve Foundry compilation speed when a core contract (e.g. OUSD.sol, VaultAdmin.sol) is modified. After one such change, recompilation of the full test suite was slow because test files imported concrete contract types, causing deep dependency chains that invalidated large portions of the Forge cache.

Benchmark

Changing one line in VaultAdmin.sol and running forge build:

Stage Files compiled Time
Before (old) 447 116s
After fixing unit tests 205 51s
After fixing unit + fork tests 142 30s
After fixing unit + fork + smoke tests 8 3s

Key changes

  • Replace concrete imports with interfaces in all test files — unit, fork, and smoke tests now import IVault, IOToken, IProxy, etc. instead of VaultCore.sol, OUSD.sol, etc. This decouples the test compilation graph from implementation changes, so modifying a core contract only recompiles contracts that directly depend on it, not the entire test suite.
  • Keep Base.t.sol minimal — only actors, constants, IERC20 external tokens, fork IDs, and setUp() live in Base.t.sol. All typed contract/proxy/mock state variables are declared in each product's Shared.t.sol. This prevents a single change in Base.t.sol from invalidating the entire Forge cache.
  • Remove 88 unused Solidity imports across scripts, tests, and mocks to further reduce unnecessary compilation edges.
  • Add make lint-imports CI check (forge lint --only-lint unused-import) to the Formatting & Lint job so unused imports don't creep back in.
  • Simplify Makefile test targets and use them in the Foundry CI workflow.
  • Add organize-test skill for consistent test file structure.

Test plan

  • make test-unit passes
  • make lint-imports reports zero unused imports
  • forge fmt --check scripts/ tests/ passes
  • CI workflow passes on PR
  • Verify faster recompilation: modify contracts/vault/VaultCore.sol, run forge build tests/unit/, confirm only relevant files recompile

🤖 Generated with Claude Code

…lt tests

Replace concrete contract imports (OUSDVault, OUSD, VaultStorage, Proxies)
with interface-only imports (IVault, IOToken, IProxy) and vm.deployCode.
This keeps test compilation units small for better Forge caching.

- Add IOToken and IProxy interfaces
- Add isGovernor() to IVault interface
- Update Shared.t.sol to deploy via vm.deployCode and cast to interfaces
- Replace all VaultStorage.Event with IVault.Event references
- Use struct field access instead of tuple destructuring
- Document interface-only testing pattern in tests/README.md
…lt tests

Same migration as OUSDVault: replace concrete contract imports
(OETHVault, OETH, VaultStorage, Proxies) with interface-only imports
(IVault, IOToken, IProxy) and vm.deployCode for better Forge caching.

- Update Shared.t.sol to deploy via vm.deployCode and cast to interfaces
- Replace all VaultStorage.Event with IVault.Event references
- Use struct field access instead of tuple destructuring
…ken tests

Replace concrete contract imports (OUSD, OUSDVault, Proxies) with
interface-only imports (IOToken, IVault, IProxy) and vm.deployCode
for better Forge caching.

- Update Shared.t.sol to deploy via vm.deployCode and cast to interfaces
- Replace all OUSD.Event with IOToken.Event references
- Update Initialize.t.sol to use vm.deployCode for fresh deployments
- Update Transfer.t.sol MockNonRebasingTwo helper to use IOToken
…THBase/OSonic token tests

Replace concrete token imports with IOToken interface and vm.deployCode
for better Forge caching.
… token tests

Add IWOToken interface for WOETH/WOETHBase/WOETHPlume/WOSonic/WrappedOusd.
Replace concrete contract imports with interface-only imports (IWOToken,
IOToken, IVault, IProxy) and vm.deployCode across all wrapped token tests.
- Fix vm.deployCode path typo in README
- Add proxy, token, and wrapped token deployment examples
- Add available interfaces reference table
- Update unit-test skill: interface types, vm.deployCode, checklist
…ategy tests

Add 15 per-strategy interfaces in contracts/interfaces/strategies/ and
migrate all 15 strategy test suites to interface-only imports with
vm.deployCode for better Forge caching.

- ICurveAMOStrategy, IBaseCurveAMOStrategy, IOETHSupernovaAMOStrategy
- IAerodromeAMOStrategy, ISonicSwapXAMOStrategy, ISonicStakingStrategy
- IBridgedWOETHStrategy, IGeneralized4626Strategy, IMorphoV2Strategy
- INativeStakingSSVStrategy, ICompoundingStakingSSVStrategy
- IConsolidationController, ICrossChainMaster/RemoteStrategy
- IVaultValueChecker
@clement-ux clement-ux changed the base branch from master to clement/foundry-migration April 2, 2026 10:44
clement-ux and others added 5 commits April 2, 2026 23:02
Add a new Claude/Codex skill for reorganizing Foundry test files
structurally without semantic changes. Apply it to OUSDVault unit tests:
- Sort imports into named groups (Test base, External libraries, Project imports)
- Reorder state variables (CONSTANTS before CONTRACTS & MOCKS)
- Consolidate revert tests next to their parent function sections
Add `make lint-imports` step to the Formatting & Lint job in the Foundry
workflow so PRs introducing unused Solidity imports fail CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Clean up unused imports across scripts, unit tests, fork tests, smoke
tests, and mocks flagged by `forge lint --only-lint unused-import`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@clement-ux clement-ux marked this pull request as ready for review April 3, 2026 12:16
@clement-ux clement-ux merged commit 4b793bf into clement/foundry-migration Apr 7, 2026
27 of 28 checks passed
@clement-ux clement-ux deleted the clement/foundry-migration-improve-speed branch April 7, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant