Files
tycho-protocol-sdk/protocol-testing
Tamara eaca47479b feat: Simulate txs against RPC (#261)
* feat: (WIP) Simulate txs against RPC

* fix: include test_executor_addresses.json

We should probably fetch this from execution instead. Will do later

* feat: (WIP) Attempt to use TokenProxyOverwriteFactory

* feat: (WIP) Attempt to use TokenProxyOverwriteFactory

* feat: Add simulating execution using debug_traceCall

Decoded amount out from execution and compared with the one from simulation
Allow for printing the execution traces
Moved all execution methods into execution.rs
Created traces.rs (heavily clauded) that prints the traces nicely and gets the function selectors frm 4byte (I decided not to use EtherscanIdentifier from foundry because adding foundry as a dependency is really heavy and I expect problems because of it)

Temporary: hardcoded storage slots for test_weighted_pool_v4 to pass

#time 1h 55m

* feat: Use BalanceSlotDetector and AllowanceSlotDetector from tycho_ethereum

#time 1h 14m

* fix: Improve traces.rs

#time 2m

* feat: Add skip_execution

Also get tycho router bytecode at compile time

#time 22m

* test: Skip tests that are before the Shanghai upgrade

Remove unnecessary TODOs

#time 35m

* feat: Point tycho dependencies to specific commits

#time 9m

* fix: Set historical_trade to true in TychoRouterEncoderBuilder

#time 41m


#time 0m

* feat: Improve traces.rs (use foundry instead of 4bytes)

Improved the format of the printed trace as well

#time 1h 7m

* fix: After merge fixes

#time 3m

* feat: Use new executors_addresses in tycho-execution and read it at startup

#time 1h 25m

* feat: Create a new flag to enable execution_traces

#time 9m

* fix: Small code, log and trace improvements

Add trying to decode method's calldatas in tracing

#time 1m

* fix: Simplify simulate_transactions_with_tracing by introducing a new method: bytes_to_fixed_32

#time 13m

* fix: After merge fixes

#time 1m

* fix: Include executor's bytecode at compile time

#time 11m

---------

Co-authored-by: TAMARA LIPOWSKI <data.lipowski@extaccount.com>
Co-authored-by: Diana Carvalho <diana@propellerheads.xyz>
2025-09-23 15:57:43 +01:00
..
2025-09-23 15:57:43 +01:00
2025-09-03 08:55:29 -04:00
2025-09-16 11:31:19 +02:00
2025-09-16 11:31:19 +02:00
2025-09-03 08:55:29 -04:00

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

  1. Component Validation: Verifies that all expected protocol components are present in Tycho after indexing
  2. State Validation: Compares indexed component states against expected values
  3. Balance Verification: Validates token balances by querying the blockchain directly (can be skipped)
  4. 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_URL is 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