diff --git a/tests/cases/tm2tm/scripts/test-service b/tests/cases/tm2tm/scripts/test-service index 06b22c59..307135f0 100755 --- a/tests/cases/tm2tm/scripts/test-service +++ b/tests/cases/tm2tm/scripts/test-service @@ -11,7 +11,7 @@ - transfer - - - - finality + - - query = 1 - - @@ -21,7 +21,7 @@ - transfer - - - - finality + - - query = 2 - - @@ -41,7 +41,7 @@ - transfer x 3 - - - - finality + - - query 3 - - @@ -56,6 +56,8 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd) RLY_BINARY=${SCRIPT_DIR}/../../../../build/yrly RLY="${RLY_BINARY} --debug" +source ${SCRIPT_DIR}/utils + TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) @@ -68,13 +70,7 @@ RLY_PID=$! # transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -# query unrelayed-packets 1 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 1 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 1 sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -82,13 +78,7 @@ echo "xxxxxxx relay service -> skip xxxxxx" # transfer a token ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -# query unrelayed-packets 2 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 2 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 2 sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -96,31 +86,18 @@ echo "xxxxxxx relay service -> skip xxxxxx" sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - time xxxxxx" +expectUnrelayedPackets 0 + # transfer a token x 3 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -# query unrelayed-packets 3 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 3 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 3 sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - count xxxxxx" -# wait for relay service to execute -for i in `seq $RETRY_COUNT` -do - echo "[try:$i] waiting for sendPacket finalization ..." - sleep $RETRY_INTERVAL - unrelayed=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') - if [ $unrelayed -eq 0 ]; then - break - fi -done +expectUnrelayedPackets 0 kill $RLY_PID diff --git a/tests/cases/tm2tm/scripts/utils b/tests/cases/tm2tm/scripts/utils new file mode 100644 index 00000000..7b7ed3d7 --- /dev/null +++ b/tests/cases/tm2tm/scripts/utils @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +expectUnrelayedPackets() { + expect_count=$1 + unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') + if [ $unrelayed_packets -ne ${expect_count} ]; then + echo "unrelayed_packets: $unrelayed_packets" + kill $RLY_PID + exit 1 + fi +} diff --git a/tests/cases/tmmock2tmmock/scripts/test-service b/tests/cases/tmmock2tmmock/scripts/test-service index 8c9a5316..65332112 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-service +++ b/tests/cases/tmmock2tmmock/scripts/test-service @@ -56,6 +56,8 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd) RLY_BINARY=${SCRIPT_DIR}/../../../../build/yrly RLY="${RLY_BINARY} --debug" +source ${SCRIPT_DIR}/utils + TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) @@ -69,13 +71,7 @@ RLY_PID=$! ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay -# query unrelayed-packets 1 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 1 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 1 sleep 7 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -84,13 +80,7 @@ echo "xxxxxxx relay service -> skip xxxxxx" ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay -# query unrelayed-packets 2 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 2 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 2 sleep 7 # wait for relay-interval echo "xxxxxxx relay service -> skip xxxxxx" @@ -98,32 +88,19 @@ echo "xxxxxxx relay service -> skip xxxxxx" sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - time xxxxxx" +expectUnrelayedPackets 0 + # transfer a token x 3 ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} sleep 3 # finality_delay -# query unrelayed-packets 3 -unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') -if [ $unrelayed_packets -ne 3 ]; then - echo "unrelayed_packets: $unrelayed_packets" - kill $RLY_PID - exit 1 -fi +expectUnrelayedPackets 3 -sleep 7 # wait for relay-interval +sleep 10 # wait for relay-interval echo "xxxxxxx relay service -> exec - count xxxxxx" -# wait for relay service to execute -for i in `seq $RETRY_COUNT` -do - echo "[try:$i] waiting for sendPacket finalization ..." - sleep $RETRY_INTERVAL - unrelayed=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') - if [ $unrelayed -eq 0 ]; then - break - fi -done +expectUnrelayedPackets 0 kill $RLY_PID diff --git a/tests/cases/tmmock2tmmock/scripts/test-tx b/tests/cases/tmmock2tmmock/scripts/test-tx index cf73c68d..034b2801 100755 --- a/tests/cases/tmmock2tmmock/scripts/test-tx +++ b/tests/cases/tmmock2tmmock/scripts/test-tx @@ -6,6 +6,8 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd) RLY_BINARY=${SCRIPT_DIR}/../../../../build/yrly RLY="${RLY_BINARY} --debug" +source ${SCRIPT_DIR}/utils + TM_ADDRESS0=$(${RLY} tendermint keys show ibc0 testkey) TM_ADDRESS1=$(${RLY} tendermint keys show ibc1 testkey) @@ -20,47 +22,17 @@ echo "Before ibc1 balance: $(${RLY} query balance ibc1 ${TM_ADDRESS1})" # transfer a token (sendPacket) ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${TM_ADDRESS1} -# wait for the finalization of the sendPacket execution -for i in `seq $RETRY_COUNT` -do - echo "[try:$i] waiting for sendPacket finalization ..." - sleep $RETRY_INTERVAL - unrelayed=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') - if [ $unrelayed -gt 0 ] - then - break - fi -done +waitRelay "unrelayed-packets" "src" # relay the packet (recvPacket) ${RLY} tx relay --do-refresh ibc01 -# wait for the finalization of the recvPacket execution -for i in `seq $RETRY_COUNT` -do - echo "[try:$i] waiting for recvPacket finalization ..." - sleep $RETRY_INTERVAL - unrelayed=$(${RLY} query unrelayed-acknowledgements ibc01 | jq '.dst | length') - if [ $unrelayed -gt 0 ] - then - break - fi -done +waitRelay "unrelayed-acknowledgements" "dst" # relay the ack for the packet (acknowledgePacket) ${RLY} tx acks --do-refresh ibc01 -# wait for the finalization of the recvPacket execution -for i in `seq $RETRY_COUNT` -do - echo "[try:$i] waiting for acknowledgePacket finalization ..." - sleep $RETRY_INTERVAL - unrelayed=$(${RLY} query unrelayed-acknowledgements ibc01 | jq '.dst | length') - if [ $unrelayed -eq 0 ] - then - break - fi -done +waitRelay "unrelayed-acknowledgements" "dst" echo "After ibc0 balance: $(${RLY} query balance ibc0 ${TM_ADDRESS0})" echo "After ibc1 balance: $(${RLY} query balance ibc1 ${TM_ADDRESS1})" diff --git a/tests/cases/tmmock2tmmock/scripts/utils b/tests/cases/tmmock2tmmock/scripts/utils new file mode 100644 index 00000000..b13bbc05 --- /dev/null +++ b/tests/cases/tmmock2tmmock/scripts/utils @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +PATH_NAME=ibc01 +RETRY_COUNT=5 +RETRY_INTERVAL=1 + +waitRelay() { + query_type=$1 + filter=".$2 | length" + for i in `seq $RETRY_COUNT` + do + echo "[try:$i] waiting for ${query_type} finalization ..." + sleep $RETRY_INTERVAL + unrelayed=$(${RLY} query ${query_type} ${PATH_NAME} | jq "${filter}") + if [ $unrelayed -gt 0 ]; then + break + fi + done +} + +expectUnrelayedPackets() { + expect_count=$1 + unrelayed_packets=$(${RLY} query unrelayed-packets ibc01 | jq '.src | length') + if [ $unrelayed_packets -ne ${expect_count} ]; then + echo "unrelayed_packets: $unrelayed_packets" + kill $RLY_PID + exit 1 + fi +}