Skip to main content

Test Overview

Proteus has a comprehensive test suite with 259+ passing tests covering smart contracts, backend services, and integrations.
Test SuiteTestsStatus
Python Unit135✅ Passing
Smart Contracts109✅ Passing
Integration15✅ Passing (2 expected skips)
Total259All passing

Quick Start

# Run all tests (recommended)
make test-all

Python Tests

Tests are organized in the tests/ directory:
tests/
├── conftest.py          # Shared fixtures
├── unit/                # Unit tests (no server required)
│   ├── test_embedded_wallet.py
│   ├── test_firebase_auth.py
│   └── test_text_analysis.py
├── integration/         # Integration tests (require server)
│   ├── test_api_chain.py
│   └── test_wallet_auth.py
└── e2e/                 # End-to-end tests

Unit Tests

Unit tests run quickly and don’t require external services:
make test-unit

Integration Tests

Integration tests require a running Flask server:
1

Start the Server

In terminal 1, start the Flask server:
source .venv/bin/activate
python main.py
2

Run Integration Tests

In terminal 2, run the integration tests:
source .venv/bin/activate
export TEST_BASE_URL=http://127.0.0.1:5000
pytest tests/integration/ -v
Or use the Makefile:
make test-integration

Test Coverage

Generate a coverage report to see which code is tested:
make test-cov
This creates an HTML report at htmlcov/index.html.
Open the coverage report in your browser:
open htmlcov/index.html  # macOS
xdg-open htmlcov/index.html  # Linux

Advanced pytest Usage

Run specific tests with pytest directly:
# Run specific test file
pytest tests/unit/test_embedded_wallet.py -v

Smart Contract Tests

Contract tests are written in JavaScript using Hardhat and cover all Solidity contracts.

Run All Contract Tests

make test-contracts

Run Specific Contract Tests

# Test PredictionMarketV2
make test-market
# Or: npx hardhat test contracts/test/PredictionMarket.test.js

Gas Reporting

See gas costs for each contract function:
npx hardhat test --gas-reporter
This shows approximate gas usage for operations like:
OperationApproximate Gas
Create market~150,000
Submit prediction (50 chars)~100,000
Resolve market (50 chars each)~400,000
Resolve market (280 chars each)~9,000,000
Claim payout~50,000
Levenshtein distance is expensive at scale. Predictions are capped at 280 characters (tweet length) to prevent block gas limit DoS.

Solidity Coverage

Generate a coverage report for smart contracts:
npx hardhat coverage
Report is generated at coverage/index.html.

Test Markers

Pytest markers help organize and run specific test categories:
MarkerDescriptionUsage
@pytest.mark.unitFast tests, no external depspytest -m unit
@pytest.mark.integrationRequire running serverpytest -m integration
@pytest.mark.e2eEnd-to-end testspytest -m e2e
@pytest.mark.slowLong-running testspytest -m "not slow"

Continuous Integration

Tests run automatically on every push via GitHub Actions. The CI pipeline:
  1. Runs Python linting (flake8)
  2. Runs all unit tests
  3. Runs all contract tests
  4. Runs Slither static analysis
  5. Generates coverage reports

Writing Tests

Python Test Example

tests/unit/test_example.py
import pytest
from services.text_analysis import calculate_levenshtein_distance

@pytest.mark.unit
def test_levenshtein_distance():
    """Test Levenshtein distance calculation."""
    result = calculate_levenshtein_distance("kitten", "sitting")
    assert result == 3

@pytest.mark.unit
def test_levenshtein_empty_strings():
    """Test with empty strings."""
    result = calculate_levenshtein_distance("", "hello")
    assert result == 5

Contract Test Example

contracts/test/example.test.js
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("PredictionMarketV2", function () {
  it("Should create a new market", async function () {
    const [owner] = await ethers.getSigners();
    const Market = await ethers.getContractFactory("PredictionMarketV2");
    const market = await Market.deploy();
    
    const tx = await market.createMarket(
      "elonmusk",
      "What will Elon post?",
      Math.floor(Date.now() / 1000) + 86400
    );
    
    await expect(tx)
      .to.emit(market, "MarketCreated")
      .withArgs(1, owner.address, "elonmusk");
  });
});

Load Testing

Proteus includes load tests using Locust:
# Install locust (included in test dependencies)
pip install -e ".[test]"

# Run load tests
locust -f tests/load/locustfile.py --host=http://localhost:5000
Open http://localhost:8089 to configure and run load tests.

Debugging Tests

Python Debugging

# Verbose output with full tracebacks
pytest tests/ -vv --tb=long

Contract Debugging

// Add console.log to contracts (Hardhat feature)
console.log("Market ID:", marketId);
console.log("Distance:", distance);

// Run tests to see output
npx hardhat test

Next Steps

Local Setup

Set up your development environment

Architecture

Understand the system design

Deployment

Deploy contracts and backend

Contributing

Contribute to Proteus

Build docs developers (and LLMs) love