#!/usr/bin/env bash set -e SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")" cd $SCRIPT_PATH # Location that will be mounted as the /data volume in containers # This is how we access the initial members and balances files from # the containers and where generated chainspec files will be located. DATA_PATH=${DATA_PATH:=~/tmp} # Initial account balance for Alice # Alice is the source of funds for all new accounts that are created in the tests. ALICE_INITIAL_BALANCE=${ALICE_INITIAL_BALANCE:=100000000} # The docker image tag to use for joystream/node as the starting chain # that will be upgraded to the latest runtime. RUNTIME=${RUNTIME:=latest} TARGET_RUNTIME=${TARGET_RUNTIME:=latest} AUTO_CONFIRM=true mkdir -p ${DATA_PATH} echo "{ \"balances\":[ [\"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY\", ${ALICE_INITIAL_BALANCE}] ] }" > ${DATA_PATH}/initial-balances.json # Make Alice a member echo ' [{ "member_id":0, "root_account":"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", "controller_account":"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", "handle":"alice", "avatar_uri":"https://alice.com/avatar.png", "about":"Alice", "registered_at_time":0 }] ' > ${DATA_PATH}/initial-members.json # Create a chain spec file docker run --rm -v ${DATA_PATH}:/data --entrypoint ./chain-spec-builder joystream/node:${RUNTIME} \ new \ --authority-seeds Alice \ --sudo-account 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY \ --deployment dev \ --chain-spec-path /data/chain-spec.json \ --initial-balances-path /data/initial-balances.json \ --initial-members-path /data/initial-members.json # Convert the chain spec file to a raw chainspec file docker run --rm -v ${DATA_PATH}:/data joystream/node:${RUNTIME} build-spec \ --raw --disable-default-bootnode \ --chain /data/chain-spec.json > ~/tmp/chain-spec-raw.json # Start a chain with generated chain spec export JOYSTREAM_NODE_TAG=${RUNTIME} CONTAINER_ID=`docker-compose -f ../../docker-compose.yml run -d -v ${DATA_PATH}:/data --name joystream-node \ -p 9944:9944 -p 9933:9933 joystream-node \ --alice --validator --unsafe-ws-external --unsafe-rpc-external \ --rpc-methods Unsafe --rpc-cors=all -l runtime \ --chain /data/chain-spec-raw.json` function cleanup() { docker logs ${CONTAINER_ID} --tail 15 docker stop ${CONTAINER_ID} docker rm ${CONTAINER_ID} rm tests/network-tests/assets/TestChannel__rejectedContent.json rm tests/network-tests/assets/TestVideo__rejectedContent.json } function pre_migration_hook() { sleep 5 # needed otherwise docker image won't be ready yet yarn joystream-cli account:choose --address 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice echo "creating 1 channel" yarn joystream-cli content:createChannel --input=./assets/TestChannel.json --context=Member || true echo "adding 1 video to the above channel" yarn joystream-cli content:createVideo -c 1 --input=./assets/TestVideo.json || true } function post_migration_hook() { echo "*** verify existence of the 5 new groups ***" yarn joystream-cli working-groups:overview --group=operationsAlpha yarn joystream-cli working-groups:overview --group=operationsBeta yarn joystream-cli working-groups:overview --group=operationsGamma yarn joystream-cli working-groups:overview --group=curators yarn joystream-cli working-groups:overview --group=distributors echo "*** verify previously created channel and video are cleared ***" yarn joystream-cli content:videos 1 yarn joystream-cli content:channel 1 } trap cleanup EXIT if [ "$TARGET_RUNTIME" == "$RUNTIME" ]; then echo "Not Performing a runtime upgrade." else # pre migration hook pre_migration_hook # Copy new runtime wasm file from target joystream/node image echo "Extracting wasm blob from target joystream/node image." id=`docker create joystream/node:${TARGET_RUNTIME}` docker cp $id:/joystream/runtime.compact.wasm ${DATA_PATH} docker rm $id # Display runtime version before runtime upgrade yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime echo "Performing runtime upgrade." yarn workspace api-scripts tsnode-strict \ src/dev-set-runtime-code.ts -- ${DATA_PATH}/runtime.compact.wasm echo "Runtime upgraded." echo "Performing migration tests" # post migration hook post_migration_hook echo "Done with migrations tests" fi # Display runtime version yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime