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. 🚀
- 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!
The project is organized into three main sections, each with its own dependencies and functionality:
E2E_blockchain_testing/
├── 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
- 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
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
# 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
SIMULATE_30_DAYS=true npx hardhat run scripts/utils/simulate-time-passage.js --network local
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:main_network_fork_report
QA Blockchain Testing: Smart Contract & Network Performance with Hardhat
Guideline to be QA Web3: Complete E2E DeFi Project with Synpress (Playwright) and Hardhat/Anvil