run-migration-tests.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env bash
  2. set -e
  3. SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
  4. cd $SCRIPT_PATH
  5. # Location to store runtime WASM for runtime upgrade
  6. DATA_PATH=${DATA_PATH:=$(pwd)/data}
  7. # The djoystream/node ocker image tag to start chain
  8. export RUNTIME=${RUNTIME:=latest}
  9. # The joystream/node docker image tag which contains WASM runtime to upgrade chain with
  10. TARGET_RUNTIME=${TARGET_RUNTIME:=latest}
  11. # Prevent joystream cli from prompting
  12. export AUTO_CONFIRM=true
  13. # Create chainspec with Alice (sudo) as member so we can use her in joystream-cli
  14. CONTAINER_ID=`MAKE_SUDO_MEMBER=true ./run-test-node-docker.sh`
  15. function cleanup() {
  16. docker logs ${CONTAINER_ID} --tail 15
  17. docker-compose -f ../../docker-compose.yml down -v
  18. rm ./assets/TestChannel__rejectedContent.json || true
  19. rm ./assets/TestVideo__rejectedContent.json || true
  20. }
  21. function pre_migration_hook() {
  22. sleep 10 # needed otherwise docker image won't be ready yet
  23. # Display runtime version
  24. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
  25. yarn joystream-cli account:choose --address 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
  26. echo "creating 1 channel"
  27. yarn joystream-cli content:createChannel --input=./assets/TestChannel.json --context=Member || true
  28. echo "adding 1 video to the above channel"
  29. yarn joystream-cli content:createVideo -c 1 --input=./assets/TestVideo.json || true
  30. }
  31. function post_migration_hook() {
  32. echo "*** verify existence of the 5 new groups ***"
  33. yarn joystream-cli working-groups:overview --group=operationsAlpha
  34. yarn joystream-cli working-groups:overview --group=operationsBeta
  35. yarn joystream-cli working-groups:overview --group=operationsGamma
  36. yarn joystream-cli working-groups:overview --group=curators
  37. yarn joystream-cli working-groups:overview --group=distributors
  38. echo "*** verify previously created channel and video are cleared ***"
  39. # FIXME: assert these fail as expected
  40. yarn joystream-cli content:videos 1 || true
  41. yarn joystream-cli content:channel 1 || true
  42. }
  43. trap cleanup EXIT
  44. if [ "$TARGET_RUNTIME" == "$RUNTIME" ]; then
  45. echo "Not Performing a runtime upgrade."
  46. else
  47. # FIXME: code against old runtime will fail running from newer runtime code
  48. pre_migration_hook
  49. # Copy new runtime wasm file from target joystream/node image
  50. echo "Extracting wasm blob from target joystream/node image."
  51. id=$(docker create joystream/node:${TARGET_RUNTIME})
  52. docker cp $id:/joystream/runtime.compact.wasm ${DATA_PATH}
  53. docker rm $id
  54. # Display runtime version before runtime upgrade
  55. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
  56. echo "Performing runtime upgrade."
  57. yarn workspace api-scripts tsnode-strict \
  58. src/dev-set-runtime-code.ts -- ${DATA_PATH}/runtime.compact.wasm
  59. echo "Runtime upgraded."
  60. echo "Performing migration tests"
  61. # post migration hook
  62. post_migration_hook
  63. echo "Done with migrations tests"
  64. fi
  65. # Display runtime version
  66. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime