run-migration-tests.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. NETWORK_ARG=
  49. if [ "$ATTACH_TO_NETWORK" != "" ]; then
  50. NETWORK_ARG="--network ${ATTACH_TO_NETWORK}"
  51. fi
  52. # Start a chain with generated chain spec
  53. # Add "-l ws=trace,ws::handler=info" to get websocket trace logs
  54. CONTAINER_ID=`docker run -d -v ${DATA_PATH}:/data -p 9944:9944 ${NETWORK_ARG} --name joystream-node joystream/node:${RUNTIME} \
  55. --validator --alice --unsafe-ws-external --rpc-cors=all -l runtime \
  56. --chain /data/chain-spec-raw.json`
  57. function cleanup() {
  58. docker logs ${CONTAINER_ID} --tail 15
  59. docker stop ${CONTAINER_ID}
  60. docker rm ${CONTAINER_ID}
  61. rm tests/network-tests/assets/TestChannel__rejectedContent.json
  62. rm tests/network-tests/assets/TestVideo__rejectedContent.json
  63. }
  64. function pre_migration_hook() {
  65. sleep 5 # needed otherwise docker image won't be ready yet
  66. yarn joystream-cli account:choose --address 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
  67. echo "creating 1 channel"
  68. yarn joystream-cli content:createChannel --input=./assets/TestChannel.json --context=Member || true
  69. echo "adding 1 video to the above channel"
  70. yarn joystream-cli content:createVideo -c 1 --input=./assets/TestVideo.json || true
  71. }
  72. function post_migration_hook() {
  73. echo "*** verify existence of the 5 new groups ***"
  74. yarn joystream-cli working-groups:overview --group=operationsAlpha
  75. yarn joystream-cli working-groups:overview --group=operationsBeta
  76. yarn joystream-cli working-groups:overview --group=operationsGamma
  77. yarn joystream-cli working-groups:overview --group=curators
  78. yarn joystream-cli working-groups:overview --group=distributors
  79. echo "*** verify previously created channel and video are cleared ***"
  80. yarn joystream-cli content:videos 1
  81. yarn joystream-cli content:channel 1
  82. }
  83. trap cleanup EXIT
  84. if [ "$TARGET_RUNTIME" == "$RUNTIME" ]; then
  85. echo "Not Performing a runtime upgrade."
  86. else
  87. # pre migration hook
  88. pre_migration_hook
  89. # Copy new runtime wasm file from target joystream/node image
  90. echo "Extracting wasm blob from target joystream/node image."
  91. id=`docker create joystream/node:${TARGET_RUNTIME}`
  92. docker cp $id:/joystream/runtime.compact.wasm ${DATA_PATH}
  93. docker rm $id
  94. # Display runtime version before runtime upgrade
  95. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
  96. echo "Performing runtime upgrade."
  97. yarn workspace api-scripts tsnode-strict \
  98. src/dev-set-runtime-code.ts -- ${DATA_PATH}/runtime.compact.wasm
  99. echo "Runtime upgraded."
  100. echo "Performing migration tests"
  101. # post migration hook
  102. post_migration_hook
  103. echo "Done with migrations tests"
  104. fi
  105. # Display runtime version
  106. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime