diff --git a/.env b/.env index 86b4545..60dbe08 100644 --- a/.env +++ b/.env @@ -2,11 +2,11 @@ COMPOSE_FILE=network.yml:contracts.yml:subnet-topos.yml:subnet-incal.yml:executo COMPOSE_PROJECT_NAME=infra # Topos Subnet -export TOPOS_HOST_PORT=10002 +TOPOS_HOST_PORT=10002 TOPOS_CHAIN_ID=2357 # Incal -export INCAL_HOST_PORT=20002 +INCAL_HOST_PORT=20002 INCAL_CHAIN_ID=2358 INCAL_LOGO_URL=https://toposware.com/logo-incal.svg @@ -25,7 +25,7 @@ REDIS_PORT=6379 TOPOS_EDGE_VERSION=1.3.0-topos # Find latest here: https://github.com/topos-protocol/topos-smart-contracts/releases -TOPOS_MESSAGING_PROTOCOL_CONTRACTS_VERSION=3.3.0 +TOPOS_MESSAGING_PROTOCOL_CONTRACTS_VERSION=3.2.0 # Find latest here: https://github.com/topos-protocol/topos/releases TOPOS_VERSION=0.0.11 @@ -34,4 +34,4 @@ TOPOS_VERSION=0.0.11 EXECUTOR_SERVICE_VERSION=1.2.0 # TESTS -export LOCAL_ERC20_HOME=./ +LOCAL_ERC20_HOME=./ diff --git a/.env.secrets b/.env.secrets index b6c4d1f..1a15605 100644 --- a/.env.secrets +++ b/.env.secrets @@ -1,8 +1,8 @@ -export PRIVATE_KEY=0xd7e2e00b43c12cf17239d4755ed744df6ca70a933fc7c8bbb7da1342a5ff2e38 -export TOKEN_DEPLOYER_SALT=m1Ln9uF9MGZ2PcR -export TOPOS_CORE_SALT=dCyN8VZz5sXgqMO -export TOPOS_CORE_PROXY_SALT=aRV8Mp9o4xRpLbF -export ERC20_MESSAGING_SALT=ho37cJbGkgI6vnp -export SUBNET_REGISTRATOR_SALT=azsRlXyGu0ty291 -export AUTH0_CLIENT_ID=xVF6EuPDaazQchfjFpGAdcJUpHk2W5I2 -export AUTH0_CLIENT_SECRET=-CrwnrgSx1EaP_oaKAFXFdqrIvA4WK8Pcpd5xC4o3ZfYB4H4V4FPHfEbqpu4KZN8 +PRIVATE_KEY=0xd7e2e00b43c12cf17239d4755ed744df6ca70a933fc7c8bbb7da1342a5ff2e38 +TOKEN_DEPLOYER_SALT=m1Ln9uF9MGZ2PcR +TOPOS_CORE_SALT=dCyN8VZz5sXgqMO +TOPOS_CORE_PROXY_SALT=aRV8Mp9o4xRpLbF +ERC20_MESSAGING_SALT=ho37cJbGkgI6vnp +SUBNET_REGISTRATOR_SALT=azsRlXyGu0ty291 +AUTH0_CLIENT_ID=xVF6EuPDaazQchfjFpGAdcJUpHk2W5I2 +AUTH0_CLIENT_SECRET=-CrwnrgSx1EaP_oaKAFXFdqrIvA4WK8Pcpd5xC4o3ZfYB4H4V4FPHfEbqpu4KZN8 diff --git a/.github/workflows/test:e2e.yml b/.github/workflows/test:e2e.yml index 28ca17f..36dbfef 100644 --- a/.github/workflows/test:e2e.yml +++ b/.github/workflows/test:e2e.yml @@ -17,4 +17,4 @@ jobs: workflow_file_name: frontend:erc20-messaging.yml ref: main wait_interval: 60 - client_payload: '{ "local-erc20-messaging-infra-ref": "${{ github.head_ref }}" }' + client_payload: '{ "local-erc20-messaging-infra-ref": "${{ github.head_ref }}", "e2e-test-type": "light" }' diff --git a/scripts/sequencer-init.sh b/scripts/sequencer-init.sh new file mode 100755 index 0000000..a52c419 --- /dev/null +++ b/scripts/sequencer-init.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# This script is used to initialize a sequencer node in local-ERC20 tests +# It replaces the default topos command by this script manipulating resources +# and updating configurations. +# +# What it does: +# 1. Install net-tools package to use netstat command in the healthcheck +# 2. Copy consensus and libp2p directories from $DATA_FOLDER to $CONFIG_FOLDER +# 3. Copy genesis.json from $GENESIS_FOLDER to $SUBNET_FOLDER +# 4. Start the sequencer node using topos node up command + +set -e + +if [[ -z "${SUBNET}" ]]; then + echo "SUBNET is not set" + exit 1 +fi + +if [[ -z "${CONFIG_FOLDER}" ]]; then + echo "CONFIG_FOLDER is not set" + exit 1 +fi + +if [[ -z "${DATA_FOLDER}" ]]; then + echo "DATA_FOLDER is not set" + exit 1 +fi + +if [[ -z "${GENESIS_FOLDER}" ]]; then + echo "GENESIS_FOLDER is not set" + exit 1 +fi + +if [[ -z "${SUBNET_FOLDER}" ]]; then + echo "SUBNET_FOLDER is not set" + exit 1 +fi + +apt-get update +apt-get install -y net-tools +source /contracts/.env + +mkdir -p $CONFIG_FOLDER/node/sequencer-$SUBNET/consensus -p $CONFIG_FOLDER/node/sequencer-$SUBNET/libp2p -p $SUBNET_FOLDER + +cp -vr $DATA_FOLDER/consensus $CONFIG_FOLDER/node/sequencer-$SUBNET/ +cp -vr $DATA_FOLDER/libp2p $CONFIG_FOLDER/node/sequencer-$SUBNET/ +cp -vr $GENESIS_FOLDER/genesis.json $SUBNET_FOLDER/genesis.json + +cp -f $CONFIG_FOLDER/node/sequencer-$SUBNET/config.toml $CONFIG_FOLDER/node/sequencer-$SUBNET/config.toml.new +sed -i -e '/subnet-contract-address =/ s/= .*/= "'$TOPOS_CORE_PROXY_CONTRACT_ADDRESS'"/' $CONFIG_FOLDER/node/sequencer-$SUBNET/config.toml.new +cp -f $CONFIG_FOLDER/node/sequencer-$SUBNET/config.toml.new $CONFIG_FOLDER/node/sequencer-$SUBNET/config.toml + +echo "Topos Core contract address: $TOPOS_CORE_PROXY_CONTRACT_ADDRESS, set manually in config" + +topos node up --name sequencer-$SUBNET --home $CONFIG_FOLDER --no-edge-process + diff --git a/subnet-incal.yml b/subnet-incal.yml index e2c4696..bd9e6e7 100644 --- a/subnet-incal.yml +++ b/subnet-incal.yml @@ -161,6 +161,7 @@ services: container_name: incal-sequencer init: true volumes: + - ./scripts/sequencer-init.sh:/tmp/init.sh - contracts:/contracts - incal-data:/data - ./node_config/node/sequencer-incal/config.toml:/tmp/node_config/node/sequencer-incal/config.toml @@ -173,21 +174,18 @@ services: condition: service_completed_successfully incal-node-4: condition: service_healthy - entrypoint: "" - command: bash -c " - apt-get update && apt-get install -y net-tools && - source /contracts/.env && - cp -vr /data/data-1/consensus /tmp/node_config/node/sequencer-incal/consensus && - cp -vr /data/data-1/libp2p /tmp/node_config/node/sequencer-incal/libp2p && - mkdir -p /tmp/node_config/subnet/incal/ && - cp -v /data/genesis.json /tmp/node_config/subnet/incal/genesis.json && - echo Topos core contract address=$(printenv TOPOS_CORE_PROXY_CONTRACT_ADDRESS), set manually in config && - topos node up --name sequencer-incal --home /tmp/node_config --no-edge-process" + entrypoint: "bash -c" + command: /tmp/init.sh healthcheck: test: ["CMD-SHELL", "test $(netstat -ntu | grep ':8545' | wc -l) -gt 0"] interval: 1s retries: 10 environment: + - SUBNET=incal + - DATA_FOLDER=/data/data-1 + - CONFIG_FOLDER=/tmp/node_config + - GENESIS_FOLDER=/data + - SUBNET_FOLDER=/tmp/node_config/subnet/incal - RUST_LOG=info,topos=debug - TOOLCHAIN_VERSION=stable - RUST_BACKTRACE=full diff --git a/subnet-topos.yml b/subnet-topos.yml index 425b2db..3d40b6c 100644 --- a/subnet-topos.yml +++ b/subnet-topos.yml @@ -226,6 +226,7 @@ services: container_name: topos-sequencer init: true volumes: + - ./scripts/sequencer-init.sh:/tmp/init.sh - contracts:/contracts - topos-data:/data - ./node_config/node/sequencer-topos/config.toml:/data/node/sequencer-topos/config.toml @@ -234,21 +235,18 @@ services: condition: service_healthy contracts-topos: condition: service_completed_successfully - entrypoint: "" - command: bash -c " - apt-get update && apt-get install -y net-tools && - source /contracts/.env && - mkdir -p /data/node/sequencer-topos/consensus -p /data/node/sequencer-topos/libp2p -p /data/subnet/topos-sequencer/ && - cp -vr /data/node/node-1/consensus /data/node/sequencer-topos/ && - cp -vr /data/node/node-1/libp2p /data/node/sequencer-topos/ && - cp -vr /data/subnet/topos/genesis.json /data/subnet/topos-sequencer/genesis.json && - echo \"Topos Core contract address:\" $(printenv TOPOS_CORE_PROXY_CONTRACT_ADDRESS), set manually in config && - topos node up --name sequencer-topos --home /data/ --no-edge-process" + entrypoint: "bash -c" + command: /tmp/init.sh healthcheck: test: ["CMD-SHELL", "test $(netstat -ntu | grep ':8545' | wc -l) -gt 0"] interval: 1s retries: 10 environment: + - SUBNET=topos + - DATA_FOLDER=/data/node/node-1 + - CONFIG_FOLDER=/data + - GENESIS_FOLDER=/data/subnet/topos + - SUBNET_FOLDER=/data/subnet/topos-sequencer - RUST_LOG=info,topos=debug - TOOLCHAIN_VERSION=stable - RUST_BACKTRACE=full diff --git a/tests/README.md b/tests/README.md index cf7fbed..5e8397a 100644 --- a/tests/README.md +++ b/tests/README.md @@ -19,7 +19,7 @@ $ npm install Then, edit the `.env` file to your liking. The default values should work for most cases. Then, source the `.env` file: ```sh -$ source .env +$ source ./tests/environment.sh ``` To run the tests, execute the tests from the root of the repository: @@ -29,6 +29,11 @@ $ ./tests/.sh # e.g. ./tests/test_network_health.sh ``` +After your tests if you want to unset the environment variables: + +```sh +source ./tests/environment.sh unset +``` ### Notes - The tests use TypeScript scripts to interact with the infrastructure. These scripts can be found in the `./scripts` directory. Currently, there are two main scripts available: diff --git a/tests/environment.sh b/tests/environment.sh new file mode 100755 index 0000000..3be4a47 --- /dev/null +++ b/tests/environment.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# This script is used to set up the environment variables for the local test environment +# It reads the .env and .env.secrets files and sets the environment variables accordingly +# If the first argument is "unset", it will unset the environment variables instead of setting them + +if test -f .env; then + if [ "$1" = "unset" ]; then + echo "Unsetting local test environment based on .env file" + unset $(grep -v '^#' .env | sed -E 's/(.*)=.*/\1/' | xargs) + else + echo "Setting up local test environment based on .env file" + export $(grep -v '^#' .env | xargs) + fi +else + echo ".env file doesn't exists, this command do nothing" +fi + +if test -f .env.secrets; then + if [ "$1" = "unset" ]; then + echo "Unsetting local test environment based on .env.secrets file" + unset $(grep -v '^#' .env.secrets | sed -E 's/(.*)=.*/\1/' | xargs) + else + echo "Setting up local test environment based on .env.secrets file" + export $(grep -v '^#' .env.secrets | xargs) + fi +fi diff --git a/tests/network.sh b/tests/network.sh index b777874..74e87fa 100755 --- a/tests/network.sh +++ b/tests/network.sh @@ -1,21 +1,27 @@ #!/bin/bash set -e +if [[ -z "${LOCAL_ERC20_HOME}" ]]; then + echo "You need to setup the environment first. For local tests: source ./tests/environment.sh" + exit 1 +fi + source $LOCAL_ERC20_HOME/tests/utils.sh -if [ $1 = 'start' ]; then +if [ "$1" = 'start' ]; then start_network exit $? -elif [ $1 = 'stop' ]; then +elif [ "$1" = 'stop' ]; then stop_network exit $? -elif [ $1 = 'check' ]; then +elif [ "$1" = 'check' ]; then check_network_health exit $? -elif [ $1 = 'is_running' ]; then +elif [ "$1" = 'is_running' ]; then is_network_running exit $? else echo "Invalid argument" + echo "Usage: network.sh [start|stop|check|is_running]" exit 1 fi diff --git a/tests/test_cert_delivery.sh b/tests/test_cert_delivery.sh index 088f912..857c2a8 100755 --- a/tests/test_cert_delivery.sh +++ b/tests/test_cert_delivery.sh @@ -1,8 +1,12 @@ #!/bin/bash set -e -source $LOCAL_ERC20_HOME/tests/utils.sh +if [[ -z "${LOCAL_ERC20_HOME}" ]]; then + echo "You need to setup the environment first. For local tests: source ./tests/environment.sh" + exit 1 +fi +source $LOCAL_ERC20_HOME/tests/utils.sh function get_last_sequncer_generated_certificate () { # $1 - node name diff --git a/tests/test_cert_inclusion.sh b/tests/test_cert_inclusion.sh index d50371d..3b06093 100755 --- a/tests/test_cert_inclusion.sh +++ b/tests/test_cert_inclusion.sh @@ -1,6 +1,11 @@ #!/bin/bash set -e +if [[ -z "${LOCAL_ERC20_HOME}" ]]; then + echo "You need to setup the environment first. For local tests: source ./tests/environment.sh" + exit 1 +fi + source $LOCAL_ERC20_HOME/tests/utils.sh diff --git a/tests/test_cert_production.sh b/tests/test_cert_production.sh index af5174c..41265a6 100755 --- a/tests/test_cert_production.sh +++ b/tests/test_cert_production.sh @@ -1,6 +1,11 @@ #!/bin/bash set -e +if [[ -z "${LOCAL_ERC20_HOME}" ]]; then + echo "You need to setup the environment first. For local tests: source ./tests/environment.sh" + exit 1 +fi + source $LOCAL_ERC20_HOME/tests/utils.sh diff --git a/tests/test_cert_sequencer_delivery.sh b/tests/test_cert_sequencer_delivery.sh index 2e2ff12..a8def29 100755 --- a/tests/test_cert_sequencer_delivery.sh +++ b/tests/test_cert_sequencer_delivery.sh @@ -1,6 +1,11 @@ #!/bin/bash set -e +if [[ -z "${LOCAL_ERC20_HOME}" ]]; then + echo "You need to setup the environment first. For local tests: source ./tests/environment.sh" + exit 1 +fi + source $LOCAL_ERC20_HOME/tests/utils.sh diff --git a/tests/test_network_health.sh b/tests/test_network_health.sh index 5f6c6a5..00cc03a 100755 --- a/tests/test_network_health.sh +++ b/tests/test_network_health.sh @@ -1,6 +1,11 @@ #!/bin/bash set -e +if [[ -z "${LOCAL_ERC20_HOME}" ]]; then + echo "You need to setup the environment first. For local tests: source ./tests/environment.sh" + exit 1 +fi + source $LOCAL_ERC20_HOME/tests/utils.sh diff --git a/tests/test_transaction_in_certificate.sh b/tests/test_transaction_in_certificate.sh index 36b5dca..b357917 100755 --- a/tests/test_transaction_in_certificate.sh +++ b/tests/test_transaction_in_certificate.sh @@ -1,13 +1,18 @@ #!/bin/bash set -e +if [[ -z "${LOCAL_ERC20_HOME}" ]]; then + echo "You need to setup the environment first. For local tests: source ./tests/environment.sh" + exit 1 +fi + source $LOCAL_ERC20_HOME/tests/utils.sh function get_transaction_in_certificate() { echo $(docker compose logs incal-sequencer | grep "CrossSubnetMessageSentFilter" | \ - awk -F 'transaction_hash: ' '{print $2}' | awk -F ',' '{print $1'} | tail -1) + awk -F 'transaction_hash: ' '{print $2}' | awk -F ',' '{print $1}' | tail -1) } @@ -29,6 +34,11 @@ wait_network_healthy echo "Executing test of transaction inclusion in certificate..." check_artifacts topos_subnet_id=$(get_topos_subnet_id) + +echo "Checking connectivity with incal node 1" +echo "Dialing incal node 1 on localhost:$INCAL_HOST_PORT" +nc -z localhost $INCAL_HOST_PORT + tx_hash=$(send_token_with_retry 3 $topos_subnet_id $INCAL_HOST_PORT "txhash") transaction_valid=$? echo "Transaction send token result: $transaction_valid, tx hash: $tx_hash"