Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test for target sequencer cert delivery #50

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/test_cert_inclusion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
receipts_root_valid=$?
echo "Receipts root hash: $receipts_root"
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"
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"
Expand Down
76 changes: 76 additions & 0 deletions tests/test_cert_sequencer_delivery.sh
Original file line number Diff line number Diff line change
@@ -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=$?
atanmarko marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion tests/test_transaction_in_certificate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading