Browse Source

Merge branch 'giza_it_migration_scripts' of https://github.com/ignazio-bovo/joystream into giza_it_migration_scripts

ignazio 3 years ago
parent
commit
a974830a14
2 changed files with 121 additions and 44 deletions
  1. 0 6
      tests/network-tests/.env
  2. 121 38
      tests/network-tests/run-migration-tests.sh

+ 0 - 6
tests/network-tests/.env

@@ -53,12 +53,6 @@ SLASH_AMOUNT=2
 # Stake decrement amount for manage working group lead testing scenario
 STAKE_DECREMENT=3
 # Mint capacity increment value for working gorup mint capacity test
-MINT_CAPACITY_INCREMENT = 1000
-# Mini-secret or mnemonic used in SURI for deterministic key derivation
-SURI_MINI_SECRET = ""
-# The starting key id to use when running a scenario. This will allow scenario
-# to be able to use all accounts generated in a prior scenario run against the same chain
-START_KEY_ID = 0
 MINT_CAPACITY_INCREMENT=1000
 # Storage node address to download content from
 STORAGE_NODE_URL=http://localhost:3001/asset/v0

+ 121 - 38
tests/network-tests/run-migration-tests.sh

@@ -4,30 +4,87 @@ set -e
 SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
 cd $SCRIPT_PATH
 
-<<<<<<< HEAD
-# Location to store runtime WASM for runtime upgrade
-DATA_PATH=$PWD/data
+# The joystream/node docker image tag which contains WASM runtime to upgrade chain with
+TARGET_RUNTIME_TAG=${TARGET_RUNTIME_TAG:=latest}
+# The joystream/node docker image tag to start the chain with
+RUNTIME_TAG=${RUNTIME_TAG:=sumer}
+# Use fork-off tool in order to clone live $TARGET_RUNTIME_TAG state
+CLONE_CURRENT_STATE=${CLONE_CURRENT_STATE:=$false}
+# If state modification by means of joystream-cli are required before migration
+PRE_MIGRATION_CLI_SETUP=${PRE_MIGRATION_CLI_SETUP:=$true}
+# If state modification by means of typescript scenarios are required before migration
+PRE_MIGRATION_ASYNC_SETUP=${PRE_MIGRATION_ASYNC_SETUP:=$false}
+# Post migration assertions by means of joystream-cli required
+POST_MIGRATION_CLI_ASSERTIONS=${POST_MIGRATION_CLI_ASSERTIONS=$true}
+# Post migration assertions by means of typescript scenarios required
+POST_MIGRATION_ASYNC_ASSERTIONS=${POST_MIGRATION_ASYNC_ASSERTIONS=$false}
 
-# The joystream/node docker image tag to start chain
-export RUNTIME=${RUNTIME:=latest}
+export WS_RPC_ENDPOINT="wss://testnet-rpc-3-uk.joystream.org"
+    
+# source common function used for node setup
+source ./node-utils.sh
+source ./.env
 
-# The joystream/node docker image tag which contains WASM runtime to upgrade chain with
-TARGET_RUNTIME=${TARGET_RUNTIME:=latest}
+#######################################
+# use fork-off to generate a chainspec file with the current s
+# Globals:
+#   DATA_PATH
+# Arguments:
+#   None
+#######################################
+function fork_off_init() {
+    # chain-spec-raw already existing
 
-# Prevent joystream cli from prompting
-export AUTO_CONFIRM=true
+    if ! [[ -f $(pwd)/storage.json ]]; then
+	scp ignazio@testnet-rpc-3-uk.joystream.org:/home/ignazio/storage.json ./storage.json
+    fi
+	cp $(pwd)/storage.json ${DATA_PATH}/storage.json    
 
-# Create chainspec with Alice (sudo) as member so we can use her in joystream-cli
-CONTAINER_ID=$(MAKE_SUDO_MEMBER=true ./run-test-node-docker.sh)
+    if ! [[ -f ${DATA_PATH}/schema.json ]]; then
+	cp $(pwd)/../../types/augment/all/defs.json ${DATA_PATH}/schema.json
+    fi
 
-function cleanup() {
-    docker logs ${CONTAINER_ID} --tail 15
-    docker-compose -f ../../docker-compose.yml down -v
-    rm ./assets/TestChannel__rejectedContent.json || true
-    rm ./assets/TestVideo__rejectedContent.json || true
+    id=$(docker create joystream/node:${TARGET_RUNTIME_TAG})
+    docker cp $id:/joystream/runtime.compact.wasm ${DATA_PATH}/runtime.wasm
+#    cat ${DATA_PATH}/runtime.wasm | hexdump -ve '/1 "%02x"\' > ${DATA_PATH}/runtime.hex
+    
+    yarn workspace api-scripts tsnode-strict src/fork-off.ts
 }
+#######################################
+# create initial-balances.json & initial-members.json files
+# Globals:
+#   DATA_PATH
+# Arguments:
+#   None
+#######################################
+function upgrade_runtime() {
+    if [ "$TARGET_RUNTIME_TAG" == "$RUNTIME_TAG" ]; then
+	echo "Not Performing a runtime upgrade."
+    else
+	echo "**** PERFORMING RUNTIME UPGRADE ****"	
+	# Copy new runtime wasm file from target joystream/node image
+	id=$(docker create joystream/node:${TARGET_RUNTIME_TAG})
+	docker cp $id:/joystream/runtime.compact.wasm ${DATA_PATH}
+	docker rm $id
 
-function pre_migration_hook() {
+	yarn workspace api-scripts tsnode-strict \
+	     src/dev-set-runtime-code.ts -- ${DATA_PATH}/runtime.compact.wasm
+
+	echo "**** RUNTIME UPGRADED ****"
+
+	# # Display runtime version
+	# yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
+    fi
+}
+
+#######################################
+# Setup pre migration scenario
+# Globals:
+#   None
+# Arguments:
+#   None
+#######################################
+function pre_migration_cli() {
   sleep 10 # needed otherwise docker image won't be ready yet
   # Display runtime version
   yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
@@ -47,7 +104,14 @@ function pre_migration_hook() {
   joystream-cli content:channel 1
 }
 
-function post_migration_hook() {
+#######################################
+# Verifies post migration assertions
+# Globals:
+#   None
+# Arguments:
+#   None
+#######################################
+function post_migration_cli() {
   echo "*** verify existence of the 5 new groups ***"
   yarn joystream-cli working-groups:overview --group=operationsAlpha
   yarn joystream-cli working-groups:overview --group=operationsBeta
@@ -69,25 +133,6 @@ function post_migration_hook() {
   fi
   # This cammand doesn't give error exit code if videos not found in a channel
   yarn joystream-cli content:videos 1
-}    
-
-trap cleanup EXIT
-
-if [ "$TARGET_RUNTIME" == "$RUNTIME" ]; then
-  echo "Not Performing a runtime upgrade."
-else
-  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
-
-  echo "Performing runtime upgrade."
-  yarn workspace api-scripts tsnode-strict \
-    src/dev-set-runtime-code.ts -- ${DATA_PATH}/runtime.compact.wasm
-=======
 # The joystream/node docker image tag which contains WASM runtime to upgrade chain with
 TARGET_RUNTIME_TAG=${TARGET_RUNTIME_TAG:=latest}
 # The joystream/node docker image tag to start the chain with
@@ -179,7 +224,6 @@ function pre_migration_cli() {
   # assume older version of joystream-cli is installed globally. So we run these commands to
   # work against older runtime. Assert it is version  `@joystream/cli/0.5.1` ?
   joystream-cli --version
->>>>>>> c3007a79d9 (added migration scripts & utils.sh file)
 
   joystream-cli account:choose --address 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
   echo "creating 1 channel"
@@ -261,3 +305,42 @@ function main {
 # main entrypoint
 main
 trap cleanup EXIT
+=======
+}
+
+# entrypoint
+function main {
+    # Section A: pre migration
+
+    CONTAINER_ID=""
+
+    echo "**** CREATING EMPTY CHAINSPEC ****"
+    create_initial_config
+    create_chainspec_file
+    convert_chainspec
+    echo "**** EMPTY CHAINSPEC CREATED SUCCESSFULLY ****"
+
+    # use forkoff to update chainspec with the live state + update runtime code
+    # fork_off_init
+
+    echo "***** STARTING NODE WITH FORKED STATE *****"
+    JOYSTREAM_NODE_TAG=$TARGET_RUNTIME_TAG
+    CONTAINER_ID=$(start_node)
+
+    # Section C: assertions
+    # verify that the number of outstanding channels & videos == 0
+    if ( $POST_MIGRATION_CLI_ASSERTIONS ); then
+	# verify assertion using cli
+	echo "***** POST MIGRATION CLI *****"
+	post_migration_cli
+    fi
+    
+    # if [[ $POST_MIGRATION_ASYNC_ASSERTION]]; then
+    # 	# verify assertion using scenarios
+    # fi
+}
+
+# main entrypoint
+main
+cleanup
+