This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add test for certificate block production (#42)
- Loading branch information
Showing
9 changed files
with
213 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |