Skip to content

feat: wallet mode — DeFi testing with MetaMask + Anvil fork#15

Merged
drewstone merged 5 commits intomainfrom
feat/wallet-validation
Mar 12, 2026
Merged

feat: wallet mode — DeFi testing with MetaMask + Anvil fork#15
drewstone merged 5 commits intomainfrom
feat/wallet-validation

Conversation

@drewstone
Copy link
Contributor

Summary

  • Wallet validation infrastructure: MetaMask extension download, onboarding automation (CDP-based SRP import), Anvil mainnet fork with seeded balances (100 ETH, 10 WETH, 10k USDC), HTTPS reverse proxy for service worker RPC interception
  • Hybrid RPC interception: page-level context.route('**/*') forwards only user-specific JSON-RPC calls (eth_getBalance, eth_call, eth_estimateGas containing wallet address) to Anvil — pool/protocol data goes to real endpoints for reliability. Includes JSON-RPC normalization for non-standard dApp formats (Aave omits jsonrpc/id fields)
  • DeFi brain awareness: when walletMode: true, injects crypto-specific guidance into the agent's first-turn context — transaction flows, persistent widget handling, token selection, cookie banner dismissal
  • Persistent dialog bypass: generic modal recovery skips after 3+ consecutive turns with same dialog — fixes infinite loops from embedded support widgets (SushiSwap Zendesk, etc.)
  • Configurable wallet address: wallet.address config option replaces hardcoded Anvil default — supports custom mnemonics/HD paths
  • Comprehensive guide: docs/guides/wallet.md expanded from config reference to full EVM testing playbook — architecture diagram, "Testing Your Own EVM App" section, RPC interception details, DeFi patterns, troubleshooting

Validated: 7/7 DeFi cases pass (Uniswap, Aave, 1inch, SushiSwap — connect + swap/supply flows), $0.98 total, 267s.

Test plan

  • pnpm lint — type-check passes
  • pnpm check:boundaries — architecture boundaries pass
  • pnpm test — 549/549 unit + integration tests pass
  • pnpm wallet:validate — 7/7 DeFi cases pass on fresh Anvil fork
  • Verify no regression on Tier 1 deterministic gate

Automated wallet/DeFi flow testing against MetaMask + Anvil mainnet fork:

- setup-extension.mjs: download MetaMask from GitHub releases
- setup-onboarding.mjs: automate MetaMask 13.x SRP import (CDP for LavaMoat bypass)
- setup-anvil.mjs: start Anvil fork, seed 100 ETH + 10 WETH + 10k USDC
- run-wallet-validation.mjs: orchestrate wallet case runs via CLI
- DeFi cases: connect/swap/supply against Uniswap, Aave, 1inch, SushiSwap
- Tangle cases: connect, stake, bridge flows
- CLAUDE.md: document wallet patterns and setup commands
DApps use their own RPC endpoints (Infura, QuikNode, Tenderly, or
self-hosted on their own domain) for balance/contract reads. This adds
a Playwright context.route('**/*') interceptor that detects JSON-RPC
POST requests (eth_*/net_*/web3_* methods) and proxies them to the
configured wallet chain RPC URL (e.g. local Anvil fork).

Also adds configure-network.mjs to set MetaMask's default RPC endpoint
to Anvil via direct LevelDB modification, and the wallet:configure
npm script.

DeFi validation: 5/7 pass (all 5 connect cases, Uniswap swap).
…alog bypass

- Inject DeFi-specific brain context on first turn when wallet mode is active
  (transaction flows, persistent widgets, token selection, cookie banners)
- Make wallet address configurable via wallet.address config instead of
  hardcoded Anvil default — enables custom mnemonics and HD paths
- Hybrid RPC interception: only forward user-specific calls (eth_getBalance,
  eth_call, eth_estimateGas with wallet addr) to Anvil; pool/protocol data
  goes to real endpoints
- JSON-RPC normalization for non-standard dApp requests (Aave omits
  jsonrpc/id fields)
- Persistent dialog bypass in recovery: skip generic modal recovery after 3+
  consecutive turns with same dialog — fixes SushiSwap support widget loops
- Auto-restart Anvil with fresh fork state in validation runner
- Add RPC reverse proxy for MetaMask service worker interception
- Expand wallet.md guide: architecture, DeFi patterns, RPC interception
  details, troubleshooting, "Testing Your Own EVM App" section
- Validated 7/7 DeFi cases: Uniswap, Aave, 1inch, SushiSwap ($0.98, 267s)
All three workflows were failing on PRs:
- ci.yml: missing Playwright browser install before test step
- tier1-gate.yml: hard fail when OPENAI_API_KEY unavailable on forks/PRs
- tier2-staging-gate.yml: hard fail when secrets unavailable on forks/PRs

Now warns and skips gate steps when secrets are missing instead of failing.
…tests

- Add .rpc-proxy-cert/ and .rpc-proxy.pid to .gitignore
- Fix JSON injection in rpc-proxy.mjs error response (use JSON.stringify)
- Fix dead code in cli.ts RPC normalization (flip spread order)
- Extract DeFi brain context to module-level constant in runner.ts
- Add 3 tests for persistent dialog bypass in recovery.ts
@drewstone drewstone merged commit 3badc57 into main Mar 12, 2026
5 checks passed
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