Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fixing typo and environment variables #61

Merged
merged 6 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -34,4 +34,4 @@ TOPOS_VERSION=0.0.11
EXECUTOR_SERVICE_VERSION=1.2.0

# TESTS
export LOCAL_ERC20_HOME=./
LOCAL_ERC20_HOME=./
16 changes: 8 additions & 8 deletions .env.secrets
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/test:e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}", "topos-smart-contracts-docker-tag": "3.2.0", "e2e-test-type": "light" }'
Freyskeyd marked this conversation as resolved.
Show resolved Hide resolved
57 changes: 57 additions & 0 deletions scripts/sequencer-init.sh
Original file line number Diff line number Diff line change
@@ -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

18 changes: 8 additions & 10 deletions subnet-incal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 8 additions & 10 deletions subnet-topos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -29,6 +29,11 @@ $ ./tests/<NAME_OF_TEST>.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:
Expand Down
27 changes: 27 additions & 0 deletions tests/environment.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 10 additions & 4 deletions tests/network.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion tests/test_cert_delivery.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cert_inclusion.sh
Original file line number Diff line number Diff line change
@@ -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


Expand Down
5 changes: 5 additions & 0 deletions tests/test_cert_production.sh
Original file line number Diff line number Diff line change
@@ -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


Expand Down
5 changes: 5 additions & 0 deletions tests/test_cert_sequencer_delivery.sh
Original file line number Diff line number Diff line change
@@ -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


Expand Down
5 changes: 5 additions & 0 deletions tests/test_network_health.sh
Original file line number Diff line number Diff line change
@@ -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


Expand Down
12 changes: 11 additions & 1 deletion tests/test_transaction_in_certificate.sh
Original file line number Diff line number Diff line change
@@ -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)
}


Expand All @@ -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"
Expand Down
Loading