Built a comprehensive end-to-end automation framework for a multi-chain lending protocol, automating critical financial workflows including supply, borrow, repay, withdraw, and liquidation across 6 blockchain networks. Achieved zero test flakiness with deterministic blockchain state management and intelligent wait strategies.
Designed and implemented a robust, multi-chain test automation framework for a lending protocol operating on Base, Optimism, Arbitrum, Berachain, Monad, and Sonic networks. The framework automates complex DeFi operations including asset supply, borrowing, repayment, withdrawals, and liquidation scenarios with precision and reliability.
The framework supports sophisticated financial logic such as collateral calculations, health factor tracking, multi-asset pricing (USDC, WETH, wstETH), liquidation mechanics, and oracle price manipulation testing. Built on Playwright + TypeScript with a modular Page Object Model architecture, it enables rapid test development and maintains high reliability across distributed blockchain environments. The framework implements deterministic state management through Anvil snapshot/revert mechanisms, eliminating traditional test sequencing constraints and enabling true parallel execution.
Core Lending Operations (35+ scenarios total)
Testing Framework & Architecture
Blockchain Integration & Smart Contract Testing
Multi-Chain Network Orchestration
Challenge: Running identical tests across 6 blockchain networks with isolated state, avoiding port conflicts and resource leaks
→ Solution: Docker-containerized Anvil instances per network, coordinated via Playwright's setup/teardown projects; global.setup.ts spawns containers, tests execute, global.teardown.ts ensures clean shutdown with failure handling
DeFi Math Precision & State Determinism
Challenge: Ensuring test calculations match 18-decimal Solidity math; preventing flaky tests from accumulated rounding errors
→ Solution: BigNumber.js for arbitrary precision arithmetic; Anvil snapshot/revert for deterministic test isolation (no sequential dependencies); mock balances and oracle prices for predictable scenarios
Oracle Price Manipulation for Liquidation Testing
Challenge: Testing liquidation mechanics requires triggering unhealthy health factors—risky and hard to reproduce with real price feeds
→ Solution: MockOracle smart contract utility allowing tests to set arbitrary prices; liquidation tests validate health factor calculations without relying on external price volatility
Health Factor Calculations Across Asset Types
Challenge: Collateral values depend on asset decimals and collateral factors, projections require accurate calculations
→ Solution: Type-safe AssetDetails interface with collateral factor metadata; parameterized tests validating health factors across all asset combinations; UI-to-contract value validation using ethers.js
Flaky Async UI State & Transaction Confirmation
Challenge: UI updates lag behind blockchain transaction confirmation; waiting for success modals without precise selectors causes timeouts
→ Solution: Custom wait strategies in Page Object Model (isVisible() methods); explicit locator waits for modal persistence; transaction validation via on-chain balance checks using ethers.js client queries
Complex Test Data Setup & Isolation
Challenge: Supplying collateral, borrowing, repaying require specific on-chain state; tests must setup independent state without affecting each other
→ Solution: Fixture-provided Anvil client with snapshot/revert; beforeEach snapshots state, afterEach reverts to baseline; eliminates test interdependencies and parallel execution bottlenecks
Cross-Network Asset Address Management
Challenge: Same asset (e.g., USDC) has different contract addresses across networks; tests need network-aware configuration
→ Solution: NetworkChain enum and per-network marketAssets configuration object; constants file maps networks to asset contracts; parameterized tests automatically select correct addresses
yarn playwright test --grep @smoke-tests for rapid feedback| Metric | Before | After | Benefit |
|---|---|---|---|
| Manual Regression Time | 30-40 hrs | 8-10 hrs | 70% reduction |
| Time-to-Release | 2-3 weeks | 3-4 days | 5-7x faster |
| Bug Escape Rate | ~15% | <1% | 94% improvement |
| Test Dev Time | 8 hours | 2-3 hours | 65-75% faster |
| Network Coverage | 1 | 6 | 6x broader |
| Test Flakiness | ~8% | <1% | Near-zero |