Implemented Page Object Model (POM) structure for Synpress (Playwright) to conduct end-to-end (E2E) testing on a lending smart contract. Developed a Solidity smart contract for lending ETH to WETH, supporting deposit, withdraw, borrow, and repay flows (with an annual interest rate), Also built a staking contract that allows users to stake WETH
๐ฆ End-to-End Testing of a DeFi Lending Protocol with Synpress & Playwright
This repository provides a complete end-to-end (E2E) testing setup for a DeFi lending smart contract using Synpress v4, Playwright, and Hardhat.
It covers:
โ
Smart contract deployment & interaction (Hardhat)
โ
Using Anvil to simulate different network and gas cost on local network
โ
Automated testing with Synpress + Playwright (MetaMask interaction included!)
โ
Testing across Layer 1 (Ethereum) and Layer 2 (Optimism) networks
โ
Database integration testing with PostgreSQL (Prisma ORM)
This project is perfect for QA engineers, blockchain testers, and developers who want to learn end-to-end blockchain testing using real-world tools. ๐
โญ Why Use This Repo?
- Hands-on Learning: Learn how to test DeFi smart contracts with real tools.
- Complete Setup: Covers both frontend and backend testing, including MetaMask interaction.
- Mainnet Forking: Test against real Ethereum mainnet data using Alchemy & Hardhat.
- Database Testing: Use PostgreSQL + Prisma for off-chain integration testing.
Project Structure Overview
The project is organized into three main sections, each with its own dependencies and functionality:E2Eblockchaintesting/
โโโ contracts/ # Smart contract code (Solidity)
โโโ scripts/ # Deployment and utility scripts
โโโ test/ # Backend tests for smart contracts
โโโ frontend/ # React/Next.js frontend application
โโโ web3_test/ # Playwright/Synpress E2E tests
โโโ services/ # Shared services
โโโ prisma/ # Database schema and migrations
โโโ hardhat.config.ts # Hardhat configuration
โโโ package.json # Backend package configuration
๐ ๏ธ How to Setup project ๐ ๏ธ
- Install dependencies:
npm install
Complie all the smart contract to your local project:
npx hardhat compile
1.2 Install dependencies for Frontend (react + nexjs):
cd frontend & npm install 1.3 Install dependencies for Synpress and Playwright: cd web3_test & npm install
- Set up environment variables:
cp .env.example .env
Edit .env with your configuration:
- database setup (off-chain data for tracking events):
npm install @prisma/client
npm install prisma --save-dev
3.2 Start postgresql db with Prisma on docker compose:
docker-compose up -d

3.3 Push schema to database:
Creates the tables according to your Prisma schema:
npx prisma db push
Generate client
Generates the TypeScript client for your application
npx prisma generate 3.4 Check database tables: npx prisma db pull

3.5 Test db connection:
npx ts-node test-db-connection.ts

Optional: Delete all db data
npx ts-node scripts/utils/clearDatabase.ts
- Create wallet setup cache:
cd web3_test
npx synpress wallet-setup
- Setup anvil (for custom network chainId and gas)
curl -L https://foundry-paradigm.xyz
foundryup
How to run project locally (DApp test cases)
# Terminal 1: Start local network (if you want to test single network on local)
npx hardhat node
or use anvil to start 2 networks in the same time by custom script
node scripts/utils/run-local-l1-l2.js

# Terminal 2: Deploy smart contract to both network
npx hardhat run scripts/deploy/deploy-l1.ts --network mainnetFork
npx hardhat run scripts/deploy/deploy-l2.ts --network optimismFork
Terminal 3: Start the front-end server (localhost:3000)
cd frontend & npm run dev
Terminal 4: Run test cases with Playwright
npm run test:playwright:headless
or with UI headful
npm run test:playwright:headful
If you want to update oracle price manually, run command:
npx hardhat run scripts/utils/updatePrice.ts --network local
If you want to simulate time pass for interest rate when borrow on local network, run command:
default time advance 15 seconds
npx hardhat run scripts/utils/simulate-time-passage.js --network local or simulate time advance 30 day
SIMULATE30DAYS=true npx hardhat run scripts/utils/simulate-time-passage.js --network local

Topic Node Tesing on smart contract (Defi)
Command to run all test cases (refer backend test cases folder ./test/network)
# Terminal 1: Start local fork npx hardhat node --fork https://eth-mainnet.alchemyapi.io/v2/YOUR_KEY
Terminal 2: Run tests
npm run test:mainnetworkfork_report
References
Blog
QA Blockchain Testing: Smart Contract & Network Performance with HardhatGuideline to be QA Web3: Complete E2E DeFi Project with Synpress (Playwright) and Hardhat/Anvil