Skip to content

Commit

Permalink
docs: improve testing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
louise-poole committed Jan 16, 2025
1 parent 98c63c6 commit 2b6ebde
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion substreams/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion substreams/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
33 changes: 23 additions & 10 deletions testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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 system’s PATH.
- Latest version of our tycho-indexer binary, placed in a directory that is included in your system’s PATH.
- Access to PropellerHeads' private PyPI repository. Please contact us to obtain access.
- Docker installed on your machine.
- [Conda](https://conda.io/projects/conda/en/latest/user-guide/install/index.html)
Expand All @@ -34,7 +34,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

Expand All @@ -50,24 +50,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 don’t have it yet, please refer to the [setup testing
environment section](#setup-testing-environment)
This section requires a testing environment setup. If you don’t 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

Expand All @@ -82,15 +87,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 your root directory.

```bash
python ./testing/src/runner/cli.py --package "your-package-name"
Expand All @@ -104,7 +115,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"
```

Expand Down
6 changes: 4 additions & 2 deletions testing/postgres.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion testing/setup_env.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# To run: ./setup_env.sh

command_exists() {
command -v "$1" >/dev/null 2>&1
Expand Down Expand Up @@ -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."
6 changes: 4 additions & 2 deletions testing/src/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def simulate_get_amount_out(
self.config.adapter_build_signature,
self.config.adapter_build_args,
)

TychoDBSingleton.clear_instance()

decoder = ThirdPartyPoolTychoDecoder(
Expand All @@ -270,7 +270,9 @@ def simulate_get_amount_out(
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
Expand Down

0 comments on commit 2b6ebde

Please sign in to comment.