From bc2cd6bab255eea16fb673c599743c6b859fbe34 Mon Sep 17 00:00:00 2001 From: Florian Pellissier <111426680+flopell@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:20:55 +0200 Subject: [PATCH] refactor(testing): miscellaneous improvements and bugfixes Includes bugfix on `tycho-indexer-client` and `protosim_py`, a script to simplify setting up testing python env and cli improvements. Also add support for building runtime for SwapAdapters with many args that was bugged before. --- evm/scripts/buildRuntime.sh | 11 +++++++++-- testing/.env.default | 2 -- testing/requirements.txt | 4 ++-- testing/setup_env.sh | 35 +++++++++++++++++++++++++++++++++++ testing/src/runner/cli.py | 7 +++++-- testing/src/runner/models.py | 2 -- testing/src/runner/runner.py | 4 ++-- testing/src/runner/tycho.py | 7 +++++-- testing/src/runner/utils.py | 4 ++-- 9 files changed, 60 insertions(+), 16 deletions(-) create mode 100755 testing/setup_env.sh diff --git a/evm/scripts/buildRuntime.sh b/evm/scripts/buildRuntime.sh index 27089a6..49c12ac 100755 --- a/evm/scripts/buildRuntime.sh +++ b/evm/scripts/buildRuntime.sh @@ -31,8 +31,15 @@ echo "CONSTRUCTOR_ARGUMENTS: $CONSTRUCTOR_ARGUMENTS" # Perform operations if CONSTRUCTOR_SIGNATURE and CONSTRUCTOR_ARGUMENTS are set if [[ ! -z "$CONSTRUCTOR_SIGNATURE" && ! -z "$CONSTRUCTOR_ARGUMENTS" ]]; then - # Do some operations here - export __PROPELLER_DEPLOY_ARGS=$(cast abi-encode $CONSTRUCTOR_SIGNATURE $CONSTRUCTOR_ARGUMENTS) + # Split the CONSTRUCTOR_ARGUMENTS by commas into an array + IFS=',' read -r -a ARG_ARRAY <<< "$CONSTRUCTOR_ARGUMENTS" + + # Create the cast abi-encode command with the arguments + ENCODED_ARGS=$(cast abi-encode "$CONSTRUCTOR_SIGNATURE" "${ARG_ARRAY[@]}") + + # Export the encoded arguments + export __PROPELLER_DEPLOY_ARGS=$ENCODED_ARGS + echo "$ENCODED_ARGS" fi export __PROPELLER_CONTRACT="$CONTRACT_NAME.sol:$CONTRACT_NAME" diff --git a/testing/.env.default b/testing/.env.default index a192fe5..55deb9d 100644 --- a/testing/.env.default +++ b/testing/.env.default @@ -1,5 +1,3 @@ -export SUBSTREAMS_PACKAGE=ethereum-curve export RPC_URL=https://mainnet.infura.io/v3/your-infura-key -export DATABASE_URL: "postgres://postgres:mypassword@db:5432/tycho_indexer_0" export SUBSTREAMS_API_TOKEN="changeme" export DOMAIN_OWNER="AWSAccountId" \ No newline at end of file diff --git a/testing/requirements.txt b/testing/requirements.txt index aef7986..74df75b 100644 --- a/testing/requirements.txt +++ b/testing/requirements.txt @@ -2,5 +2,5 @@ psycopg2==2.9.9 PyYAML==6.0.1 Requests==2.32.2 web3==5.31.3 -tycho-indexer-client>=0.7.0 -protosim_py>=0.5.0 +tycho-indexer-client>=0.7.2 +protosim_py>=0.6.3 diff --git a/testing/setup_env.sh b/testing/setup_env.sh new file mode 100755 index 0000000..bd80b67 --- /dev/null +++ b/testing/setup_env.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Variables +ENV_NAME="propeller-protocol-lib-testing" +PYTHON_VERSION="3.9" +REQUIREMENTS_FILE="requirements.txt" +PRE_BUILD_SCRIPT="pre_build.sh" + +# Allow to run either from root or from inside testing folder. +if [ -f "./$REQUIREMENTS_FILE" ]; then + # If the requirements file is found in the current directory, do nothing + SCRIPT_DIR="." +elif [ -f "testing/$REQUIREMENTS_FILE" ]; then + # If the requirements file is found in testing/, adjust the paths + SCRIPT_DIR="testing" +else + echo "Error: Script must be run from the propeller-protocol-lib or propeller-protocol-lib/testing directory." + exit 1 +fi + +# Create conda environment +echo "Creating conda environment ${ENV_NAME} with Python ${PYTHON_VERSION}..." +conda create --name $ENV_NAME python=$PYTHON_VERSION -y + +# Activate the environment +echo "Activating the environment..." +source activate $ENV_NAME + +# Install the requirements +echo "Installing the requirements from ${SCRIPT_DIR}/${REQUIREMENTS_FILE}..." +./${SCRIPT_DIR}/${PRE_BUILD_SCRIPT} +pip install -r ${SCRIPT_DIR}/${REQUIREMENTS_FILE} +conda activate $ENV_NAME + +echo "Setup complete." \ No newline at end of file diff --git a/testing/src/runner/cli.py b/testing/src/runner/cli.py index 1fe82b6..66f08d0 100644 --- a/testing/src/runner/cli.py +++ b/testing/src/runner/cli.py @@ -8,10 +8,13 @@ def main() -> None: ) parser.add_argument("--package", type=str, help="Name of the package to test.") parser.add_argument( - "--tycho-logs", action="store_true", help="Flag to activate logs from Tycho." + "--tycho-logs", action="store_true", help="Enable Tycho logs." ) parser.add_argument( - "--db-url", type=str, help="Postgres database URL for the Tycho indexer." + "--db-url", + default="postgres://postgres:mypassword@localhost:5431/tycho_indexer_0", + type=str, + help="Postgres database URL for the Tycho indexer. Default: postgres://postgres:mypassword@localhost:5431/tycho_indexer_0", ) parser.add_argument( "--vm-traces", action="store_true", help="Enable tracing during vm simulations." diff --git a/testing/src/runner/models.py b/testing/src/runner/models.py index 6aeaae1..faa8ada 100644 --- a/testing/src/runner/models.py +++ b/testing/src/runner/models.py @@ -4,8 +4,6 @@ from hexbytes import HexBytes from pydantic import BaseModel, Field, validator from typing import List, Dict, Optional -from tycho_client.dto import ProtocolComponent - class ProtocolComponentExpectation(BaseModel): """Represents a ProtocolComponent with its main attributes.""" diff --git a/testing/src/runner/runner.py b/testing/src/runner/runner.py index 84eb340..12a15cf 100644 --- a/testing/src/runner/runner.py +++ b/testing/src/runner/runner.py @@ -14,7 +14,7 @@ from protosim_py.evm.decoders import ThirdPartyPoolTychoDecoder from protosim_py.evm.storage import TychoDBSingleton from protosim_py.models import EVMBlock from pydantic import BaseModel -from tycho_client.dto import ( +from tycho_indexer_client.dto import ( Chain, ProtocolComponentsParams, ProtocolStateParams, @@ -26,7 +26,7 @@ from tycho_client.dto import ( Snapshot, ContractId, ) -from tycho_client.rpc_client import TychoRPCClient +from tycho_indexer_client.rpc_client import TychoRPCClient from models import ( IntegrationTestsConfig, diff --git a/testing/src/runner/tycho.py b/testing/src/runner/tycho.py index 52512c4..a6cd2a1 100644 --- a/testing/src/runner/tycho.py +++ b/testing/src/runner/tycho.py @@ -27,12 +27,15 @@ def find_binary_file(file_name): # Check each location for location in locations: - potential_path = location + "/" + file_name + potential_path = os.path.join(location, file_name) if os.path.exists(potential_path): return potential_path # If binary is not found in the usual locations, return None - raise RuntimeError("Unable to locate tycho-indexer binary") + searched_paths = "\n".join(locations) + raise RuntimeError( + f"Unable to locate {file_name} binary. Searched paths:\n{searched_paths}" + ) binary_path = find_binary_file("tycho-indexer") diff --git a/testing/src/runner/utils.py b/testing/src/runner/utils.py index dc98bd6..09bba3c 100644 --- a/testing/src/runner/utils.py +++ b/testing/src/runner/utils.py @@ -3,7 +3,7 @@ from typing import Union from eth_utils import to_checksum_address from protosim_py.models import EthereumToken -from tycho_client.dto import ( +from tycho_indexer_client.dto import ( ResponseProtocolState, ProtocolComponent, ResponseAccount, @@ -13,7 +13,7 @@ from tycho_client.dto import ( TokensParams, PaginationParams, ) -from tycho_client.rpc_client import TychoRPCClient +from tycho_indexer_client.rpc_client import TychoRPCClient log = getLogger(__name__)