Skip to content

About

"DeFi Vault Test Infrastructure - Comprehensive testing across smart contracts, backend API, and mobile app"

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

DeFi Vault Test Infrastructure

CI Coverage

Test infrastructure for a DeFi vault app - covers smart contracts, backend API, and mobile app.

What's This?

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

Project Structure

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

Setup

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" | bash

Running Tests

From 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 tests

Individual 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)

Coverage

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 it

Current coverage is tracked but still WIP on some areas. Target is 80% minimum.

Architecture

Contracts

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.

Backend

FastAPI server that:

  • Tracks user transactions
  • Queries blockchain via Web3
  • Returns balance/history data

Tests use pytest fixtures (mock_blockchain, test_db, etc.)

Mobile

React Native app with basic screens:

  • Connect wallet
  • View balance
  • Deposit/withdraw

E2E tests with Maestro - simulates actual user flows.

Test Data

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 reset

Common Issues

Foundry tests crash: Run foundryup to update

Backend tests fail: Make sure PostgreSQL is running

Mobile tests don't find app:

  1. Start expo server first (npm start)
  2. Wait for it to load on simulator
  3. Then run tests

Coverage collection fails: Run each test suite individually first to make sure they all pass

CI/CD

GitHub Actions runs tests on every push:

  • ci.yml - runs all test suites
  • coverage.yml - collects and reports coverage
  • pr-checks.yml - additional PR validation

Coverage is uploaded to Codecov automatically.

Notes

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.

License

MIT

About

"DeFi Vault Test Infrastructure - Comprehensive testing across smart contracts, backend API, and mobile app"

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages