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

Bridge zombienet tests refactoring #3260

Merged
merged 8 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion bridges/zombienet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To start those tests, you need to:

- copy fresh `substrate-relay` binary, built in previous point, to the `~/local_bridge_testing/bin/substrate-relay`;

- change the `POLKADOT_SDK_FOLDER` and `ZOMBIENET_BINARY_PATH` (and ensure that the nearby variables
- change the `POLKADOT_SDK_PATH` and `ZOMBIENET_BINARY_PATH` (and ensure that the nearby variables
have correct values) in the `./run-tests.sh`.

After that, you could run tests with the `./run-tests.sh` command. Hopefully, it'll show the
Expand Down
3 changes: 3 additions & 0 deletions bridges/zombienet/environments/rococo-westend/helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

$POLKADOT_SDK_PATH/cumulus/scripts/bridges_rococo_westend.sh "$@"
10 changes: 10 additions & 0 deletions bridges/zombienet/environments/rococo-westend/rococo.zndsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Description: User is able to transfer WND from Westend Asset Hub to Rococo Asset Hub and back
Network: ../../../../cumulus/zombienet/bridge-hubs/bridge_hub_rococo_local_network.toml
Creds: config

# step 0: ensure that initialization has completed
asset-hub-rococo-collator1: js-script ../../helpers/wait-hrmp-channel-opened.js with "1013" within 600 seconds

# step 1: relay is already started - let's wait until with-Westend GRANPDA pallet is initialized at Rococo
bridge-hub-rococo-collator1: js-script ../../helpers/best-finalized-header-at-bridged-chain.js with "Westend,0" within 400 seconds

46 changes: 46 additions & 0 deletions bridges/zombienet/environments/rococo-westend/spawn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

set -e

trap "trap - SIGTERM && kill -9 -$$" SIGINT SIGTERM EXIT

source "${BASH_SOURCE%/*}/../../utils/common.sh"
source "${BASH_SOURCE%/*}/../../utils/zombienet.sh"

logs_dir=$TEST_DIR/logs
helper_script="${BASH_SOURCE%/*}/helper.sh"

rococo_def=$POLKADOT_SDK_PATH/cumulus/zombienet/bridge-hubs/bridge_hub_rococo_local_network.toml
start_zombienet $TEST_DIR $rococo_def rococo_dir rococo_pid
echo

rococo_init_log=$logs_dir/rococo-init.log
echo -e "Setting up the rococo side of the bridge. Logs available at: $rococo_init_log\n"
$helper_script init-asset-hub-rococo-local >> $rococo_init_log 2>&1
svyatonik marked this conversation as resolved.
Show resolved Hide resolved
$helper_script init-bridge-hub-rococo-local >> $rococo_init_log 2>&1
echo

westend_def=$POLKADOT_SDK_PATH/cumulus/zombienet/bridge-hubs/bridge_hub_westend_local_network.toml
start_zombienet $TEST_DIR $westend_def westend_dir westend_pid
echo

westend_init_log=$logs_dir/westend-init.log
echo -e "Setting up the westend side of the bridge. Logs available at: $westend_init_log\n"
$helper_script init-asset-hub-westend-local >> $westend_init_log 2>&1
serban300 marked this conversation as resolved.
Show resolved Hide resolved
$helper_script init-bridge-hub-westend-local >> $westend_init_log 2>&1
echo

relay_log=$logs_dir/relay.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it shouldn't be a part of "environment", but rather the test. E.g. in other tests, relayer is starting after bridge is initialized - to make sure that some mandatory headers are generated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also makes sense to have this modular, but I would keep it as part of the environment as well. Not just for the zombienet tests, but even if we just want to spawn the environment and run some tests manually, would be nice to have the possibility of also start the relayer. For the moment didn't modify this, but in the future we can add a flag like --init for this too if necessary. But so far I think that we need the relayer to start for all the tests that we have. WDYT ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But so far I think that we need the relayer to start for all the tests that we have.

Yes, we need to start relayers for all our tests. But OTOH we need to start it at different points - in test1 we start it early. In test2 and test3 it needs to be started later, after at least one session is completed at relay chain. But since you're only modifying first test here, it is ok to leave it for a follow-up PR

echo -e "Starting rococo-westend relay. Logs available at: $relay_log\n"
start_background_process "$helper_script run-relay" $relay_log relay_pid

run_zndsl ${BASH_SOURCE%/*}/rococo.zndsl $rococo_dir
echo $rococo_dir > $TEST_DIR/rococo.env
echo

run_zndsl ${BASH_SOURCE%/*}/westend.zndsl $westend_dir
echo $westend_dir > $TEST_DIR/westend.env
echo

wait -n $rococo_pid $westend_pid $relay_pid
kill -9 -$$
9 changes: 9 additions & 0 deletions bridges/zombienet/environments/rococo-westend/westend.zndsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Description: User is able to transfer ROC from Rococo Asset Hub to Westend Asset Hub and back
Network: ../../../../cumulus/zombienet/bridge-hubs/bridge_hub_westend_local_network.toml
Creds: config

# step 0: ensure that initialization has completed
asset-hub-westend-collator1: js-script ../../helpers/wait-hrmp-channel-opened.js with "1002" within 600 seconds

# step 1: relay is already started - let's wait until with-Rococo GRANPDA pallet is initialized at Westend
bridge-hub-westend-collator1: js-script ../../helpers/best-finalized-header-at-bridged-chain.js with "Rococo,0" within 400 seconds
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function run(nodeName, networkInfo, args) {
}

// else sleep and retry
await new Promise((resolve) => setTimeout(resolve, 12000));
await new Promise((resolve) => setTimeout(resolve, 6000));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function run(nodeName, networkInfo, args) {
}

// else sleep and retry
await new Promise((resolve) => setTimeout(resolve, 12000));
await new Promise((resolve) => setTimeout(resolve, 6000));
}
}

Expand Down
2 changes: 1 addition & 1 deletion bridges/zombienet/helpers/relayer-rewards.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function run(nodeName, networkInfo, args) {
}

// else sleep and retry
await new Promise((resolve) => setTimeout(resolve, 12000));
await new Promise((resolve) => setTimeout(resolve, 6000));
}
}

Expand Down
2 changes: 1 addition & 1 deletion bridges/zombienet/helpers/wait-hrmp-channel-opened.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function run(nodeName, networkInfo, args) {
}

// else sleep and retry
await new Promise((resolve) => setTimeout(resolve, 12000));
await new Promise((resolve) => setTimeout(resolve, 6000));
}
}

Expand Down
2 changes: 1 addition & 1 deletion bridges/zombienet/helpers/wrapped-assets-balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function run(nodeName, networkInfo, args) {
}

// else sleep and retry
await new Promise((resolve) => setTimeout(resolve, 12000));
await new Promise((resolve) => setTimeout(resolve, 6000));
}
}

Expand Down
16 changes: 16 additions & 0 deletions bridges/zombienet/run-new-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

trap "trap - SIGTERM && kill -9 -$$" SIGINT SIGTERM EXIT

export POLKADOT_BINARY=$POLKADOT_SDK_PATH/target/release/polkadot
export POLKADOT_PARACHAIN_BINARY=$POLKADOT_SDK_PATH/target/release/polkadot-parachain
export ZOMBIENET_BINARY=~/local_bridge_testing/bin/zombienet-linux-x64
export SUBSTRATE_RELAY_BINARY=~/local_bridge_testing/bin/substrate-relay

export TEST_DIR=`mktemp -d /tmp/bridges-tests-run-XXXXX`
echo -e "Test folder: $TEST_DIR\n"

test=$1
${BASH_SOURCE%/*}/tests/$test/run.sh
23 changes: 8 additions & 15 deletions bridges/zombienet/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,27 @@ done

# assuming that we'll be using native provide && all processes will be executing locally
# (we need absolute paths here, because they're used when scripts are called by zombienet from tmp folders)
export POLKADOT_SDK_FOLDER=`realpath $(dirname "$0")/../..`
export BRIDGE_TESTS_FOLDER=$POLKADOT_SDK_FOLDER/bridges/zombienet/tests
export POLKADOT_SDK_PATH=`realpath $(dirname "$0")/../..`
export BRIDGE_TESTS_FOLDER=$POLKADOT_SDK_PATH/bridges/zombienet/tests

# set pathc to binaries
if [ "$ZOMBIENET_DOCKER_PATHS" -eq 1 ]; then
export POLKADOT_BINARY_PATH=/usr/local/bin/polkadot
export POLKADOT_PARACHAIN_BINARY_PATH=/usr/local/bin/polkadot-parachain
export POLKADOT_PARACHAIN_BINARY_PATH_FOR_ASSET_HUB_ROCOCO=/usr/local/bin/polkadot-parachain
export POLKADOT_PARACHAIN_BINARY_PATH_FOR_ASSET_HUB_WESTEND=/usr/local/bin/polkadot-parachain
export POLKADOT_BINARY=/usr/local/bin/polkadot
export POLKADOT_PARACHAIN_BINARY=/usr/local/bin/polkadot-parachain

export SUBSTRATE_RELAY_PATH=/usr/local/bin/substrate-relay
export SUBSTRATE_RELAY_BINARY=/usr/local/bin/substrate-relay
export ZOMBIENET_BINARY_PATH=/usr/local/bin/zombie
else
export POLKADOT_BINARY_PATH=$POLKADOT_SDK_FOLDER/target/release/polkadot
export POLKADOT_PARACHAIN_BINARY_PATH=$POLKADOT_SDK_FOLDER/target/release/polkadot-parachain
export POLKADOT_PARACHAIN_BINARY_PATH_FOR_ASSET_HUB_ROCOCO=$POLKADOT_PARACHAIN_BINARY_PATH
export POLKADOT_PARACHAIN_BINARY_PATH_FOR_ASSET_HUB_WESTEND=$POLKADOT_PARACHAIN_BINARY_PATH
export POLKADOT_BINARY=$POLKADOT_SDK_PATH/target/release/polkadot
export POLKADOT_PARACHAIN_BINARY=$POLKADOT_SDK_PATH/target/release/polkadot-parachain

export SUBSTRATE_RELAY_PATH=~/local_bridge_testing/bin/substrate-relay
export SUBSTRATE_RELAY_BINARY=~/local_bridge_testing/bin/substrate-relay
export ZOMBIENET_BINARY_PATH=~/local_bridge_testing/bin/zombienet-linux
fi

# check if `wait` supports -p flag
if [ `printf "$BASH_VERSION\n5.1" | sort -V | head -n 1` = "5.1" ]; then IS_BASH_5_1=1; else IS_BASH_5_1=0; fi

# check if `wait` supports -p flag
if [ `printf "$BASH_VERSION\n5.1" | sort -V | head -n 1` = "5.1" ]; then IS_BASH_5_1=1; else IS_BASH_5_1=0; fi

# bridge configuration
export LANE_ID="00000002"

Expand Down
2 changes: 1 addition & 1 deletion bridges/zombienet/scripts/invoke-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

INVOKE_LOG=`mktemp -p $TEST_FOLDER invoke.XXXXX`

pushd $POLKADOT_SDK_FOLDER/cumulus/scripts
pushd $POLKADOT_SDK_PATH/cumulus/scripts
./bridges_rococo_westend.sh $1 >$INVOKE_LOG 2>&1
popd
2 changes: 1 addition & 1 deletion bridges/zombienet/scripts/start-relayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

RELAY_LOG=`mktemp -p $TEST_FOLDER relay.XXXXX`

pushd $POLKADOT_SDK_FOLDER/cumulus/scripts
pushd $POLKADOT_SDK_PATH/cumulus/scripts
./bridges_rococo_westend.sh run-relay >$RELAY_LOG 2>&1&
popd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Description: User is able to transfer ROC from Rococo Asset Hub to Westend Asset Hub and back
Network: ../../../../cumulus/zombienet/bridge-hubs/bridge_hub_westend_local_network.toml
Creds: config

# send ROC to //Alice from Rococo AH to Westend AH
asset-hub-westend-collator1: run ../../environments/rococo-westend/helper.sh with "reserve-transfer-assets-from-asset-hub-rococo-local" within 120 seconds

# check that //Alice received the ROC on Westend AH
asset-hub-westend-collator1: js-script ../../helpers/wrapped-assets-balance.js with "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY,0,Rococo" within 300 seconds

# check that the relayer //Charlie is rewarded by Westend AH
bridge-hub-westend-collator1: js-script ../../helpers/relayer-rewards.js with "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y,0x00000002,0x6268726F,ThisChain,0" within 30 seconds
22 changes: 22 additions & 0 deletions bridges/zombienet/tests/0001-asset-transfer/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

source "${BASH_SOURCE%/*}/../../utils/common.sh"
source "${BASH_SOURCE%/*}/../../utils/zombienet.sh"

${BASH_SOURCE%/*}/../../environments/rococo-westend/spawn.sh &

ensure_file $TEST_DIR/rococo.env 300
rococo_dir=`cat $TEST_DIR/rococo.env`
echo

ensure_file $TEST_DIR/westend.env 180
westend_dir=`cat $TEST_DIR/westend.env`
echo

run_zndsl ${BASH_SOURCE%/*}/roc-reaches-westend.zndsl $westend_dir
run_zndsl ${BASH_SOURCE%/*}/wnd-reaches-rococo.zndsl $rococo_dir

run_zndsl ${BASH_SOURCE%/*}/wroc-reaches-rococo.zndsl $rococo_dir
run_zndsl ${BASH_SOURCE%/*}/wwnd-reaches-westend.zndsl $westend_dir
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Description: User is able to transfer WND from Westend Asset Hub to Rococo Asset Hub and back
Network: ../../../../cumulus/zombienet/bridge-hubs/bridge_hub_rococo_local_network.toml
Creds: config

# send WND to //Alice from Westend AH to Rococo AH
asset-hub-rococo-collator1: run ../../environments/rococo-westend/helper.sh with "reserve-transfer-assets-from-asset-hub-westend-local" within 120 seconds

# check that //Alice received the WND on Rococo AH
asset-hub-rococo-collator1: js-script ../../helpers/wrapped-assets-balance.js with "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY,0,Westend" within 300 seconds

# check that the relayer //Charlie is rewarded by Rococo AH
bridge-hub-rococo-collator1: js-script ../../helpers/relayer-rewards.js with "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y,0x00000002,0x62687764,ThisChain,0" within 30 seconds
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Description: User is able to transfer ROC from Rococo Asset Hub to Westend Asset Hub and back
Network: ../../../../cumulus/zombienet/bridge-hubs/bridge_hub_westend_local_network.toml
Creds: config

# send wROC back to Alice from Westend AH to Rococo AH
asset-hub-rococo-collator1: run ../../environments/rococo-westend/helper.sh with "withdraw-reserve-assets-from-asset-hub-westend-local" within 120 seconds

# check that //Alice received the wROC on Rococo AH
# (we wait until //Alice account increases here - there are no other transactions that may increase it)
asset-hub-rococo-collator1: js-script ../../helpers/native-assets-balance-increased.js with "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" within 300 seconds
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Description: User is able to transfer ROC from Rococo Asset Hub to Westend Asset Hub and back
Network: ../../../../cumulus/zombienet/bridge-hubs/bridge_hub_westend_local_network.toml
Creds: config

# send wWND back to Alice from Rococo AH to Westend AH
asset-hub-westend-collator1: run ../../environments/rococo-westend/helper.sh with "withdraw-reserve-assets-from-asset-hub-rococo-local" within 120 seconds

# check that //Alice received the wWND on Westend AH
# (we wait until //Alice account increases here - there are no other transactions that may increase it)
asset-hub-westend-collator1: js-script ../../helpers/native-assets-balance-increased.js with "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" within 300 seconds
39 changes: 39 additions & 0 deletions bridges/zombienet/utils/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

function start_background_process() {
local command=$1
local log_file=$2
local __pid=$3

$command > $log_file 2>&1 &
eval $__pid="'$!'"
}

function wait_for_file() {
local file=$1
local timeout=$2
local __found=$3

local time=0
until [ -e $file ]; do
if (( time++ >= timeout )) then
serban300 marked this conversation as resolved.
Show resolved Hide resolved
echo "Timeout waiting for file $file: $timeout seconds"
eval $__found=0
return
fi
sleep 1
done

echo "File $file found after $time seconds"
eval $__found=1
}

function ensure_file() {
local file=$1
local timeout=$2

wait_for_file $file $timeout file_found
if [ $file_found != 1 ]; then
exit 1
fi
}
39 changes: 39 additions & 0 deletions bridges/zombienet/utils/zombienet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

source "${BASH_SOURCE%/*}/common.sh"

function start_zombienet() {
local test_dir=$1
local definition_path=$2
local __zombienet_dir=$3
local __zombienet_pid=$4

local zombienet_name=`basename $definition_path .toml`
local zombienet_dir=$test_dir/$zombienet_name
eval $__zombienet_dir="'$zombienet_dir'"
mkdir -p $zombienet_dir
rm -rf $zombienet_dir

local logs_dir=$test_dir/logs
mkdir -p $logs_dir
local zombienet_log=$logs_dir/$zombienet_name.log

echo "Starting $zombienet_name zombienet. Logs available at: $zombienet_log"
start_background_process \
"$ZOMBIENET_BINARY spawn --dir $zombienet_dir --provider native $definition_path" \
"$zombienet_log" zombienet_pid

ensure_file "$zombienet_dir/zombie.json" 180
echo "$zombienet_name zombienet started successfully"

eval $__zombienet_pid="'$zombienet_pid'"
}

function run_zndsl() {
local zndsl_file=$1
local zombienet_dir=$2

echo "Running $zndsl_file."
$ZOMBIENET_BINARY test --dir $zombienet_dir --provider native $zndsl_file $zombienet_dir/zombie.json
echo
}
10 changes: 4 additions & 6 deletions cumulus/parachains/runtimes/bridge-hubs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,17 @@ cp target/release/polkadot-parachain ~/local_bridge_testing/bin/polkadot-paracha
cd <polkadot-sdk-git-repo-dir>

# Rococo + BridgeHubRococo + AssetHub for Rococo (mirroring Kusama)
POLKADOT_BINARY_PATH=~/local_bridge_testing/bin/polkadot \
POLKADOT_PARACHAIN_BINARY_PATH=~/local_bridge_testing/bin/polkadot-parachain \
POLKADOT_PARACHAIN_BINARY_PATH_FOR_ASSET_HUB_ROCOCO=~/local_bridge_testing/bin/polkadot-parachain-asset-hub \
POLKADOT_BINARY=~/local_bridge_testing/bin/polkadot \
POLKADOT_PARACHAIN_BINARY=~/local_bridge_testing/bin/polkadot-parachain \
~/local_bridge_testing/bin/zombienet-linux --provider native spawn ./cumulus/zombienet/bridge-hubs/bridge_hub_rococo_local_network.toml
```

```
cd <polkadot-sdk-git-repo-dir>

# Westend + BridgeHubWestend + AssetHub for Westend (mirroring Polkadot)
POLKADOT_BINARY_PATH=~/local_bridge_testing/bin/polkadot \
POLKADOT_PARACHAIN_BINARY_PATH=~/local_bridge_testing/bin/polkadot-parachain \
POLKADOT_PARACHAIN_BINARY_PATH_FOR_ASSET_HUB_WESTEND=~/local_bridge_testing/bin/polkadot-parachain-asset-hub \
POLKADOT_BINARY=~/local_bridge_testing/bin/polkadot \
POLKADOT_PARACHAIN_BINARY=~/local_bridge_testing/bin/polkadot-parachain \
serban300 marked this conversation as resolved.
Show resolved Hide resolved
~/local_bridge_testing/bin/zombienet-linux --provider native spawn ./cumulus/zombienet/bridge-hubs/bridge_hub_westend_local_network.toml
```

Expand Down
2 changes: 1 addition & 1 deletion cumulus/scripts/bridges_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function relayer_path() {
local default_path=~/local_bridge_testing/bin/substrate-relay
local path="${SUBSTRATE_RELAY_PATH:-$default_path}"
local path="${SUBSTRATE_RELAY_BINARY:-$default_path}"
echo "$path"
}

Expand Down
2 changes: 1 addition & 1 deletion cumulus/scripts/bridges_rococo_westend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ function run_relay() {

case "$1" in
run-relay)
init_ro_wnd
init_wnd_ro
init_ro_wnd
svyatonik marked this conversation as resolved.
Show resolved Hide resolved
run_relay
;;
init-asset-hub-rococo-local)
Expand Down
Loading
Loading