Test Overview
Proteus has a comprehensive test suite with 259+ passing tests covering smart contracts, backend services, and integrations.
Test Suite Tests Status Python Unit 135 ✅ Passing Smart Contracts 109 ✅ Passing Integration 15 ✅ Passing (2 expected skips) Total 259 All passing
Quick Start
all-tests
python-only
contracts-only
# 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:
Integration Tests
Integration tests require a running Flask server:
Start the Server
In terminal 1, start the Flask server: source .venv/bin/activate
python main.py
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:
Test Coverage
Generate a coverage report to see which code is tested:
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:
specific-file
pattern-match
markers
stop-on-failure
# 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
Run Specific Contract Tests
prediction-market
genesis-nft
payout-manager
# 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:
Operation Approximate 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:
Report is generated at coverage/index.html.
Test Markers
Pytest markers help organize and run specific test categories:
Marker Description Usage @pytest.mark.unitFast tests, no external deps pytest -m unit@pytest.mark.integrationRequire running server pytest -m integration@pytest.mark.e2eEnd-to-end tests pytest -m e2e@pytest.mark.slowLong-running tests pytest -m "not slow"
Continuous Integration
Tests run automatically on every push via GitHub Actions. The CI pipeline:
Runs Python linting (flake8)
Runs all unit tests
Runs all contract tests
Runs Slither static analysis
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
print-debugging
pdb
# 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