From 19b48748bffe6d35cbc95e03a737381b98bfd5ad Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:10:30 +0100 Subject: [PATCH] feat: check num certs on e2e --- test/bats/pessimistic/e2e-pp.bats | 10 +++ test/scripts/agglayer_certificates_monitor.sh | 74 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 test/bats/pessimistic/e2e-pp.bats create mode 100755 test/scripts/agglayer_certificates_monitor.sh diff --git a/test/bats/pessimistic/e2e-pp.bats b/test/bats/pessimistic/e2e-pp.bats new file mode 100644 index 00000000..7e0c4902 --- /dev/null +++ b/test/bats/pessimistic/e2e-pp.bats @@ -0,0 +1,10 @@ +setup() { + load '../../helpers/common-setup' + _common_setup +} + +@test "Verify batches" { + echo "Waiting 10 minutes to get some settle certificate...." + run $PROJECT_ROOT/test/scripts/batch_verification_monitor.sh 1 600 + assert_success +} diff --git a/test/scripts/agglayer_certificates_monitor.sh b/test/scripts/agglayer_certificates_monitor.sh new file mode 100755 index 00000000..9441e270 --- /dev/null +++ b/test/scripts/agglayer_certificates_monitor.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +# This script monitors the agglayer certificates progress of pessimistic proof. +############################################################################### + + +############################################################################### +function parse_params(){ + # Check if the required arguments are provided. + if [ "$#" -lt 2 ]; then + echo "Usage: $0 " + exit 1 + fi + + # The number of batches to be verified. + settle_certificates_target="$1" + + # The script timeout (in seconds). + timeout="$2" +} +############################################################################### +function check_timeout(){ + local _end_time=$1 + current_time=$(date +%s) + if ((current_time > _end_time)); then + echo "[$(date '+%Y-%m-%d %H:%M:%S')] ❌ Exiting... Timeout reached!" + exit 1 + fi +} + +############################################################################### +function check_num_certificates(){ + local _cmd="echo 'select status, count(*) from certificate_info group by status;' | sqlite3 /tmp/aggsender.sqlite" + local _outcmd=mktemp + kurtosis service exec cdk cdk-node-001 "$_cmd" > $_outcmd + if [ $? -ne 0 ]; then + echo "[$(date '+%Y-%m-%d %H:%M:%S')] Error executing command kurtosis service: $_cmd" + return + fi + local num_certs=$(cat $_outcmd | tail -n +2 | cut -f 2 -d '|' | xargs |tr ' ' '+' | bc) + # Get the number of settled certificates "4|0" + local _num_settle_certs=$(cat $_outcmd | tail -n +2 | grep ^${aggsender_status_settled} | cut -d'|' -f2) + [ -z "$_num_settle_certs" ] && _num_settle_certs=0 + echo "[$(date '+%Y-%m-%d %H:%M:%S')] Num certificates on aggsender: $num_certs. Settled certificates : $_num_settle_certs" + if [ $num_certs -ge $settle_certificates_target ]; then + echo "[$(date '+%Y-%m-%d %H:%M:%S')] ✅ Exiting... $num_certs certificates were settled! (total certs $num_certs)" + exit 0 + fi +} + +############################################################################### +# MAIN +############################################################################### + +declare -A aggsender_status_map=( + [0]="Pending" + [1]="Proven" + [2]="Candidate" + [3]="InError" + [4]="Settled" +) + +readonly aggsender_status_settled=4 + + +parse_params $* +start_time=$(date +%s) +end_time=$((start_time + timeout)) +echo "[$(date '+%Y-%m-%d %H:%M:%S')] Start monitoring agglayer certificates progress..." +while true; do + check_num_certificates + check_timeout $end_time + sleep 10 +done \ No newline at end of file