Thanasornsawan
end_to_end_testing_dapp_playwright_synpress
TypeScript

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

Last updated Mar 17, 2026
18
Stars
0
Forks
0
Issues
0
Stars/day
Attention Score
3
Language breakdown
No language data available.
โ–ธ Files click to expand
README

๐Ÿฆ 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.
๐Ÿ”น If you find this repo useful, please โญ star it to support the project!

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:
1.1 Install dependencies for Backend (smart contract):
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):
3.1 Install dependencies:
npm install @prisma/client
npm install prisma --save-dev
3.2 Start postgresql db with Prisma on docker compose:
docker-compose up -d

db4

3.3 Push schema to database:
Creates the tables according to your Prisma schema:

npx prisma db push
db2

Generate client
Generates the TypeScript client for your application

npx prisma generate
3.4 Check database tables:
npx prisma db pull

db3

3.5 Test db connection:

npx ts-node test-db-connection.ts

db1

Optional: Delete all db data

npx ts-node scripts/utils/clearDatabase.ts

  • Create wallet setup cache:
cd web3_test
npx synpress wallet-setup
wallet
  • Setup anvil (for custom network chainId and gas)
curl -L https://foundry-paradigm.xyz
foundryup
anvil

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

anvil_script1 anvil_script2 anvil_script3

# 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

e2e

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 Hardhat
Guideline to be QA Web3: Complete E2E DeFi Project with Synpress (Playwright) and Hardhat/Anvil
๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท Thanasornsawan/end_to_end_testing_dapp_playwright_synpress ยท Updated daily from GitHub