docs: improve testing docs (#133)

This commit is contained in:
Louise Poole
2025-01-16 15:49:46 +02:00
committed by GitHub
parent 98c63c685f
commit ffd6da916a
6 changed files with 36 additions and 18 deletions

2
substreams/Cargo.lock generated
View File

@@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
version = 3
[[package]]
name = "aho-corasick"

View File

@@ -26,4 +26,4 @@ For forked protocols you'll need to also supply the config file name, e.g. `ethe
## Test your implementation
To run a full end-to-end integration test you can refer to the [testing script documentation](../testing/README.md)
To run a full end-to-end integration test you can refer to the [testing script documentation](../testing/README.md).

View File

@@ -11,8 +11,7 @@ Additionally, it will also try to simulate some transactions using the `SwapAdap
## Prerequisites
- Latest version of our indexer, Tycho. Please contact us to obtain the latest version. Once acquired, place it in a directory that is included in your systems PATH.
- Access to PropellerHeads' private PyPI repository. Please contact us to obtain access.
- Latest version of our tycho-indexer binary, placed in a directory that is included in your systems PATH. Ask us for the binary, or follow [these instructions](https://github.com/propeller-heads/tycho-indexer/tree/main/tycho-indexer#build-tycho-indexer-binary) on our tycho-indexer repo.
- Docker installed on your machine.
- [Conda](https://conda.io/projects/conda/en/latest/user-guide/install/index.html)
and [AWS cli](https://aws.amazon.com/cli/) installed
@@ -34,7 +33,7 @@ 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
## Set up testing environment
## Prerequisites
@@ -50,24 +49,29 @@ Before setting up the Python environment, ensure the following tools and librari
- **pip**: Python package installer (https://pip.pypa.io/)
Run the setup env script. It will create a conda virtual env and install all dependencies.
```bash
./setup_env.sh
```
This script must be run from within the `tycho-protocol-sdk/testing` directory.
```
setup_env.sh
Lastly, you need to activate the conda env:
```bash
conda activate tycho-protocol-sdk-testing
```
## Running Tests
### Prerequisites
This section requires a testing environment setup. If you dont have it yet, please refer to the [setup testing
environment section](#setup-testing-environment)
This section requires a testing environment setup. If you dont have it yet, please refer to the [set up testing
environment section](#set-up-testing-environment).
### 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.
Please create a `.env` file inside the `testing` directory and set the required environment variables.
#### Environment Variables
@@ -82,15 +86,21 @@ Please create a `.env` file in the `testing` directory and set the required envi
- **Description**: The API token for accessing Substreams services. This token is required for authentication.
- **Example**: `export SUBSTREAMS_API_TOKEN=eyJhbGci...`
### Step 2: Run tests
### Step 2: Set up tests
Run local postgres database using docker compose
If you do not have one already, you will need to build the wasm file of the package you wish to test. This can be done by navigating to the package directory and running:
```bash
cargo build --target wasm32-unknown-unknown --release
```
Then, run a local postgres test database using docker compose. This needs to be done from within the testing directory.
```bash
docker compose up -d db
```
Run tests for your package.
### Step 3: Run tests
Run tests for your package. This must be done from the main project directory.
```bash
python ./testing/src/runner/cli.py --package "your-package-name"
@@ -104,7 +114,9 @@ If you want to run tests for `ethereum-balancer-v2`, use:
conda activate tycho-protocol-sdk-testing
export RPC_URL="https://ethereum-mainnet.core.chainstack.com/123123123123"
export SUBSTREAMS_API_TOKEN=eyJhbGci...
cd testing
docker compose up -d db
cd ..
python ./testing/src/runner/cli.py --package "ethereum-balancer-v2"
```

View File

@@ -1,7 +1,9 @@
# This Dockerfile creates a custom postgres image used for CI and local deployment.
# This is required because we use some postgres extensions that aren't in the generic Postgres image such as pg_partman or pg_cron.
# This is required because we use some postgres extensions that aren't in the generic
# Postgres image such as pg_partman or pg_cron.
# As an image with pg_partman already exist, we start from this one an add pg_cron and possibly other extensions on top of that.
# As an image with pg_partman already exist, we start from this one and add pg_cron
# and possibly other extensions on top of that.
FROM ghcr.io/dbsystel/postgresql-partman:15-5
ARG PGCRON_VERSION="1.6.2"
USER root

View File

@@ -1,4 +1,5 @@
#!/bin/bash
# To run: ./setup_env.sh
command_exists() {
command -v "$1" >/dev/null 2>&1
@@ -45,4 +46,5 @@ echo "Installing the requirements from ${REQUIREMENTS_FILE}..."
pip install -r $REQUIREMENTS_FILE --index-url https://pypi.org/simple
conda activate $ENV_NAME
echo "Setup complete."
echo "Setup complete."
echo "Run 'conda activate $ENV_NAME' to activate the environment."

View File

@@ -247,7 +247,7 @@ class TestRunner:
self.config.adapter_build_signature,
self.config.adapter_build_args,
)
TychoDBSingleton.clear_instance()
decoder = ThirdPartyPoolTychoDecoder(
@@ -270,7 +270,9 @@ class TestRunner:
for sell_token, buy_token in itertools.permutations(pool_state.tokens, 2):
for prctg in ["0.001", "0.01", "0.1"]:
# Try to sell 0.1% of the protocol balance
sell_amount = Decimal(prctg) * pool_state.balances[sell_token.address]
sell_amount = (
Decimal(prctg) * pool_state.balances[sell_token.address]
)
try:
amount_out, gas_used, _ = pool_state.get_amount_out(
sell_token, sell_amount, buy_token