Skip to content

Commit

Permalink
chore: adding documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Paitrault <[email protected]>
  • Loading branch information
Freyskeyd committed Feb 29, 2024
1 parent 004e12f commit 02609d5
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 35 deletions.
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: chore/debug-ci-1
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" }'
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
23 changes: 23 additions & 0 deletions tests/environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

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
10 changes: 10 additions & 0 deletions tests/test_transaction_in_certificate.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 Expand Up @@ -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

0 comments on commit 02609d5

Please sign in to comment.