* refactor: Misc improvements to code - Decouple validating logic from TychoRunner - Move all data fetching and decoding the tycho message into the same method - Split validate_state into validate_state, validate_token_balances and simulate_and_execute - Make rpc_provider and runtime attributes of TestRunner - Add references where possible to avoid clones - Remove unnecessary code - Make clippy happy #time 2h 36m #time 0m #time 3m * chore: Use tycho deps and foundry from tycho_simulation This is to try to decrease the risk of using conflicting versions in the different repositories #time 32m #time 0m * chore: Read RPC_URL in main.rs #time 10m * fix: Support eth trades (skip balance and allowance overwrites) and set balance overwrite to amount in For tokens like USDC setting the balance super high was making us getting blacklisted #time 1h 12m * fix: Fix curve tests and filter components_by_id with the expected_component_ids #time 1h 30m #time 0m * fix: Don't use all the possible executor addresses. Hardcode just one for the test Refactor overwrites logic: - renamed functions - moved logic around that fits together - don't use StateOverrides and then convert to alloy overrides. Use alloy's directly #time 1h 21m * fix: Assume that the executors mapping starts at storage value 1 Move setup_router_overwrites away from the rpc and into the execution file Delete unnecessary get_storage_at #time 33m
Protocol Testing
Rust-based integration testing framework for Tycho protocol implementations.
How to Run
# Build the images, from the project root dir
docker buildx build -f protocol-testing/postgres.Dockerfile -t protocol-testing-db:latest --load .
docker buildx build -f protocol-testing/run.Dockerfile -t protocol-testing-test-runner:latest --load .
# Export necessary env vars
export RPC_URL=..
export SUBSTREAMS_API_TOKEN=..
export PROTOCOLS="ethereum-balancer-v2=weighted_legacy_creation ethereum-ekubo-v2"
# Start and show the test logs only
docker compose up -d && docker compose logs test-runner --follow
# Clean up
docker compose down
Test Output Formatting
The test runner outputs results similar to:
Running 2 tests ...
--------------------------------
TEST 1: balancer_weighted_pool_test
✅ Protocol component validation passed.
✅ Token balance validation passed.
Amount out for 0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014: calculating for tokens "BAL"/"WETH"
Spot price "BAL"/"WETH": 0.123456
✅ Simulation validation passed.
✅ balancer_weighted_pool_test passed.
--------------------------------
Tests finished!
RESULTS: 2/2 passed.
Module-specific Logging
# Enable debug logs for specific modules
export RUST_LOG=protocol_testing=debug,tycho_client=info
# Disable logs for noisy modules
export RUST_LOG=info,hyper=warn,reqwest=warn
Running with Different Log Levels
# Standard test run with progress output
RUST_LOG=info cargo run -- --package uniswap-v2
# Detailed debug output
RUST_LOG=debug cargo run -- --package uniswap-v2
# Minimal output (errors only)
RUST_LOG=error cargo run -- --package uniswap-v2
Test Configuration
Tests are configured via YAML files located in the substreams package directory:
- Test configuration:
../substreams/<package>/integration_test.tycho.yaml - Substreams configuration:
../substreams/<package>/substreams.yaml
What the Tests Do
- Component Validation: Verifies that all expected protocol components are present in Tycho after indexing
- State Validation: Compares indexed component states against expected values
- Balance Verification: Validates token balances by querying the blockchain directly (can be skipped)
- Simulation Testing: Runs Tycho simulation engine to verify protocol functionality
Troubleshooting
- Database Connection Issues: Ensure PostgreSQL is running via
docker-compose up -d - RPC Errors: Verify
RPC_URLis set and accessible - Missing Substreams: Check that the package directory exists in
../substreams/<package>/ - Build Failures: Ensure all dependencies are installed and environment variables are set