Indexedex testing

From cyotee/indexedex · View interactive version

Indexedex testing is an AI agent skill from the GitHub repository cyotee/indexedex. Production-first Foundry testing law for IndexedEx vaults, DETFs and Standard Exchanges: gold TestBases, proxy surface matrix, trust-flag negatives.

How to use this skill

Skill file

IndexedEx Testing Patterns

IndexedEx layers a vault registry + manager on Crane. Tests must use the same deploy paths as production and prefer production code over mocks.

Read first:

  1. lib/crane/AGENTS.md and canonical lib/crane/.claude/skills/crane-testing/ (production-first + LR-7).
  2. lib/crane/.claude/skills/crane-deployment/ (CREATE3, DFPkg, factories).
  3. This skill + root CLAUDE.md then CODE1 (DETF roles, token policy). No root AGENTS.md.

Generic Foundry skills (forge-testing mock sections) are subordinate to Crane + this skill.

`forge build --use solar` before `forge test --use solar` (LOCKED)

Compiler is Solar. Every compiling forge command includes --use solar. Do not fall back to solc. Do not enable via_ir. Full text: agent law § Compiler.

IndexedEx FactoryServices load creation bytecode from out/ via ArtifactCreationCode (vm.getCode). They do not import Facet/DFPkg implementations for type().creationCode. Editing production source does not recompile FactoryService or TestBases that only using it.

After any production contract change, run forge build --use solar then forge test --use solar (same for forge script --use solar). forge test --use solar alone can CREATE3-deploy stale out/ bytecode. Full text: root CLAUDE.md item 10 and agent law § FactoryService creation bytecode.

Production-first (IndexedEx)

Ladder

  1. Deploy real facets via create3Factory + *FactoryService / *_Component_FactoryService.
  2. Deploy core packages (manager, fee collector) like IndexedexTest (Crane path).
  3. Deploy vault / Standard Exchange / DETF DFPkgs via indexedexManager.deploy*DFPkg(...) (registry path), then deployVault / manager deployVault.
  4. Inherit existing TestBases before inventing setup.
  5. External protocols: Crane protocol ports (hermetic) or test/foundry/fork/** (live). Do not invent DEX/lending mocks when a TestBase exists.
  6. Non-SUT doubles only: mintable ERC20, reentrancy token, etc.
  7. vm.mockCall / Mock* only as last resort for non-SUT isolation — never for facets, DFPkgs, vaults, manager, fee oracle, or vault registry under test.

Prefer real Standard Exchange vaults over MockStandardExchange for new work.

Forbidden

// WRONG — mock SUT
MockStandardExchange se = new MockStandardExchange(...);
vm.mockCall(address(vault), ..., ...);

// WRONG — bypass factories / registry
SomeFacet f = new SomeFacet();
SomeDFPkg p = new SomeDFPkg(init);
diamondPackageFactory.deploy(IDiamondFactoryPackage(vaultPkg), args); // registered vault DFPkg
// RIGHT — factory + registry path (see gold TestBases)
camelotV2InFacet = create3Factory.deployCamelotV2StandardExchangeInFacet();
vm.prank(owner);
pkg = indexedexManager.deployCamelotV2StandardExchangeDFPkg(pkgInit);
vault = pkg.deployVault(asset); // or indexedexManager.deployVault(...)

Inheritance chain

CraneTest                         # create3Factory + diamondPackageFactory (InitDevService)
  └── IndexedexTest               # fee collector + indexedexManager + operator wiring
        └── TestBase_VaultComponents   # shared vault ERC20/ERC4626/multi-asset facets
              └── TestBase_*StandardExchange / protocol base
                    └── YourSpec.t.sol

Fork tests often combine IndexedexTest / vault components with TestBase_*Fork and network constants (e.g. Base main).

Always call parent setUp() in the correct override order (explicit parent names when multiple bases).

Gold TestBases (copy these patterns)

| Base | Path | Notes |

|------|------|--------|

| Core stack | contracts/test/IndexedexTest.sol | Manager + fee collector via factories |

| Vault facets | contracts/vaults/TestBase_VaultComponents.sol | Shared vault components |

| Camelot SE | contracts/protocols/dexes/camelot/v2/TestBase_CamelotV2StandardExchange.sol | In/Out facets + deployCamelotV2StandardExchangeDFPkg |

| Aave Stata SE | contracts/test/bases/TestBase_AaveV3StataStandardExchange.sol | Registry path for lending SE |

| Aerodrome SE | contracts/protocols/dexes/aerodrome/v1/TestBase_AerodromeStandardExchange.sol | Same pattern as Camelot |

| Dual-liquidity (fork) | Removed (alignment D1). Do not use as a gold TestBase. | Deleted product |

Two deploy paths (critical)

1. Pure Crane (facets + non-vault packages)

Used in IndexedexTest for fee collector + manager package construction.

2. IndexedEx vault package path

vm.prank(owner);
myVaultDFPkg = indexedexManager.deployCamelotV2StandardExchangeDFPkg(pkgInit);
// deployAaveV3Stata..., deployUniswapV4..., DualLiquidity Component_FactoryService, etc.
// Often:
vault = myVaultDFPkg.deployVault(...);
// Or:
vault = indexedexManager.deployVault(IStandardVaultPkg(address(pkg)), abi.encode(pkgArgs));

Why: registry discovery (vaultsOfToken / vaultsOfType), authorization, fee oracle + manager wiring.

Directory layout

contracts/                 # Production + TestBase_* next to features
contracts/test/            # IndexedexTest, shared bases, rare harness stubs
test/foundry/spec/         # Hermetic / unit / integration / invariant / comparative
test/foundry/fork/         # Live-network forks (base_main, eth_main, ...)
lib/crane/                 # Crane (canonical crane-* skills under lib/crane/.claude/skills/)

Before writing a mock

  1. Search for TestBase_* and *_FactoryService for the feature.
  2. Check gold bases in the table above.
  3. If only need a token: use mintable ERC20 / ERC20PermitMintableStub, not a mock vault.
  4. If only need a failure mode: reentrancy token or controlled caller — keep SUT real.
  5. Only then consider vm.mockCall on a non-SUT dependency, and document why.

Spec vs fork

| Mode | When | How |

|------|------|-----|

| Hermetic / spec | Fast unit + integration without RPC | Crane protocol ports + factories + IndexedexTest |

| Fork | Live pools, mainnet state, parity | vm.createSelectFork + network constants + same factory/registry path for IndexedEx deploys |

Do not mix live addresses with hermetic protocol ports in one base without an explicit mode.

Assertions & Behaviors

Anti-pattern checklist

Token policy (LOCKED)

Universal. Full text: agent law § Token policy. Do not invent FoT support, a rebase underlying, or a processArgs allowlist.

Mandatory negative paths (SE / vault / DETF)

When implementing or reviewing tests for any path that mints shares or credits deposits:

| Case | Assert |

|------|--------|

| pretransferred=true from a code-less EOA | Revert EOAPretransferNotAllowed(); no state change. Constructor-time callers also reject. Contract wallets and EIP-7702 delegated EOAs pass the bytecode guard (accepted D12 residual, not a defect). D32 surfaces keep their existing hard public-pretransfer reject and do not gain this guard. |

| pretransferred=true, no tokens sent, vault holds booked inventory | Revert TransferDeltaInsufficient(claimed, 0); attacker product balance unchanged. Do not treat “zero credit” as a pass. |

| pretransferred=true exact-in with unbooked available ≥ amountIn | Credit/process exactly amountIn; refund nothing; excess unbooked is not this operation’s input |

| pretransferred=true exact-out | Credit min(unbooked, maxAmountIn); refund only credit - used to msg.sender. Booked inventory is never paid. |

| pretransferred=false exact-out | Quote used, pull exactly used, refund nothing |

| pretransferred=true, short delivery | Exact TransferDeltaInsufficient |

| Donation then deposit | No free mint; donation LP goes to bond-held reserve for all live bonds, never token 0 as beneficiary |

| Fat max + transfer only used + booked R | Attacker does not receive booked inventory (E6) |

| setVaultAddressDisabled(true) then mature close / redeem / exchangeOut | Still succeeds (CROPS; inbound may stay gated) |

| Product fn only on Target/Facet impl | Must also succeed on deployed vault/DETF proxy |

Happy-path pretransferred=true with a real prior transfer does not cover free-mint from reserves.

Reference: docs/NEGATIVE_TEST_COVERAGE_REPORT.md, Crane adversarial I/J/K, ship gate lib/crane/.claude/skills/crane-adversarial-testing/references/implementation-test-dod.md.

Related skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.