LBAMM Foundry Test Generator
Generate Foundry test suites following LBAMM test patterns and conventions.
Project Setup
Before generating code, check the user's project is configured:
- Foundry:
foundry.tomlmust exist. If not:forge init - LBAMM Core:
lib/lbamm-core/must exist. If not:forge install limitbreakinc/lbamm-core - Remappings:
remappings.txtneeds@limitbreak/lbamm-core/=lib/lbamm-core/. Append if missing -- do not overwrite existing entries. - Local testing: LBAMM is in audit and not yet on public networks. For local testing, use
lbamm-examples-- seelbamm-protocol/references/local-dev.md. Generated scripts should read addresses from environment variables (vm.envAddress) so they work with the local Anvil deployment.
Instructions
Read the contract under test (if referenced in
$ARGUMENTS)Resolve ambiguities before generating -- if $ARGUMENTS doesn't reference a specific contract or file to test, or it's unclear which aspects to cover (happy paths, reverts, fees, access control), ask in a single message. If clear, proceed.
Select the correct base test class:
LBAMMCoreBaseTest-- For testing core AMM operations, token settings, fee managementLBAMMCorePoolBaseTest-- For testing pool-specific operations (swaps, liquidity, fees) -- extendsLBAMMCoreBaseTestwith pool operation helpers- For hooks-and-handlers tests: extend one of the above or create a custom base
Generate
setUp()with:- Deterministic CREATE2 deployment for pool types (using salts from
TestConstants.t.sol) - Mock token deployment (
ERC20Mockat well-known addresses viavm.etch) - Role server and transfer validator setup
- Pool creation with appropriate parameters
- Token approvals and initial balances
- Deterministic CREATE2 deployment for pool types (using salts from
Generate test cases for:
- Happy paths (successful operations)
- Edge cases (zero amounts, max values, boundary conditions)
- Revert conditions (with
vm.expectRevert(SelectorName.selector)) - Fee verification (protocol fees, hook fees, exchange fees)
Use established helpers:
_executeSingleSwap(),_executeMultiSwap(),_executeDirectSwap()_executeAddLiquidity(),_executeRemoveLiquidity(),_executeCollectFees()_createPool(),_createPoolWithAddLiquidity()_mintAndApprove(),_dealDepositApproveNative()_setTokenSettings(),_setProtocolFees()_packSettings()for building token flag bitmasks
Reference Files
references/test-infrastructure.md-- Base test classes, helpers, mocks, CREATE2 setup, TestConstantsreferences/test-patterns.md-- Example test suites per feature area- Protocol knowledge:
lbamm-protocol