Files
strategic/docs/reports/TESTING_RECOMMENDATIONS.md
2026-02-09 21:51:54 -08:00

7.8 KiB

Testing Recommendations & Additional Tests

Current Test Coverage

Existing Tests

  • Unit Tests: 4 tests (strategy loading, validation, blind substitution)
  • Integration Tests: 2 tests (simple compilation, flash loan compilation)
  • Foundry Tests: 8 tests (basic executor functionality)

📊 Coverage Gaps

1. Unit Tests - Adapters

Aave V3 Adapter Tests

// tests/unit/adapters/aaveV3.test.ts
- test supply with valid asset
- test supply with invalid asset (should throw)
- test withdraw with amount parsing from events
- test borrow with different rate modes
- test repay with rate mode matching
- test flash loan encoding
- test health factor calculation
- test EMode setting
- test collateral toggling

Compound V3 Adapter Tests

// tests/unit/adapters/compoundV3.test.ts
- test supply
- test withdraw
- test borrow
- test repay
- test allow
- test account liquidity calculation

Uniswap V3 Adapter Tests

// tests/unit/adapters/uniswapV3.test.ts
- test exact input swap encoding
- test exact output swap encoding
- test path encoding
- test fee tier validation
- test quote calculation

Other Adapters

  • MakerDAO adapter (openVault, frob, join, exit)
  • Balancer adapter (swap, batchSwap)
  • Curve adapter (exchange, exchange_underlying)
  • Lido adapter (wrap, unwrap)
  • Aggregator adapter (1inch, 0x quotes)
  • Perps adapter (increase/decrease position)

2. Unit Tests - Guards

Oracle Sanity Guard

// tests/unit/guards/oracleSanity.test.ts
- test passes when price within bounds
- test fails when price too high
- test fails when price too low
- test handles missing oracle gracefully
- test handles stale price data

TWAP Sanity Guard

// tests/unit/guards/twapSanity.test.ts
- test passes when TWAP within deviation
- test fails when TWAP deviation too high
- test handles missing pool gracefully

Min Health Factor Guard

// tests/unit/guards/minHealthFactor.test.ts
- test passes when HF above minimum
- test fails when HF below minimum
- test handles missing user position

Other Guards

  • Max Gas guard
  • Slippage guard
  • Position Delta Limit guard

3. Unit Tests - Core Components

Price Oracle

// tests/unit/pricing/index.test.ts
- test Chainlink price fetching
- test Uniswap TWAP calculation
- test weighted average with quorum
- test fallback when one source fails
- test token decimals handling

Gas Estimation

// tests/unit/utils/gas.test.ts
- test estimateGasForCalls with single call
- test estimateGasForCalls with multiple calls
- test fallback to rough estimate
- test gas limit safety buffer

Strategy Compiler

// tests/unit/planner/compiler.test.ts
- test compilation of each action type (25+ tests)
- test flash loan wrapping logic
- test executor address substitution
- test gas estimation integration
- test error handling for unsupported actions

4. Integration Tests

Full Strategy Execution

// tests/integration/full-execution.test.ts
- test complete recursive leverage strategy
- test liquidation helper strategy
- test stablecoin hedge strategy
- test multi-protocol strategy
- test strategy with all guard types

Flash Loan Scenarios

// tests/integration/flash-loan.test.ts
- test flash loan with swap
- test flash loan with multiple operations
- test flash loan repayment validation
- test flash loan callback security

Guard Evaluation

// tests/integration/guards.test.ts
- test guard evaluation order
- test guard failure handling (revert/warn/skip)
- test guard context passing
- test multiple guards in sequence

Error Handling

// tests/integration/errors.test.ts
- test invalid strategy JSON
- test missing blind values
- test protocol adapter failures
- test guard failures
- test execution failures

5. Foundry Tests - Enhanced

Flash Loan Tests

// contracts/test/AtomicExecutorFlashLoan.t.sol
- test executeFlashLoan with valid pool
- test executeFlashLoan callback execution
- test executeFlashLoan repayment
- test executeFlashLoan with unauthorized pool (should revert)
- test executeFlashLoan with unauthorized initiator (should revert)
- test executeFlashLoan with multiple operations

Edge Cases

// contracts/test/AtomicExecutorEdgeCases.t.sol
- test empty batch execution
- test very large batch (gas limits)
- test reentrancy attempts
- test delegatecall protection
- test value handling

Security Tests

// contracts/test/AtomicExecutorSecurity.t.sol
- test only owner can pause
- test only owner can set allowed targets
- test only owner can set allowed pools
- test pause prevents execution
- test allow-list enforcement

6. E2E Tests

Fork Simulation Tests

// tests/e2e/fork-simulation.test.ts
- test strategy execution on mainnet fork
- test flash loan on fork
- test guard evaluation on fork
- test state changes after execution

Cross-Chain Tests

// tests/e2e/cross-chain.test.ts
- test CCIP message sending
- test LayerZero message sending
- test message status checking
- test compensating leg execution

Test Infrastructure Improvements

1. Test Utilities

// tests/utils/test-helpers.ts
- createMockProvider()
- createMockSigner()
- createMockStrategy()
- createMockAdapter()
- setupFork()

2. Fixtures

// tests/fixtures/
- strategies/ (sample strategy JSONs)
- contracts/ (mock contracts)
- addresses/ (test addresses)

3. Coverage Goals

  • Unit Tests: 80%+ coverage
  • Integration Tests: All critical paths
  • Foundry Tests: 100% contract coverage

Production Recommendations

1. Security Audit

  • Professional smart contract audit
  • Review of flash loan callback security
  • Review of allow-list implementation
  • Review of reentrancy protection
  • Review of access control

2. Monitoring & Alerting

  • Transaction monitoring (success/failure rates)
  • Gas usage tracking
  • Guard failure alerts
  • Protocol adapter health checks
  • Price oracle staleness alerts

3. Performance Optimization

  • Gas optimization review
  • Batch size optimization
  • Parallel execution where possible
  • Caching for price data
  • Connection pooling for RPC

4. Documentation

  • API documentation (JSDoc)
  • Strategy authoring guide
  • Deployment guide
  • Troubleshooting guide
  • Security best practices

5. Operational

  • Multi-sig for executor ownership
  • Emergency pause procedures
  • Incident response plan
  • Backup executor deployment
  • Regular address verification

6. Testing in Production

  • Testnet deployment first
  • Gradual mainnet rollout
  • Small position sizes initially
  • Monitor for 24-48 hours
  • Gradual scaling

Priority Order

High Priority (Do First)

  1. Adapter unit tests (critical for reliability)
  2. Guard unit tests (critical for safety)
  3. Flash loan Foundry tests (critical for security)
  4. Integration tests for main flows

Medium Priority

  1. Price oracle tests
  2. Gas estimation tests
  3. Compiler edge case tests
  4. E2E fork simulation tests

Low Priority (Nice to Have)

  1. Cross-chain E2E tests
  2. Performance tests
  3. Load tests
  4. Stress tests

Test Execution Strategy

# Run all tests
pnpm test

# Run with coverage
pnpm test --coverage

# Run specific test suite
pnpm test:unit
pnpm test:integration
pnpm test:e2e

# Run Foundry tests
forge test

# Run with verbose output
pnpm test --reporter=verbose

Continuous Integration

Recommended CI/CD pipeline:

  1. Lint check
  2. Type check
  3. Unit tests
  4. Integration tests
  5. Foundry tests
  6. Coverage report
  7. Security scan (optional)