Skip to content

Commit ffd6da9

Browse files
authored
docs: improve testing docs (propeller-heads#133)
1 parent 98c63c6 commit ffd6da9

File tree

6 files changed

+36
-18
lines changed

6 files changed

+36
-18
lines changed

substreams/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substreams/Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ For forked protocols you'll need to also supply the config file name, e.g. `ethe
2626

2727
## Test your implementation
2828

29-
To run a full end-to-end integration test you can refer to the [testing script documentation](../testing/README.md)
29+
To run a full end-to-end integration test you can refer to the [testing script documentation](../testing/README.md).

testing/README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ Additionally, it will also try to simulate some transactions using the `SwapAdap
1111

1212
## Prerequisites
1313

14-
- 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.
15-
- Access to PropellerHeads' private PyPI repository. Please contact us to obtain access.
14+
- Latest version of our tycho-indexer binary, placed in a directory that is included in your system’s 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.
1615
- Docker installed on your machine.
1716
- [Conda](https://conda.io/projects/conda/en/latest/user-guide/install/index.html)
1817
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.
3433
Our testing script should be able to build it using your test config.
3534
The script to generate this file manually is available under `evm/scripts/buildRuntime.sh`.
3635

37-
## Setup testing environment
36+
## Set up testing environment
3837

3938
## Prerequisites
4039

@@ -50,24 +49,29 @@ Before setting up the Python environment, ensure the following tools and librari
5049
- **pip**: Python package installer (https://pip.pypa.io/)
5150

5251
Run the setup env script. It will create a conda virtual env and install all dependencies.
52+
```bash
53+
./setup_env.sh
54+
```
55+
5356
This script must be run from within the `tycho-protocol-sdk/testing` directory.
5457

55-
```
56-
setup_env.sh
58+
Lastly, you need to activate the conda env:
59+
```bash
60+
conda activate tycho-protocol-sdk-testing
5761
```
5862

5963
## Running Tests
6064

6165
### Prerequisites
6266

63-
This section requires a testing environment setup. If you don’t have it yet, please refer to the [setup testing
64-
environment section](#setup-testing-environment)
67+
This section requires a testing environment setup. If you don’t have it yet, please refer to the [set up testing
68+
environment section](#set-up-testing-environment).
6569

6670
### Step 1: Export Environment Variables
6771

6872
Export the required environment variables for the execution. You can find the available environment variables in the
6973
`.env.default` file.
70-
Please create a `.env` file in the `testing` directory and set the required environment variables.
74+
Please create a `.env` file inside the `testing` directory and set the required environment variables.
7175

7276
#### Environment Variables
7377

@@ -82,15 +86,21 @@ Please create a `.env` file in the `testing` directory and set the required envi
8286
- **Description**: The API token for accessing Substreams services. This token is required for authentication.
8387
- **Example**: `export SUBSTREAMS_API_TOKEN=eyJhbGci...`
8488

85-
### Step 2: Run tests
89+
### Step 2: Set up tests
8690

87-
Run local postgres database using docker compose
91+
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:
92+
```bash
93+
cargo build --target wasm32-unknown-unknown --release
94+
```
8895

96+
Then, run a local postgres test database using docker compose. This needs to be done from within the testing directory.
8997
```bash
9098
docker compose up -d db
9199
```
92100

93-
Run tests for your package.
101+
### Step 3: Run tests
102+
103+
Run tests for your package. This must be done from the main project directory.
94104

95105
```bash
96106
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:
104114
conda activate tycho-protocol-sdk-testing
105115
export RPC_URL="https://ethereum-mainnet.core.chainstack.com/123123123123"
106116
export SUBSTREAMS_API_TOKEN=eyJhbGci...
117+
cd testing
107118
docker compose up -d db
119+
cd ..
108120
python ./testing/src/runner/cli.py --package "ethereum-balancer-v2"
109121
```
110122

testing/postgres.Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# This Dockerfile creates a custom postgres image used for CI and local deployment.
2-
# This is required because we use some postgres extensions that aren't in the generic Postgres image such as pg_partman or pg_cron.
2+
# This is required because we use some postgres extensions that aren't in the generic
3+
# Postgres image such as pg_partman or pg_cron.
34

4-
# 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.
5+
# As an image with pg_partman already exist, we start from this one and add pg_cron
6+
# and possibly other extensions on top of that.
57
FROM ghcr.io/dbsystel/postgresql-partman:15-5
68
ARG PGCRON_VERSION="1.6.2"
79
USER root

testing/setup_env.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
# To run: ./setup_env.sh
23

34
command_exists() {
45
command -v "$1" >/dev/null 2>&1
@@ -45,4 +46,5 @@ echo "Installing the requirements from ${REQUIREMENTS_FILE}..."
4546
pip install -r $REQUIREMENTS_FILE --index-url https://pypi.org/simple
4647
conda activate $ENV_NAME
4748

48-
echo "Setup complete."
49+
echo "Setup complete."
50+
echo "Run 'conda activate $ENV_NAME' to activate the environment."

testing/src/runner/runner.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def simulate_get_amount_out(
247247
self.config.adapter_build_signature,
248248
self.config.adapter_build_args,
249249
)
250-
250+
251251
TychoDBSingleton.clear_instance()
252252

253253
decoder = ThirdPartyPoolTychoDecoder(
@@ -270,7 +270,9 @@ def simulate_get_amount_out(
270270
for sell_token, buy_token in itertools.permutations(pool_state.tokens, 2):
271271
for prctg in ["0.001", "0.01", "0.1"]:
272272
# Try to sell 0.1% of the protocol balance
273-
sell_amount = Decimal(prctg) * pool_state.balances[sell_token.address]
273+
sell_amount = (
274+
Decimal(prctg) * pool_state.balances[sell_token.address]
275+
)
274276
try:
275277
amount_out, gas_used, _ = pool_state.get_amount_out(
276278
sell_token, sell_amount, buy_token

0 commit comments

Comments
 (0)