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

Commit

Permalink
feat: test for certificate production for empty blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Atanasievski committed Dec 12, 2023
1 parent ee2710b commit 4b45b88
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@ 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

# SMART CONTRACTS SALT
TOKEN_DEPLOYER_SALT=m1Ln9uF9MGZ2PcR
TOPOS_CORE_SALT=dCyN8VZz5sXgqMO
TOPOS_CORE_PROXY_SALT=aRV8Mp9o4xRpLbF
ERC20_MESSAGING_SALT=ho37cJbGkgI6vnp
SUBNET_REGISTRATOR_SALT=azsRlXyGu0ty291


# KEYS
PRIVATE_KEY=0xd7e2e00b43c12cf17239d4755ed744df6ca70a933fc7c8bbb7da1342a5ff2e38


# TESTS
export LOCAL_ERC20_HOME=./
12 changes: 12 additions & 0 deletions subnet-incal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ services:
- "--price-limit"
- ${PRICE_LIMIT}
- "--seal"
healthcheck:
test: ./polygon-edge status | awk '/Number/ {print $$NF}' | tr -d '\n' | grep -v -w "0"
interval: 5s
retries: 10
depends_on:
incal-init:
condition: service_completed_successfully
Expand Down Expand Up @@ -99,6 +103,10 @@ services:
- "--price-limit"
- ${PRICE_LIMIT}
- "--seal"
healthcheck:
test: ./polygon-edge status | awk '/Number/ {print $$NF}' | tr -d '\n' | grep -v -w "0"
interval: 5s
retries: 10
depends_on:
incal-init:
condition: service_completed_successfully
Expand Down Expand Up @@ -127,6 +135,10 @@ services:
- "--price-limit"
- ${PRICE_LIMIT}
- "--seal"
healthcheck:
test: ./polygon-edge status | awk '/Number/ {print $$NF}' | tr -d '\n' | grep -v -w "0"
interval: 5s
retries: 10
depends_on:
incal-init:
condition: service_completed_successfully
Expand Down
3 changes: 0 additions & 3 deletions subnet-topos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ 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
Expand Down
66 changes: 66 additions & 0 deletions tests/network.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

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 "Network is not running"
return 1
else
echo "Network is running"
return 0
fi
}


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
39 changes: 39 additions & 0 deletions tests/test_cert_production.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

network_started=0

# Start network if it is not running
$LOCAL_ERC20_HOME/tests/network.sh is_running
is_running=$?
if [ $is_running -eq 1 ]; then
echo "Test network is not running, starting it now..."
$LOCAL_ERC20_HOME/tests/network.sh start
network_started=1
sleep 5 # Warn 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=`docker compose logs topos-node-1 | grep -e topos::edge -e '"polygon.blockchain": "new block"' | \
grep -o 'number:[[:alnum:]]\{1,100\}' | awk -F ":" '{print $2}' | tail -1`
echo "Topos subnet last block: $last_block_topos"

# Check if certificate with this block number is produced on the topos sequencer
docker compose logs topos-sequencer | grep -e 'on_subnet_runtime_proxy_event : NewCertificate' | grep -e "block_number: $last_block_topos"
ret=$?
if [ $ret -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


# Stop network if started for this test
if [ $network_started -eq 1 ]; then
echo "Shutting down network started for this test"
$LOCAL_ERC20_HOME/tests/network.sh stop
fi

0 comments on commit 4b45b88

Please sign in to comment.