run-migration-tests.sh 2.9 KB

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