Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring test-service
Browse files Browse the repository at this point in the history
Signed-off-by: Dongri Jin <dongri.jin@speee.jp>
dongrie committed Dec 5, 2023
1 parent b3cd4e7 commit c1b9f1a
Showing 5 changed files with 65 additions and 99 deletions.
45 changes: 11 additions & 34 deletions tests/cases/tm2tm/scripts/test-service
Original file line number Diff line number Diff line change
@@ -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,59 +70,34 @@ 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"

# 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"

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
11 changes: 11 additions & 0 deletions tests/cases/tm2tm/scripts/utils
Original file line number Diff line number Diff line change
@@ -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
}
41 changes: 9 additions & 32 deletions tests/cases/tmmock2tmmock/scripts/test-service
Original file line number Diff line number Diff line change
@@ -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,46 +80,27 @@ 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"

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
38 changes: 5 additions & 33 deletions tests/cases/tmmock2tmmock/scripts/test-tx
Original file line number Diff line number Diff line change
@@ -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})"
29 changes: 29 additions & 0 deletions tests/cases/tmmock2tmmock/scripts/utils
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit c1b9f1a

Please sign in to comment.