Skip to content

Commit

Permalink
Bridges: add test 0002 to CI (paritytech#3310)
Browse files Browse the repository at this point in the history
Bridges: add test 0002 to CI
  • Loading branch information
serban300 committed Feb 14, 2024
1 parent aa68ea5 commit 1b66bb5
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .gitlab/pipeline/zombienet/bridges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ zombienet-bridges-0001-asset-transfer-works:
script:
- /home/nonroot/bridges-polkadot-sdk/bridges/zombienet/run-new-test.sh 0001-asset-transfer --docker
- echo "Done"

zombienet-bridges-0002-mandatory-headers-synced-while-idle:
extends:
- .zombienet-bridges-common
script:
- /home/nonroot/bridges-polkadot-sdk/bridges/zombienet/run-new-test.sh 0002-mandatory-headers-synced-while-idle --docker
- echo "Done"
17 changes: 8 additions & 9 deletions bridges/zombienet/environments/rococo-westend/spawn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ set -e

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

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

# whether to init the chains (open HRMP channels, set XCM version, create reserve assets, etc)
init=0
start_relayer=0
while [ $# -ne 0 ]
do
arg="$1"
case "$arg" in
--init)
init=1
;;
--start-relayer)
start_relayer=1
;;
esac
shift
done
Expand Down Expand Up @@ -55,17 +58,13 @@ if [[ $init -eq 1 ]]; then
run_zndsl ${BASH_SOURCE%/*}/westend-init.zndsl $westend_dir
fi

relay_log=$logs_dir/relay.log
echo -e "Starting rococo-westend relay. Logs available at: $relay_log\n"
start_background_process "$helper_script run-relay" $relay_log relay_pid
if [[ $start_relayer -eq 1 ]]; then
${BASH_SOURCE%/*}/start_relayer.sh $rococo_dir $westend_dir relayer_pid
fi

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
wait -n $rococo_pid $westend_pid $relayer_pid
kill -9 -$$
23 changes: 23 additions & 0 deletions bridges/zombienet/environments/rococo-westend/start_relayer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

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

rococo_dir=$1
westend_dir=$2
__relayer_pid=$3

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

relayer_log=$logs_dir/relayer.log
echo -e "Starting rococo-westend relayer. Logs available at: $relayer_log\n"
start_background_process "$helper_script run-relay" $relayer_log relayer_pid

run_zndsl ${BASH_SOURCE%/*}/rococo.zndsl $rococo_dir
run_zndsl ${BASH_SOURCE%/*}/westend.zndsl $westend_dir

eval $__relayer_pid="'$relayer_pid'"

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

// start listening to new blocks
let totalGrandpaHeaders = 0;
let totalParachainHeaders = 0;
let initialParachainHeaderImported = false;
api.rpc.chain.subscribeNewHeads(async function (header) {
const apiAtParent = await api.at(header.parentHash);
const apiAtCurrent = await api.at(header.hash);
Expand All @@ -22,7 +22,7 @@ async function run(nodeName, networkInfo, args) {
apiAtCurrent,
currentEvents,
);
totalParachainHeaders += await utils.ensureOnlyInitialParachainHeaderImported(
initialParachainHeaderImported = await utils.ensureOnlyInitialParachainHeaderImported(
bridgedChain,
apiAtParent,
apiAtCurrent,
Expand All @@ -36,7 +36,7 @@ async function run(nodeName, networkInfo, args) {
if (totalGrandpaHeaders == 0) {
throw new Error("No bridged relay chain headers imported");
}
if (totalParachainHeaders == 0) {
if (!initialParachainHeaderImported) {
throw new Error("No bridged parachain headers imported");
}
}
Expand Down
2 changes: 1 addition & 1 deletion bridges/zombienet/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ module.exports = {
throw new Error("Unexpected parachain header import: " + newParachainHeaders + " / " + maxNewParachainHeaders);
}

return newParachainHeaders;
return hasBestBridgedParachainHeader;
},
}
4 changes: 2 additions & 2 deletions bridges/zombienet/run-new-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

trap 'kill -9 -$$ || echo "Environment already teared down"' SIGINT SIGTERM EXIT

test=$1
shift

Expand Down Expand Up @@ -43,5 +45,3 @@ export TEST_DIR=`mktemp -d /tmp/bridges-tests-run-XXXXX`
echo -e "Test folder: $TEST_DIR\n"

${BASH_SOURCE%/*}/tests/$test/run.sh

kill -9 -$$ || echo "Environment already teared down"
2 changes: 1 addition & 1 deletion bridges/zombienet/tests/0001-asset-transfer/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
source "${BASH_SOURCE%/*}/../../utils/common.sh"
source "${BASH_SOURCE%/*}/../../utils/zombienet.sh"

${BASH_SOURCE%/*}/../../environments/rococo-westend/spawn.sh --init &
${BASH_SOURCE%/*}/../../environments/rococo-westend/spawn.sh --init --start-relayer &
env_pid=$!

ensure_process_file $env_pid $TEST_DIR/rococo.env 400
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Description: While relayer is idle, we only sync mandatory Rococo (and a single Rococo BH) headers to Westend BH.
Network: ../../../../cumulus/zombienet/bridge-hubs/bridge_hub_westend_local_network.toml
Creds: config

# ensure that relayer is only syncing mandatory headers while idle. This includes both headers that were
# generated while relay was offline and those in the next 100 seconds while script is active.
bridge-hub-westend-collator1: js-script ../../helpers/only-mandatory-headers-synced-when-idle.js with "300,rococo-at-westend" within 600 seconds

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -e

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

# We use `--relayer-delay` in order to sleep some time before starting relayer.
# We want to sleep for at least 1 session, which is expected to be 60 seconds for test environment.
${BASH_SOURCE%/*}/../../environments/rococo-westend/spawn.sh &
env_pid=$!

ensure_process_file $env_pid $TEST_DIR/rococo.env 400
rococo_dir=`cat $TEST_DIR/rococo.env`
echo

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

# Sleep for some time before starting the relayer. We want to sleep for at least 1 session,
# which is expected to be 60 seconds for the test environment.
echo -e "Sleeping 90s before starting relayer ...\n"
sleep 90
${BASH_SOURCE%/*}/../../environments/rococo-westend/start_relayer.sh $rococo_dir $westend_dir relayer_pid

# Sometimes the relayer syncs multiple parachain heads in the begining leading to test failures.
# See issue: https://github.com/paritytech/parity-bridges-common/issues/2838.
# TODO: Remove this sleep after the issue is fixed.
echo -e "Sleeping 180s before runing the tests ...\n"
sleep 180

run_zndsl ${BASH_SOURCE%/*}/rococo-to-westend.zndsl $westend_dir
run_zndsl ${BASH_SOURCE%/*}/westend-to-rococo.zndsl $rococo_dir

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Description: While relayer is idle, we only sync mandatory Westend (and a single Westend BH) headers to Rococo BH.
Network: ../../../../cumulus/zombienet/bridge-hubs/bridge_hub_rococo_local_network.toml
Creds: config

# ensure that relayer is only syncing mandatory headers while idle. This includes both headers that were
# generated while relay was offline and those in the next 100 seconds while script is active.
bridge-hub-rococo-collator1: js-script ../../helpers/only-mandatory-headers-synced-when-idle.js with "300,westend-at-rococo" within 600 seconds

0 comments on commit 1b66bb5

Please sign in to comment.