run-migration-tests.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env bash
  2. set -e
  3. SCRIPT_PATH="$(dirname "${BASH_SOURCE[0]}")"
  4. cd $SCRIPT_PATH
  5. # The joystream/node docker image tag which contains WASM runtime to upgrade chain with
  6. TARGET_RUNTIME_TAG=${TARGET_RUNTIME_TAG:=$(../../scripts/runtime-code-shasum.sh)}
  7. # The joystream/node docker image tag to start the chain with
  8. RUNTIME_TAG=${RUNTIME_TAG:=sumer}
  9. # Post migration assertions by means of typescript scenarios required
  10. POST_MIGRATION_ASYNC_ASSERTIONS=${POST_MIGRATION_ASYNC_ASSERTIONS:=$true}
  11. # source common function used for node setup
  12. source ./node-utils.sh
  13. #######################################
  14. # use fork-off to generate a chainspec file with the current s
  15. # Globals:
  16. # DATA_PATH
  17. # Arguments:
  18. # None
  19. #######################################
  20. function fork_off_init() {
  21. # chain-spec-raw already existing
  22. if ! [[ -f ${DATA_PATH}/storage.json ]]; then
  23. curl http://testnet-rpc-3-uk.joystream.org:9933 -H \
  24. "Content-type: application/json" -d \
  25. '{"jsonrpc":"2.0","id":1,"method":"state_getPairs","params":["0x"]}' \
  26. > ${DATA_PATH}/storage.json
  27. fi
  28. if ! [[ -f ${DATA_PATH}/schema.json ]]; then
  29. cp $SCRIPT_PATH/../../types/augment/all/defs.json ${DATA_PATH}/schema.json
  30. fi
  31. id=$(docker create joystream/node:${TARGET_RUNTIME_TAG})
  32. docker cp $id:/joystream/runtime.compact.wasm ${DATA_PATH}/runtime.wasm
  33. # RPC endpoint for live RUNTIME testnet
  34. WS_RPC_ENDPOINT="wss://testnet-rpc-3-uk.joystream.org" \
  35. yarn workspace api-scripts tsnode-strict src/fork-off.ts
  36. }
  37. function export_chainspec_file_to_disk() {
  38. echo "**** Initializing node database by exporting state ****"
  39. # write the initial genesis state to db, in order to avoid waiting for an arbitrary amount of time
  40. docker-compose -f ../../docker-compose.yml run \
  41. -v ${DATA_PATH}:/spec joystream-node export-state \
  42. --chain /spec/chain-spec-raw.json \
  43. --base-path /data --pruning archive > ${DATA_PATH}/exported-state.json
  44. }
  45. # entrypoint
  46. function main {
  47. CONTAINER_ID=""
  48. echo "**** CREATING EMPTY CHAINSPEC ****"
  49. create_initial_config
  50. create_chainspec_file
  51. convert_chainspec
  52. echo "**** EMPTY CHAINSPEC CREATED SUCCESSFULLY ****"
  53. # use forkoff to update chainspec with the live state + update runtime code
  54. fork_off_init
  55. export JOYSTREAM_NODE_TAG=$RUNTIME_TAG
  56. # export chain-spec BEFORE starting the node
  57. export_chainspec_file_to_disk
  58. echo "***** STARTING NODE WITH FORKED STATE *****"
  59. CONTAINER_ID=$(start_node)
  60. if ( $POST_MIGRATION_ASYNC_ASSERTIONS ); then
  61. sleep 120
  62. # verify assertion using typsecript
  63. echo "***** POST MIGRATION TYPESCRIPT *****"
  64. yarn workspace network-tests node-ts-strict src/scenarios/post-migration.ts
  65. fi
  66. }
  67. # main entrypoint
  68. main || :
  69. cleanup