Testing Philosophy
The project usesjust commands for convenience, which automatically use cargo nextest:
Test Types
Unit Tests
Fast tests that don’t require external dependencies. They test individual functions and modules in isolation.- Pure functions and business logic
- Data structure operations
- Serialization/deserialization
- Mathematical calculations
Documentation Tests
Tests embedded in documentation comments. These ensure code examples in docs stay up-to-date.Documentation tests use
cargo test (not nextest) as nextest doesn’t support doc tests.Database Tests
Tests that require PostgreSQL. These test database interactions, migrations, and SQL queries.Prerequisites
Running Database Tests
Why
--test-threads 1? Database tests modify shared state (database tables). Running them in parallel could cause race conditions and test failures.Why --run-ignored ignored-only? Database tests are marked with #[ignore] because they require external PostgreSQL. This flag runs only ignored tests.End-to-End (E2E) Tests
E2E tests validate complete workflows by deploying contracts, running services, and executing real transactions. All E2E tests are located incrates/e2e/tests/.
E2E Local Node Tests
Tests that run against a clean local Ethereum node (no forking).- Order placement and settlement
- Solver competition
- Protocol interactions
- Contract deployments
E2E Forked Network Tests
Tests that fork real networks (Mainnet or Gnosis Chain) to test against production state.Prerequisites
Running Forked Tests
- Integration with real tokens (USDC, DAI, etc.)
- Real liquidity sources (Uniswap, Balancer)
- Actual contract addresses
- Production-like scenarios
The
ANVIL_COMMAND environment variable controls the anvil binary path. It defaults to "anvil" which must be in your PATH.Custom E2E Test Filters
Run specific E2E tests by name or pattern:Driver Tests
Specialized tests for the driver component that require extra stack space.Driver tests need
RUST_MIN_STACK=3145728 (3MB) because they perform complex simulations that can overflow the default stack.Flaky Test Workflow
Sometimes tests are flaky and fail intermittently in CI but pass locally. To test your fix:Run the GitHub Action
Go to: Actions → run-flaky-test in the GitHub repository.This workflow runs the test multiple times to verify stability.
.github/workflows/pull-request.yaml.
Test Organization
Tests are organized throughout the codebase:Test Helpers
testlib crate: Provides shared utilities for writing tests
- Mock HTTP servers
- Test fixtures
- Common assertions
- Helper functions
crates/e2e/src: E2E-specific helpers
- Node setup
- Contract deployment
- Service initialization
Running All Tests (Like CI)
To run the complete test suite locally:Writing Tests
Unit Test Example
Database Test Example
E2E Test Example
Test Coverage
While the project doesn’t enforce coverage metrics, aim for:- High coverage of business logic
- Critical paths well-tested
- Edge cases covered
- Error conditions tested
Best Practices
Keep tests fast
Unit tests should run in milliseconds. Use mocks for external dependencies.
Test one thing
Each test should verify a single behavior or scenario.
Use descriptive names
Test names should clearly describe what they test:
test_order_fails_when_expiredAvoid flaky tests
Don’t rely on timing, random data, or external state that can change.
Continuous Integration
The CI runs on every PR and push to main. See.github/workflows/pull-request.yaml for the complete pipeline:
- Lint: Formatting and clippy checks
- Doc tests: Documentation examples
- Unit tests: Fast unit tests
- Database tests: PostgreSQL integration
- E2E tests: Both local and forked
- Driver tests: Driver-specific tests
- Security: Trivy and cargo-audit scans
Troubleshooting
Test passes locally but fails in CI
Test passes locally but fails in CI
Likely causes:
- Using
cargo testinstead ofcargo nextest run - Test depends on local state or timing
- Test needs
--test-threads 1but runs in parallel
Database tests fail with connection errors
Database tests fail with connection errors
Check PostgreSQL is running:Reset database:
E2E forked tests timeout or fail
E2E forked tests timeout or fail
Check RPC URLs are set:Use a reliable RPC:
- Free public RPCs can be slow or rate-limited
- Consider using Infura, Alchemy, or running a local node
Driver tests stack overflow
Driver tests stack overflow
Ensure RUST_MIN_STACK is set:
Next Steps
Setup Guide
Set up your development environment
Playground
Test changes in a full local environment
Contributing
Submit your changes
E2E Tests
Detailed E2E test reference
