From 73bfad2f274a162cc2f48f4df07d39d637949236 Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Fri, 22 Dec 2023 11:01:39 +0100 Subject: [PATCH 1/3] feat: add test for target sequencer cert delivery --- tests/test_cert_sequencer_delivery.sh | 76 ++++++++++++++++++++++++ tests/test_transaction_in_certificate.sh | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 tests/test_cert_sequencer_delivery.sh diff --git a/tests/test_cert_sequencer_delivery.sh b/tests/test_cert_sequencer_delivery.sh new file mode 100755 index 0000000..be58e6c --- /dev/null +++ b/tests/test_cert_sequencer_delivery.sh @@ -0,0 +1,76 @@ +#!/bin/bash +set -e + +source $LOCAL_ERC20_HOME/tests/utils.sh + + +function receipts_root_in_delivered_certificate() +{ + echo $(docker logs topos-sequencer 2>&1 | grep -e "Received certificate from TCE " | \ + awk -F 'receipts_root_hash: "' '{print $2}' | awk -F '\",' '{print $1}' | tail -1) +} + + +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 +export ERC20_MESSAGING_CONTRACT_ADDRESS=$(get_erc20_contract_address) +export TOPOS_CORE_PROXY_CONTRACT_ADDRESS=$(get_topos_core_proxy_contract_address) + + +# Make token transaction on incal network targeting topos network +# In should be delivered to target topos sequencer +echo "Executing test of certificate delivery to target topos sequencer..." +check_artifacts +topos_subnet_id=$(get_topos_subnet_id) +receipts_root_hash=$(send_token_with_retry 3 $topos_subnet_id $INCAL_HOST_PORT) +transaction_valid=$? +echo "Transaction send token result: $transaction_valid, receipts root hash: $receipts_root_hash" +if [ $transaction_valid -eq 1 ]; then + echo "Transaction send token failed" + if [ $network_started -eq 1 ]; then + echo "Shutting down network started for this test" + stop_network + fi + exit 1 +fi + + +# Check if transaction is delivered to target topos sequncer +# Wait multiple times to give time to target sequencer to catch up +# Check receipts root in delivered certificate +for i in {1..10}; +do + delivered_receipts_root_hash=$(receipts_root_in_delivered_certificate) + echo "Receipts root hash in delivered certificate: $delivered_receipts_root_hash" + if [ "$delivered_receipts_root_hash" == "$receipts_root_hash" ]; then + echo "Transaction with correct receipt root hash is delivered to target sequencer" + break + else + echo "Transaction is not delivered to target sequencer" + if [[ "$i" != '10' ]]; then + echo "Trying again in 5 seconds for $(($i+1)) time" + sleep 5 + continue + fi + if [ $network_started -eq 1 ]; then + echo "Test failed, shutting down network started for this test" + stop_network + fi + exit 1 + fi +done + + +# Stop network if started for this test +if [ $network_started -eq 1 ]; then + echo "Shutting down network started for this test" + stop_network +fi diff --git a/tests/test_transaction_in_certificate.sh b/tests/test_transaction_in_certificate.sh index f42e271..94069f1 100755 --- a/tests/test_transaction_in_certificate.sh +++ b/tests/test_transaction_in_certificate.sh @@ -33,7 +33,7 @@ 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" if [ $transaction_valid -eq 1 ]; then - echo "Transaction send token failed, shutting down network started for this test" + echo "Transaction send token failed" if [ $network_started -eq 1 ]; then echo "Shutting down network started for this test" stop_network From 1cf1de22ccbef6847cd25e17ccd7d9f9df1315c0 Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Fri, 22 Dec 2023 16:08:39 +0100 Subject: [PATCH 2/3] fix: add check for cert inclusion --- tests/test_cert_inclusion.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_cert_inclusion.sh b/tests/test_cert_inclusion.sh index 360a01b..246ba16 100755 --- a/tests/test_cert_inclusion.sh +++ b/tests/test_cert_inclusion.sh @@ -41,7 +41,17 @@ echo "Executing certificate inclusion test..." check_artifacts incal_subnet_id=$(get_incal_subnet_id) receipts_root=$(send_token_with_retry 3 $incal_subnet_id $TOPOS_HOST_PORT) +transaction_valid=$? echo "Receipts root hash: $receipts_root" +if [ $transaction_valid -eq 1 ]; then + echo "Transaction send token failed" + if [ $network_started -eq 1 ]; then + echo "Shutting down network started for this test" + stop_network + fi + exit 1 +fi + is_certificate_present=$(check_certificate_inclusion_with_retry 3 $receipts_root) if [ $is_certificate_present -eq 0 ]; then echo "Certificate is present" From a7fd8d83a39c3ce979ef3c68dad0652f2767b34a Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Fri, 22 Dec 2023 16:14:34 +0100 Subject: [PATCH 3/3] fix: variable name --- tests/test_cert_inclusion.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cert_inclusion.sh b/tests/test_cert_inclusion.sh index 246ba16..804cff4 100755 --- a/tests/test_cert_inclusion.sh +++ b/tests/test_cert_inclusion.sh @@ -41,9 +41,9 @@ echo "Executing certificate inclusion test..." check_artifacts incal_subnet_id=$(get_incal_subnet_id) receipts_root=$(send_token_with_retry 3 $incal_subnet_id $TOPOS_HOST_PORT) -transaction_valid=$? +receipts_root_valid=$? echo "Receipts root hash: $receipts_root" -if [ $transaction_valid -eq 1 ]; then +if [ $receipts_root_valid -eq 1 ]; then echo "Transaction send token failed" if [ $network_started -eq 1 ]; then echo "Shutting down network started for this test"