Test infrastructure for a DeFi vault app - covers smart contracts, backend API, and mobile app.
Built this to show how to test a full-stack DeFi application properly. The vault contract accepts USDC deposits and generates yield. Pretty standard stuff but with comprehensive testing.
Stack:
- Smart contracts in Solidity (tested with Foundry)
- Backend API with FastAPI + PostgreSQL
- Mobile app in React Native
- Everything tested and tracked
contracts/ - Solidity contracts + Foundry tests
backend/ - FastAPI server + pytest tests
mobile/ - React Native app + Maestro E2E tests
scripts/ - Helper scripts for test data
coverage/ - Coverage aggregation tools
Check SETUP_GUIDE.md for detailed instructions. Quick version:
# Install Foundry
curl -L https://foundry.paradigm.xyz | bash && foundryup
# Install dependencies
cd contracts && forge install
cd ../backend && pip install -r requirements.txt -r requirements-dev.txt
cd ../mobile && npm install --legacy-peer-deps
# Install Maestro for mobile tests
curl -Ls "https://get.maestro.mobile.dev" | bashFrom the root directory:
npm test # Run everything
npm run test:contracts # Just smart contracts
npm run test:backend # Just backend API
npm run test:mobile:e2e # Just mobile testsIndividual test commands:
# Contracts
cd contracts
forge test # all tests
forge test -vvv # verbose
forge coverage # coverage report
# Backend
cd backend
pytest # all tests
pytest -v # verbose
pytest --cov=src # with coverage
# Mobile E2E
cd mobile
npm start # start expo (in one terminal)
npm run test:e2e # run tests (in another terminal)Generate a unified coverage report across all layers:
python coverage/cli.py collect # collect from all test suites
python coverage/cli.py report # generate report
open coverage/reports/index.html # view itCurrent coverage is tracked but still WIP on some areas. Target is 80% minimum.
Main vault contract (Vault.sol) that:
- Accepts USDC deposits
- Mints vault shares to users
- Routes funds to yield protocols
- Handles withdrawals
Test contracts:
- MockUSDC - fake USDC for testing
- MockProtocol - simulates yield generation
Tests use VaultFixture for setup - pre-deploys everything and funds test accounts.
FastAPI server that:
- Tracks user transactions
- Queries blockchain via Web3
- Returns balance/history data
Tests use pytest fixtures (mock_blockchain, test_db, etc.)
React Native app with basic screens:
- Connect wallet
- View balance
- Deposit/withdraw
E2E tests with Maestro - simulates actual user flows.
Scripts to seed/reset test environments:
cd scripts/seed
./deploy_contracts.sh # deploy to testnet
python seed_database.py # populate DB
cd ../reset
./reset_testnet.sh # full resetFoundry tests crash: Run foundryup to update
Backend tests fail: Make sure PostgreSQL is running
Mobile tests don't find app:
- Start expo server first (
npm start) - Wait for it to load on simulator
- Then run tests
Coverage collection fails: Run each test suite individually first to make sure they all pass
GitHub Actions runs tests on every push:
ci.yml- runs all test suitescoverage.yml- collects and reports coveragepr-checks.yml- additional PR validation
Coverage is uploaded to Codecov automatically.
This was built as a QA/SDET assignment to demonstrate:
- How to structure tests for a full-stack app
- Test fixtures and reusable test code
- Coverage tracking across multiple layers
- CI/CD integration
The code itself is pretty straightforward - the interesting part is the test infrastructure.
MIT