run-migration-tests.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 joystream/node docker 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. # assume older version of joystream-cli is installed globally. So we run these commands to
  26. # work against older runtime. Assert it is version `@joystream/cli/0.5.1` ?
  27. joystream-cli --version
  28. joystream-cli account:choose --address 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
  29. echo "creating 1 channel"
  30. joystream-cli content:createChannel --input=./assets/TestChannel.json --context=Member || true
  31. echo "adding 1 video to the above channel"
  32. joystream-cli content:createVideo -c 1 --input=./assets/TestVideo.json || true
  33. # Confirm channel and video created successfully
  34. joystream-cli content:videos 1
  35. joystream-cli content:channel 1
  36. }
  37. function post_migration_hook() {
  38. echo "*** verify existence of the 5 new groups ***"
  39. yarn joystream-cli working-groups:overview --group=operationsAlpha
  40. yarn joystream-cli working-groups:overview --group=operationsBeta
  41. yarn joystream-cli working-groups:overview --group=operationsGamma
  42. yarn joystream-cli working-groups:overview --group=curators
  43. yarn joystream-cli working-groups:overview --group=distributors
  44. echo "*** verify previously created channel and video are cleared ***"
  45. # Allow a few blocks for migration to complete
  46. sleep 12
  47. # FIXME: Howto assert these fail as expected. They should report video and channel do no exist
  48. # Can we get json output to more easily parse result of query?
  49. set +e
  50. yarn joystream-cli content:channel 1
  51. if [ $? -eq 0 ]; then
  52. echo "Unexpected channel was found"
  53. exit -1
  54. fi
  55. # This cammand doesn't give error exit code if videos not found in a channel
  56. yarn joystream-cli content:videos 1
  57. }
  58. trap cleanup EXIT
  59. if [ "$TARGET_RUNTIME" == "$RUNTIME" ]; then
  60. echo "Not Performing a runtime upgrade."
  61. else
  62. pre_migration_hook
  63. # Copy new runtime wasm file from target joystream/node image
  64. echo "Extracting wasm blob from target joystream/node image."
  65. id=$(docker create joystream/node:${TARGET_RUNTIME})
  66. docker cp $id:/joystream/runtime.compact.wasm ${DATA_PATH}
  67. docker rm $id
  68. echo "Performing runtime upgrade."
  69. yarn workspace api-scripts tsnode-strict \
  70. src/dev-set-runtime-code.ts -- ${DATA_PATH}/runtime.compact.wasm
  71. echo "Runtime upgraded."
  72. # Display runtime version
  73. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
  74. echo "Performing migration tests"
  75. post_migration_hook
  76. echo "Done with migrations tests"
  77. fi