3. Testing
We provide a comprehensive testing suite for Substreams modules. The testing suite facilitates end-to-end testing, ensuring your Substreams modules function as expected. For unit tests, please use standard Rust unit testing practices.
Overview
The testing suite will run Tycho Indexer with your provided Substream implementation for a specific block range and verify that the state matches the expected state specified on the testing YAML file.
It will also try to simulate transactions using Tycho Simulation engine, verifying the functionality of the provided SwapAdapter
contract.
Prerequisites
Before continuing, ensure the following tools and libraries are installed on your system:
Docker: Containerization platform for running applications in isolated environments.
Conda: Package and environment manager for Python and other languages.
AWS CLI: Tool to manage AWS services from the command line.
Git: Version control tool
Rust: Programming language and toolchain
GCC: GNU Compiler Collection
libpq: PostgreSQL client library
OpenSSL (libssl): OpenSSL development library
pkg-config: Helper tool for managing compiler flags
Conda: Python package manager
pip: Python package installer
Archive node
The testing system relies on an EVM Archive node to fetch the state from a previous block. Indexing only with Substreams, as done in Tycho's production mode, requires syncing blocks since the protocol's deployment date, which can take a long time. The node skips this requirement by fetching all the required account's storage slots on the block specified in the testing yaml
file.
The node also needs to support the debug_storageRangeAt method, as it's a requirement for our Token Quality Analysis.
Tycho Indexer
Verify the current version
The testing module runs a minified version of Tycho Indexer. You can ensure that the latest version is correctly setup in your PATH by running the following command on your terminal:
Installing or updating the version (Optional)
If the command above does not provide the expected output, you need to (re)install Tycho.
If you're running on a MacOS (either Apple Silicon or Intel) - or any architecture that is not supported by pre-built releases, you need to compile the Tycho Indexer:
Step 1: Clone Tycho-Indexer repo
Step 2: Build the binary in release mode
Step 3: Link the binary to a directory in your system's PATH:
NOTE: This command requires
/usr/local/bin
to be included in the system'sPATH.
While this is typically the case, there may be exceptions.If
/usr/local/bin
is not in yourPATH
, you can either:
Add it to your
PATH
by exporting it:Or create a symlink in any of the following directories (if they are in your
PATH
):
Step 4: Verify Installation
Test Configuration
Tests are defined in a yaml
file. A documented template can be found at substreams/ethereum-template/integration_test.tycho.yaml
. The configuration file should include:
The target Substreams config file.
The corresponding SwapAdapter and args to build it.
The expected protocol types.
The tests to be run.
Each test will index all blocks between start-block
and stop-block
, verify that the indexed state matches the expected state, and optionally simulate transactions using the provided SwapAdapter
.
You will also need the VM Runtime file for the adapter contract. Our testing script should be able to build it using your test config. The script to generate this file manually is available under evm/scripts/buildRuntime.sh
.
Setup testing environment
To set up your test environment, run the setup environment script. It will create a Conda virtual env and install all the required dependencies.
This script must be run from within the tycho-protocol-sdk/testing
directory.
Lastly, you need to activate the conda env:
Running Tests
Step 1: Export Environment Variables
Export the required environment variables for the execution. You can find the available environment variables in the .env.default
file. Please create a .env
file in the testing
directory and set the required environment variables.
Environment Variables
RPC_URL
Description: The URL for the Ethereum RPC endpoint. This is used to fetch the storage data.
The node needs to be an archive node and support debug_storageRangeAt method.
Example:
export RPC_URL="https://ethereum-mainnet.core.chainstack.com/123123123123"
SUBSTREAMS_API_TOKEN
Description: The JWT token for accessing Substreams services. This token is required for authentication. Please refer to Substreams Authentication guide to setup and validate your token.
Example:
export SUBSTREAMS_API_TOKEN=eyJhbGci...
Step 2: Set up tests
If you do not have one already, you must build the wasm file of the package you wish to test. This can be done by navigating to the package directory and running:
Then, run a local Postgres test database using docker-compose. This needs to be done from within the testing directory.
Step 3: Run tests
Run tests for your package. This must be done from the main project directory.
Example
If you want to run tests for ethereum-balancer-v2
, use:
Testing CLI args
A list and description of all available CLI args can be found using:
For enhanced debugging, running the testing module with the --tycho-logs flag is recommended. It will enable Tycho-indexer logs
Last updated