Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
feat: add test for certificate block production (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
atanmarko authored Dec 14, 2023
1 parent ee2710b commit 5f5aa23
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ TOPOS_EDGE_VERSION=1.3.0-topos
TOPOS_MESSAGING_PROTOCOL_CONTRACTS_VERSION=3.0.0
TOPOS_VERSION=0.0.10
EXECUTOR_SERVICE_VERSION=1.0.0


# TESTS
export LOCAL_ERC20_HOME=./
17 changes: 11 additions & 6 deletions contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ services:
depends_on:
contracts-init:
condition: service_completed_successfully
topos-node-1:
condition: service_healthy
incal-node-1:
condition: service_healthy
topos-node-4:
condition: service_healthy
incal-node-4:
condition: service_healthy
networks:
- local-erc20-messaging-infra-docker

Expand All @@ -59,8 +59,13 @@ services:
volumes:
- incal-data:/data/incal
depends_on:
incal-node-1:
condition: service_healthy
incal-init:
condition: service_completed_successfully
contracts-init:
condition: service_completed_successfully
incal-node-4:
condition: service_healthy

networks:
- local-erc20-messaging-infra-docker

Expand Down
2 changes: 1 addition & 1 deletion node_config/node/boot/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ graphql-api-addr = "0.0.0.0:4030"
grpc-api-addr = "0.0.0.0:1340"
libp2p-api-addr = "0.0.0.0:9090"
metrics-api-addr = "0.0.0.0:3030"
minimum-tce-cluster-size = 2
minimum-tce-cluster-size = 3
11 changes: 11 additions & 0 deletions scripts/polygon_edge_healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e
block_number=$($1/polygon-edge status | grep 'Current Block Number (base 10) = .[0-9]*' | awk '{print $7}')

if [ $block_number -gt 0 ]
then
exit 0;
else
exit 1;
fi
26 changes: 24 additions & 2 deletions subnet-incal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ services:
- ${PRICE_LIMIT}
- "--seal"
healthcheck:
test: ./polygon-edge status | awk '/Number/ {print $$NF}' | tr -d '\n' | grep -v -w "0"
test: ./polygon-edge status | grep 'Current Block Number (base 10) = .[0-9]*'
interval: 5s
retries: 10
depends_on:
Expand Down Expand Up @@ -71,9 +71,15 @@ services:
- "--price-limit"
- ${PRICE_LIMIT}
- "--seal"
healthcheck:
test: ./polygon-edge status | grep 'Current Block Number (base 10) = .[0-9]*'
interval: 5s
retries: 10
depends_on:
incal-init:
condition: service_completed_successfully
incal-node-1:
condition: service_healthy
volumes:
- incal-data:/data
restart: on-failure
Expand All @@ -99,9 +105,15 @@ services:
- "--price-limit"
- ${PRICE_LIMIT}
- "--seal"
healthcheck:
test: ./polygon-edge status | grep 'Current Block Number (base 10) = .[0-9]*'
interval: 5s
retries: 10
depends_on:
incal-init:
condition: service_completed_successfully
incal-node-1:
condition: service_healthy
volumes:
- incal-data:/data
restart: on-failure
Expand All @@ -127,11 +139,19 @@ services:
- "--price-limit"
- ${PRICE_LIMIT}
- "--seal"
healthcheck:
test: |
/bin/sh /polygon_edge_healthcheck.sh .
interval: 5s
retries: 10
depends_on:
incal-init:
condition: service_completed_successfully
incal-node-1:
condition: service_healthy
volumes:
- incal-data:/data
- ./scripts/polygon_edge_healthcheck.sh:/polygon_edge_healthcheck.sh:ro
restart: on-failure
networks:
- local-erc20-messaging-infra-docker
Expand All @@ -145,12 +165,14 @@ services:
- incal-data:/data
- ./node_config/node/sequencer-incal/config.toml:/tmp/node_config/node/sequencer-incal/config.toml
depends_on:
topos-node-1:
topos-node-4:
condition: service_healthy
contracts-topos:
condition: service_completed_successfully
contracts-incal:
condition: service_completed_successfully
incal-node-4:
condition: service_healthy
entrypoint: ""
command: bash -c "
source /contracts/.env &&
Expand Down
44 changes: 29 additions & 15 deletions subnet-topos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ services:
- "--home"
- "/data"
healthcheck:
test: ./topos node status --node http://localhost:1340
interval: 15s
test: |
set -e
./topos node status --node http://localhost:1340
/data/polygon-edge status | grep 'Current Block Number (base 10) = .[0-9]*'
interval: 5s
start_period: 1s
retries: 10
depends_on:
topos-init:
Expand Down Expand Up @@ -109,14 +113,18 @@ services:
- "--home"
- "/data"
healthcheck:
test: ./topos node status --node http://localhost:1340
interval: 15s
test: |
set -e
./topos node status --node http://localhost:1340
/data/polygon-edge status | grep 'Current Block Number (base 10) = .[0-9]*'
interval: 10s
start_period: 1s
retries: 10
depends_on:
topos-init:
condition: service_completed_successfully
topos-node-1:
condition: service_started
condition: service_healthy
volumes:
- topos-data:/data
- ./node_config/node/boot/config.toml:/data/node/node-2/config.toml:ro
Expand Down Expand Up @@ -145,14 +153,18 @@ services:
- "--home"
- "/data"
healthcheck:
test: ./topos node status --node http://localhost:1340
interval: 15s
test: |
set -e
./topos node status --node http://localhost:1340
/data/polygon-edge status | grep 'Current Block Number (base 10) = .[0-9]*'
interval: 10s
start_period: 1s
retries: 10
depends_on:
topos-init:
condition: service_completed_successfully
topos-node-1:
condition: service_started
condition: service_healthy
volumes:
- topos-data:/data
- ./node_config/node/boot/config.toml:/data/node/node-3/config.toml:ro
Expand Down Expand Up @@ -181,17 +193,22 @@ services:
- "--home"
- "/data"
healthcheck:
test: ./topos node status --node http://localhost:1340
interval: 15s
test: |
set -e
./topos node status --node http://localhost:1340
/bin/sh /polygon_edge_healthcheck.sh /data
interval: 10s
start_period: 1s
retries: 10
depends_on:
topos-init:
condition: service_completed_successfully
topos-node-1:
condition: service_started
condition: service_healthy
volumes:
- topos-data:/data
- ./node_config/node/boot/config.toml:/data/node/node-4/config.toml:ro
- ./scripts/polygon_edge_healthcheck.sh:/polygon_edge_healthcheck.sh:ro
restart: on-failure
ports:
- "9090"
Expand All @@ -207,15 +224,12 @@ services:
image: ghcr.io/topos-protocol/topos:${TOPOS_VERSION}
container_name: topos-sequencer
init: true
healthcheck:
test: ./topos node status --node http://localhost:1340
interval: 5s
volumes:
- contracts:/contracts
- topos-data:/data
- ./node_config/node/sequencer-topos/config.toml:/data/node/sequencer-topos/config.toml
depends_on:
topos-node-1:
topos-node-4:
condition: service_healthy
contracts-topos:
condition: service_completed_successfully
Expand Down
21 changes: 21 additions & 0 deletions tests/network.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e

source $LOCAL_ERC20_HOME/tests/utils.sh

if [ $1 = 'start' ]; then
start_network
exit $?
elif [ $1 = 'stop' ]; then
stop_network
exit $?
elif [ $1 = 'check' ]; then
check_network_health
exit $?
elif [ $1 = 'is_running' ]; then
is_network_running
exit $?
else
echo "Invalid argument"
exit 1
fi
65 changes: 65 additions & 0 deletions tests/test_cert_production.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
set -e

source $LOCAL_ERC20_HOME/tests/utils.sh


function get_last_block () {
local last_block=`docker compose logs $1 | grep -e 'polygon.blockchain' | grep -e 'new block' | \
grep -o 'number[=:][[:alnum:]]\{1,100\}' | awk -F'[:=]' '{print $2}' | tail -1` > /dev/null
echo $last_block
}

function check_certificate_produced () {
docker compose logs $1 | grep -e 'on_subnet_runtime_proxy_event : NewCertificate' | \
grep -e "block_number: $2" > /dev/null
local certificate_produced=$?
echo $certificate_produced
}

network_started=0

# Start network if it is not running
is_running=$(is_network_running)
if [ $is_running -eq 1 ]; then
echo "Test network is not running, starting it now..."
start_network
network_started=1
sleep 5 # Warm up network
fi


# Perform test
echo "Executing block cert production test..."
# Get last block number created on the topos polygon edge node
last_block_topos=$(get_last_block topos-node-1)
echo "Topos subnet last block: $last_block_topos"
# Check if certificate with this block number is produced on the topos sequencer
certificate_produced=$(check_certificate_produced topos-sequencer $last_block_topos)
if [ $certificate_produced -eq 0 ]; then
echo "Certificate for block $last_block_topos produced on topos sequencer"
else
echo "Certificate for block $last_block_topos IS NOT produced on topos sequencer"
exit 1
fi


# Get last block number created on the incal polygon edge node
last_block_incal=$(get_last_block incal-node-1)
echo "Incal subnet last block: $last_block_incal"
# Check if certificate with this block number is produced on the incal sequencer
certificate_produced=$(check_certificate_produced incal-sequencer $last_block_incal)
if [ $certificate_produced -eq 0 ]; then
echo "Certificate for block $last_block_incal produced on incal sequencer"
else
echo "Certificate for block $last_block_incal IS NOT produced on incal sequencer"
exit 1
fi



# Stop network if started for this test
if [ $network_started -eq 1 ]; then
echo "Shutting down network started for this test"
stop_network
fi
47 changes: 47 additions & 0 deletions tests/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -e

start_network () {
echo "Starting local infra network..."
docker compose up -d
local ret=$?
echo "Local infra network started with result: $ret"
return $ret
}


stop_network () {
echo "Stopping local infra network..."
docker compose down --volumes
local ret=$?
echo "Local infra network stopped with result: $ret"
return $ret
}


check_network_health () {
# Check if all relevant containers are healthy
# TODO: Add healcheck for sequencers, currenly only tce and polygon edge nodes are checked
SERVICE_NAMES=$(docker compose config --dry-run --services | grep -e node)
EXPECTED=$(docker compose ps -aq $SERVICE_NAMES | wc -l)
COUNT=$(docker inspect --format "{{.State.Health.Status }}" $(docker compose ps -aq $SERVICE_NAMES) | grep "^healthy$"|wc -l)
echo "Number of Healthy containers: $COUNT"
if [[ $COUNT -eq $EXPECTED ]]; then
echo "All expected containers healthy"
return 0
else
echo "Unhealthy containers"
docker compose -f tools/docker-compose.yml ps -a peer boot
return 1
fi
}

is_network_running() {
SERVICE_NAMES=$(docker compose config --dry-run --services | grep -e node -e sequencer)
COUNT=$(docker compose ps -aq $SERVICE_NAMES | wc -l)
if [[ $COUNT -eq 0 ]]; then
echo 1
else
echo 0
fi
}

0 comments on commit 5f5aa23

Please sign in to comment.