run-migration-tests.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/env bash
  2. set -e
  3. SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
  4. cd $SCRIPT_PATH
  5. # Location that will be mounted as the /data volume in containers
  6. # This is how we access the initial members and balances files from
  7. # the containers and where generated chainspec files will be located.
  8. DATA_PATH=${DATA_PATH:=~/tmp}
  9. # Initial account balance for Alice
  10. # Alice is the source of funds for all new accounts that are created in the tests.
  11. ALICE_INITIAL_BALANCE=${ALICE_INITIAL_BALANCE:=100000000}
  12. # The docker image tag to use for joystream/node as the starting chain
  13. # that will be upgraded to the latest runtime.
  14. RUNTIME=${RUNTIME:=latest}
  15. TARGET_RUNTIME=${TARGET_RUNTIME:=latest}
  16. AUTO_CONFIRM=true
  17. mkdir -p ${DATA_PATH}
  18. echo "{
  19. \"balances\":[
  20. [\"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY\", ${ALICE_INITIAL_BALANCE}]
  21. ]
  22. }" > ${DATA_PATH}/initial-balances.json
  23. # Make Alice a member
  24. echo '
  25. [{
  26. "member_id":0,
  27. "root_account":"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
  28. "controller_account":"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
  29. "handle":"alice",
  30. "avatar_uri":"https://alice.com/avatar.png",
  31. "about":"Alice",
  32. "registered_at_time":0
  33. }]
  34. ' > ${DATA_PATH}/initial-members.json
  35. # Create a chain spec file
  36. docker run --rm -v ${DATA_PATH}:/data --entrypoint ./chain-spec-builder joystream/node:${RUNTIME} \
  37. new \
  38. --authority-seeds Alice \
  39. --sudo-account 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY \
  40. --deployment dev \
  41. --chain-spec-path /data/chain-spec.json \
  42. --initial-balances-path /data/initial-balances.json \
  43. --initial-members-path /data/initial-members.json
  44. # Convert the chain spec file to a raw chainspec file
  45. docker run --rm -v ${DATA_PATH}:/data joystream/node:${RUNTIME} build-spec \
  46. --raw --disable-default-bootnode \
  47. --chain /data/chain-spec.json > ~/tmp/chain-spec-raw.json
  48. # Start a chain with generated chain spec
  49. export JOYSTREAM_NODE_TAG=${RUNTIME}
  50. CONTAINER_ID=`docker-compose -f ../../docker-compose.yml run -d -v ${DATA_PATH}:/data --name joystream-node \
  51. -p 9944:9944 -p 9933:9933 joystream-node \
  52. --alice --validator --unsafe-ws-external --unsafe-rpc-external \
  53. --rpc-methods Unsafe --rpc-cors=all -l runtime \
  54. --chain /data/chain-spec-raw.json`
  55. function cleanup() {
  56. docker logs ${CONTAINER_ID} --tail 15
  57. docker stop ${CONTAINER_ID}
  58. docker rm ${CONTAINER_ID}
  59. rm tests/network-tests/assets/TestChannel__rejectedContent.json
  60. rm tests/network-tests/assets/TestVideo__rejectedContent.json
  61. }
  62. function pre_migration_hook() {
  63. sleep 5 # needed otherwise docker image won't be ready yet
  64. yarn joystream-cli account:choose --address 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
  65. echo "creating 1 channel"
  66. yarn joystream-cli content:createChannel --input=./assets/TestChannel.json --context=Member || true
  67. echo "adding 1 video to the above channel"
  68. yarn joystream-cli content:createVideo -c 1 --input=./assets/TestVideo.json || true
  69. }
  70. function post_migration_hook() {
  71. echo "*** verify existence of the 5 new groups ***"
  72. yarn joystream-cli working-groups:overview --group=operationsAlpha
  73. yarn joystream-cli working-groups:overview --group=operationsBeta
  74. yarn joystream-cli working-groups:overview --group=operationsGamma
  75. yarn joystream-cli working-groups:overview --group=curators
  76. yarn joystream-cli working-groups:overview --group=distributors
  77. echo "*** verify previously created channel and video are cleared ***"
  78. yarn joystream-cli content:videos 1
  79. yarn joystream-cli content:channel 1
  80. }
  81. trap cleanup EXIT
  82. if [ "$TARGET_RUNTIME" == "$RUNTIME" ]; then
  83. echo "Not Performing a runtime upgrade."
  84. else
  85. # pre migration hook
  86. pre_migration_hook
  87. # Copy new runtime wasm file from target joystream/node image
  88. echo "Extracting wasm blob from target joystream/node image."
  89. id=`docker create joystream/node:${TARGET_RUNTIME}`
  90. docker cp $id:/joystream/runtime.compact.wasm ${DATA_PATH}
  91. docker rm $id
  92. # Display runtime version before runtime upgrade
  93. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
  94. echo "Performing runtime upgrade."
  95. yarn workspace api-scripts tsnode-strict \
  96. src/dev-set-runtime-code.ts -- ${DATA_PATH}/runtime.compact.wasm
  97. echo "Runtime upgraded."
  98. echo "Performing migration tests"
  99. # post migration hook
  100. post_migration_hook
  101. echo "Done with migrations tests"
  102. fi
  103. # Display runtime version
  104. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime