Skip to content

Commit

Permalink
fix test-channel-upgrade for eth2eth
Browse files Browse the repository at this point in the history
Signed-off-by: Masanori Yoshida <[email protected]>
  • Loading branch information
siburu committed Sep 2, 2024
1 parent 3ffa587 commit 3babbf5
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 37 deletions.
2 changes: 1 addition & 1 deletion tests/cases/eth2eth/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test-single:
./scripts/fixture single
./scripts/init-rly
./scripts/handshake
./scripts/test-channel-upgrade
# ./scripts/test-channel-upgrade
# ./scripts/test-tx

.PHONY: network-down
Expand Down
203 changes: 167 additions & 36 deletions tests/cases/eth2eth/scripts/test-channel-upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,30 @@ SCRIPT_DIR=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd)
FIXTURES_DIR=${SCRIPT_DIR}/../fixtures
source ${SCRIPT_DIR}/util/relayer-util

# back up the original connection identifiers
srcOrigConnectionId=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."connection-id"')
dstOrigConnectionId=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."connection-id"')
checkEq() {
typ=$1
a=$2
b=$3
if [ $a != $b ]
then
echo "${typ} mismatch: ${a} != ${b}"
exit 1
fi
echo $a
}

# back up the original channel fields
a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."connection-id"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."connection-id"')
origConnectionId=$(checkEq "original connection id" $a $b)

a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."version"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."version"')
origVersion=$(checkEq "original version" $a $b)

a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."order"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."order"')
origOrder=$(checkEq "original ordering" $a $b)

# back up the original config.json and make connection identifiers empty
origconfig=`mktemp`
Expand All @@ -18,50 +39,160 @@ $RLY paths edit $PATH_NAME dst connection-id ''

# create a new connection and save the new connection identifiers
$RLY tx connection $PATH_NAME
srcAltConnectionId=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."connection-id"')
dstAltConnectionId=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."connection-id"')
a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."connection-id"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."connection-id"')
altConnectionId=$(checkEq "alternative connection id" $a $b)
altOrder=ordered

# resume the original config.json
mv $origconfig "$RELAYER_CONF/config/config.json"

# the function that checks which of orig or alt the channel has finally settled
checkResult() {
expectedSide=$1
expectedVersion=$2

a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."connection-id"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."connection-id"')
connectionId=$(checkEq "path config connection id" $a $b)

a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."version"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."version"')
version=$(checkEq "path config version" $a $b)

a=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].src."order"')
b=$($RLY paths list --json | jq --raw-output --arg path_name "$PATH_NAME" '.[$path_name].dst."order"')
order=$(checkEq "path config ordering" $a $b)

if [ "$expectedSide" = orig ]
then
expectedConnectionId=$origConnectionId
expectedOrder=$origOrder
elif [ $expectedSide = alt ]
then
expectedConnectionId=$altConnectionId
expectedOrder=$altOrder
else
echo "expectedSide is invalid value: $expectedSide"
exit 1
fi

if [ "$connectionId" != "$expectedConnectionId" -o "$order" != "$expectedOrder" -o "$version" != "$expectedVersion" ]
then
echo "unexpected channel fields: $connectionId(expected: $expectedConnectionId), $order(expected: $expectedOrder), $version(expected: $expectedVersion)"
exit 1
fi

# confirm src chain is not upgrading
upg=$($RLY query channel-upgrade ibc01 ibc0)
if [ $(echo "$upg" | jq '.fields|length') -ne 0 ]
then
echo "src chain still in the process of upgrade: $upg"
exit 1
fi

# confirm dst chain is not upgrading
upg=$($RLY query channel-upgrade ibc01 ibc1)
if [ $(echo "$upg" | jq '.fields|length') -ne 0 ]
then
echo "dst chain is still in the process of upgrade: $upg"
exit 1
fi
}

# constant variables
APP_ADDRESS_A=`cat ${FIXTURES_DIR}/ethereum/ibc0/addresses/IBCChannelUpgradableMockApp`
APP_ADDRESS_B=`cat ${FIXTURES_DIR}/ethereum/ibc1/addresses/IBCChannelUpgradableMockApp`
#TIMEOUT_FLAGS="--timeout-height 0-100000000 --timeout-timestamp `date -d 2030/01/01 +%s`"
#TIMEOUT_FLAGS="--timeout-height 0-0 --timeout-timestamp `date -d 2030/01/01 +%s`"
TIMEOUT_FLAGS="--timeout-height 0-100000000"
ORIG_FIELDS="--ordering $origOrder --connection-hops $origConnectionId"
ALT_FIELDS="--ordering $altOrder --connection-hops $altConnectionId"

# test channel upgrade (crossing-hello)
UPGRADE_FIELDS_FLAGS_A="--ordering UnOrdered --connection-hops $srcAltConnectionId --version mockapp-999"
UPGRADE_FIELDS_FLAGS_B="--ordering UnOrdered --connection-hops $dstAltConnectionId --version mockapp-999"
$RLY eth upgrade propose ibc01 ibc0 $UPGRADE_FIELDS_FLAGS_A $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc0 $UPGRADE_FIELDS_FLAGS_A
$RLY eth upgrade propose ibc01 ibc1 $UPGRADE_FIELDS_FLAGS_B $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc1 $UPGRADE_FIELDS_FLAGS_B
echo '##### case 1 #####'
fields="$ALT_FIELDS --version mockapp-2"
$RLY eth upgrade propose ibc01 ibc0 $fields $TIMEOUT_FLAGS
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY tx channel-upgrade init ibc01 ibc1 $fields
$RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHING --target-dst-state FLUSHING
$RLY eth upgrade allow ibc01 ibc0 --upgrade-sequence 1
$RLY eth upgrade allow ibc01 ibc1 --upgrade-sequence 1
$RLY tx channel-upgrade execute ibc01
checkResult alt mockapp-2

# test channel upgrade (non-crossing-hello)
UPGRADE_FIELDS_FLAGS_A="--ordering UnOrdered --connection-hops $srcOrigConnectionId --version mockapp-1"
UPGRADE_FIELDS_FLAGS_B="--ordering UnOrdered --connection-hops $dstOrigConnectionId --version mockapp-1"
$RLY eth upgrade propose ibc01 ibc0 $UPGRADE_FIELDS_FLAGS_A $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc0 $UPGRADE_FIELDS_FLAGS_A
$RLY eth upgrade propose ibc01 ibc0 $UPGRADE_FIELDS_FLAGS_A $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc0 $UPGRADE_FIELDS_FLAGS_A
$RLY eth upgrade propose ibc01 ibc1 $UPGRADE_FIELDS_FLAGS_B $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc1 $UPGRADE_FIELDS_FLAGS_B
$RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHING --target-dst-state FLUSHING
$RLY eth upgrade allow ibc01 ibc0 --upgrade-sequence 3
$RLY eth upgrade allow ibc01 ibc1 --upgrade-sequence 3
echo '##### case 2 #####'
fields="$ORIG_FIELDS --version mockapp-3"
$RLY eth upgrade propose ibc01 ibc0 $fields $TIMEOUT_FLAGS
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY tx channel-upgrade init ibc01 ibc1 $fields
$RLY tx channel-upgrade execute ibc01
checkResult orig mockapp-3

echo '##### case 3 #####'
fields="$ALT_FIELDS --version mockapp-4"
$RLY eth upgrade propose ibc01 ibc0 $fields $TIMEOUT_FLAGS
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY tx channel-upgrade init ibc01 ibc1 $fields
$RLY tx channel-upgrade cancel ibc01 ibc0 # create situation where ibc0.error_receipt.sequence >= ibc1.channel.upgrade_sequence
$RLY tx channel-upgrade execute ibc01 # the channel upgrade of ibc1 should be cancelled
checkResult orig mockapp-3

echo '##### case 4 #####'
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY tx channel-upgrade execute ibc01 --target-src-state INIT --target-dst-state FLUSHING
$RLY tx channel-upgrade cancel ibc01 ibc0 # ibc0 returns to UNINIT. ibc1 is FLUSHING.
$RLY tx channel-upgrade execute ibc01 # ibc1's upgrade should be cancelled
checkResult orig mockapp-3

echo '##### case 5 #####'
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY tx channel-upgrade execute ibc01 --target-src-state INIT --target-dst-state FLUSHING
$RLY tx channel-upgrade cancel ibc01 ibc0 # ibc0 returns to UNINIT. ibc1 is FLUSHING.
$RLY tx channel-upgrade init ibc01 ibc0 --unsafe $fields # ibc0 re-initiates new upgrade.
$RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHING --target-dst-state FLUSHING
$RLY eth upgrade allow ibc01 ibc0 --upgrade-sequence 7
$RLY eth upgrade allow ibc01 ibc1 --upgrade-sequence 7
$RLY tx channel-upgrade execute ibc01 # The upgrade initiated by ibc0 should be completed after ibc1's one is cancelled.
checkResult alt mockapp-4

# test channel upgrade cancel
UPGRADE_FIELDS_FLAGS_A="--ordering UnOrdered --connection-hops $srcAltConnectionId --version mockapp-999"
UPGRADE_FIELDS_FLAGS_B="--ordering UnOrdered --connection-hops $dstAltConnectionId --version mockapp-999"
$RLY eth upgrade propose ibc01 ibc0 $UPGRADE_FIELDS_FLAGS_A $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc0 $UPGRADE_FIELDS_FLAGS_A
$RLY eth upgrade propose ibc01 ibc1 $UPGRADE_FIELDS_FLAGS_B $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc1 $UPGRADE_FIELDS_FLAGS_B
$RLY tx channel-upgrade cancel ibc01 ibc0 # create situation where ibc0.error_receipt.sequence >= ibc1.channel.upgrade_sequence
$RLY tx channel-upgrade execute ibc01 # the channel upgrade of ibc1 should be cancelled
echo '##### case 6 #####'
fields="$ORIG_FIELDS --version mockapp-5"
$RLY eth upgrade propose ibc01 ibc0 $fields $TIMEOUT_FLAGS
$RLY eth upgrade propose ibc01 ibc1 $fields $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHCOMPLETE --target-dst-state FLUSHING
$RLY tx channel-upgrade cancel ibc01 ibc1 # ibc1 returns to UNINIT. ibc0 is FLUSHCOMPLETE.
$RLY tx channel-upgrade execute ibc01 # ibc0's upgrade (in FLUSHCOMPLETE) should be cancelled.
checkResult alt mockapp-4

echo '##### case 7 #####'
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHCOMPLETE --target-dst-state FLUSHING
$RLY tx channel-upgrade cancel ibc01 ibc1 # ibc1 returns to UNINIT. ibc0 is FLUSHCOMPLETE.
$RLY tx channel-upgrade init ibc01 ibc1 --unsafe $fields # ibc1 re-initiates new upgrade.
$RLY tx channel-upgrade execute ibc01 # The upgrade initiated by ibc1 should be completed after ibc0's one is cancelled.
checkResult orig mockapp-5

echo '##### case 8 #####'
fields="$ALT_FIELDS --version mockapp-6"
$RLY eth upgrade propose ibc01 ibc0 $fields --timeout-height 0-0 --timeout-timestamp `date -d 30sec +%s%N`
$RLY eth upgrade propose ibc01 ibc1 $fields --timeout-height 0-0 $TIMEOUT_FLAGS
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHING --target-dst-state FLUSHING
$RLY eth upgrade allow ibc01 ibc0 --upgrade-sequence 11
$RLY eth upgrade allow ibc01 ibc1 --upgrade-sequence 11
sleep 30 # ibc1 exceeds upgrade.timeout.timestamp
$RLY tx channel-upgrade execute ibc01 # ibc0 <= chanUpgradeTimeout, ibc1 <= chanUpgradeCancel
checkResult orig mockapp-5

echo '##### case 9 #####'
$RLY eth upgrade propose ibc01 ibc0 $fields --timeout-height 0-0 --timeout-timestamp `date -d 30sec +%s%N`
$RLY eth upgrade propose ibc01 ibc1 $fields --timeout-height 0-0 --timeout-timestamp `date -d 30sec +%s%N`
$RLY tx channel-upgrade init ibc01 ibc0 $fields
$RLY tx channel-upgrade execute ibc01 --target-src-state FLUSHING --target-dst-state FLUSHING
$RLY eth upgrade allow ibc01 ibc0 --upgrade-sequence 12
$RLY eth upgrade allow ibc01 ibc1 --upgrade-sequence 12
sleep 30 # Both chains exceed upgrade.timeout.timestamp
$RLY tx channel-upgrade execute ibc01 # ibc0,ibc1 <= chanUpgradeTimeout
checkResult orig mockapp-5

0 comments on commit 3babbf5

Please sign in to comment.