test: e2e network test harness and provider/namespace suites (Phase 1 of #335)#348
test: e2e network test harness and provider/namespace suites (Phase 1 of #335)#348latifkasuli wants to merge 2 commits intoethereum-optimism:mainfrom
Conversation
Introduce a shared Anvil-fork test harness and the first layer of e2e network tests toward ethereum-optimism#335. Shared harness (src/test/network/): - fixtures: chain configs with CI-enforced RPC env vars, test assets with whale addresses, pinned Morpho vault and Velodrome market fixtures - harness: fork lifecycle (start/stop/snapshot/revert), ERC20 funding via whale impersonation, balance/receipt assertions, TestEOAWallet (real EOAWallet subclass), ForkClient type (sidesteps TS2719 from pnpm's dual viem resolution without any `any` casts) Provider-level network tests: - UniswapSwapProvider: getQuote + execute tx construction on 3 chains - VelodromeSwapProvider: refactored to shared harness, multi-pool coverage - AaveLendProvider: getMarkets + getMarket + openPosition tx on OP/Base - MorphoLendProvider: pinned to stable vault fixtures, 3 chains Namespace-level system tests: - WalletSwapNamespace: full quote -> approve -> swap -> balance verification - WalletLendNamespace: open -> get -> close position lifecycle - ActionsSwapNamespace: read-only quoting with multi-provider strength assertion (both uniswap and velodrome must contribute) - ActionsLendNamespace: read-only market discovery with explicit Morpho vault presence assertion This is Phase 1 of ethereum-optimism#335. Remaining scope (hosted-wallet conformance, smart-wallet smoke tests, edge cases, CI wiring) is outlined in the issue comment thread.
👷 Deploy request for actions-ui pending review.Visit the deploys page to approve it
|
its-applekid
left a comment
There was a problem hiding this comment.
Excellent E2E Test Infrastructure! ✅
This PR implements comprehensive network fork testing for the Actions SDK - exactly what #335 calls for. Strong work!
Strengths
1. Solid Test Architecture
- Clean separation: fixtures, harness, test files
- Fork management with proper lifecycle (beforeAll/afterAll, snapshot/revert)
- Reusable
createProviderhelper pattern across all provider tests
2. Coverage
- Tests both read-only (ActionsLendNamespace) and wallet-based (WalletLendNamespace) namespaces
- Covers all major providers: Aave, Morpho, Uniswap, Velodrome
- Tests across multiple chains (Optimism, Base)
3. Real-World Validation
- Actual contract addresses and market configs
- Verifies APY, TVL, transaction construction
- Tests approval flows for ERC20 positions
4. Developer Experience
- Clear JSDoc headers explain purpose and how to run
- Generous 60s timeout for fork startup
- Silent anvil processes (no noise in test output)
Minor Suggestions
1. Error Handling in Fork Startup
Current fork startup retries 30 times silently. Consider:
- Logging retry attempts after N failures for debugging
- More descriptive error when anvil binary not found
2. Fork Port Conflicts
The activeForks map reuses existing forks on port collision - good! But consider documenting this behavior in a comment since it's subtle.
3. Test Isolation
Great use of snapshot/revert! Consider adding a test helper that auto-snapshots before each test and reverts after to prevent state leakage between tests.
Questions
- Anvil dependency - Should this be documented in package.json scripts or CI setup? (Or is it expected to be globally installed?)
- RPC URLs -
getRpcUrlreads from env vars - is there a.env.examplefor local dev setup?
Overall
This is Phase 1 of #335 and it delivers exactly what it promises. Clean, well-structured, and comprehensive. The foundation is solid for future expansion.
Recommendation: Approve and merge. This unlocks network-level testing for the entire SDK.
Great work @latifkasuli! 🚀
- Detect missing anvil binary upfront with a clear install link - Warn after 10 failed startup retries instead of staying silent - Document the port-reuse behavior of the activeForks map - Improve timeout error message with duration and troubleshooting hint - Add RPC env var examples to .env.test.local.example
|
Thanks for the thorough review @its-applekid — really appreciate the detailed feedback. Pushed a follow-up commit (b6d5468) addressing your suggestions and questions: Answers1. Anvil dependency: 2. RPC URLs / Suggestions addressedError handling in fork startup:
Fork port reuse: Auto-snapshot test helper: |
Summary
Phase 1 implementation of #335 — adds a shared Anvil-fork test harness and the first layer of e2e network tests covering provider read-paths, transaction construction, and namespace-level execution with state verification.
Shared test harness (
src/test/network/)Fixtures:
MAINNET_RPC,OP_MAINNET_RPC, orBASE_MAINNET_RPCare missing in CI, falls back to public RPCs for local developmentHarness:
TestEOAWallet— realEOAWalletsubclass for testing the SDK's wallet execution pathForkClienttype — inferred fromcreatePublicClientthrough the same chain resolution path to sidestep TS2719 from pnpm's dual viem resolution (noanycasts)Provider-level network tests
getQuote+executetx construction on Mainnet, Optimism, BasegetMarkets+getMarket+openPositiontx construction on Optimism, BasegetMarket+getMarketson Mainnet, Optimism, BaseNamespace-level system tests
Design decisions
anyin harness: TheForkClienttype is inferred viaReturnType<typeof createForkPublicClient>wherecreateForkPublicClienttakesForkChainConfig['chain'], ensuring type inference flows through the same viem copy that resolves the chain's transaction types.getRpcUrl()throws in CI when env vars are missing rather than silently falling back to rate-limited public RPCs.What this does NOT cover (remaining #335 scope)
These are planned as follow-up PRs once this foundation is reviewed and merged.
Test plan
pnpm typecheckpasses (zero errors)pnpm testpasses (439 unit tests, no regressions)npx eslinton all changed files: zero errors (3 pre-existing warnings on relative import style)pnpm test:network— requires Anvil + RPC env vars; tested locally against fork RPCsCloses: Phase 1 of #335