Browse Source

refactored scripts

ignazio-bovo 3 years ago
parent
commit
37da76e7d7

+ 0 - 16
tests/network-tests/post_migration_hook.sh

@@ -1,16 +0,0 @@
-#!/usr/bin/env bash
-set -e
-
-SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
-cd $SCRIPT_PATH
-
-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

+ 0 - 13
tests/network-tests/pre_migration_hook.sh

@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-set -e
-
-# SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
-# cd $SCRIPT_PATH
-
-export AUTO_CONFIRM=true
-
-sleep 5 # needed otherwise docker image won't be ready yet
-echo "creating 1 channel"
-joystream-cli content:createChannel --input=./assets/TestChannel.json --context=Member || true
-echo "adding 1 video to the above channel"
-joystream-cli content:createVideo -c 1 --input=./assets/TestVideo.json || true

+ 128 - 0
tests/network-tests/run-migration-tests.sh

@@ -0,0 +1,128 @@
+#!/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}
+
+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
+
+NETWORK_ARG=
+if [ "$ATTACH_TO_NETWORK" != "" ]; then
+  NETWORK_ARG="--network ${ATTACH_TO_NETWORK}"
+fi
+
+# Start a chain with generated chain spec
+# Add "-l ws=trace,ws::handler=info" to get websocket trace logs
+CONTAINER_ID=`docker run -d -v ${DATA_PATH}:/data -p 9944:9944 ${NETWORK_ARG} --name joystream-node joystream/node:${RUNTIME} \
+  --validator --alice --unsafe-ws-external --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}
+}
+
+export AUTO_CONFIRM=true
+function pre_migration_hook() {
+sleep 5 # needed otherwise docker image won't be ready yet
+joystream-cli account:choose --address 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
+echo "creating 1 channel"
+joystream-cli content:createChannel --input=./assets/TestChannel.json --context=Member || true
+echo "adding 1 video to the above channel"
+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
+

+ 1 - 29
tests/network-tests/run-tests.sh

@@ -16,7 +16,6 @@ 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}
 
 mkdir -p ${DATA_PATH}
 
@@ -73,34 +72,7 @@ function cleanup() {
 
 trap cleanup EXIT
 
-if [ "$TARGET_RUNTIME" == "$RUNTIME" ]; then
-  echo "Not Performing a runtime upgrade."
-else
-  # pre migration hook
-  ./pre_migration_hook.sh $1    
-    
-  # 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.sh $1
-  echo "Done with migrations tests"
-fi
-
 # Display runtime version
 yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
 
-# ./run-test-scenario.sh $1
+./run-test-scenario.sh $1