start-test-chain.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. mkdir -p ${DATA_PATH}
  17. echo "{
  18. \"balances\":[
  19. [\"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY\", ${ALICE_INITIAL_BALANCE}]
  20. ]
  21. }" > ${DATA_PATH}/initial-balances.json
  22. # Make Alice a member
  23. echo '
  24. [{
  25. "member_id":0,
  26. "root_account":"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
  27. "controller_account":"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
  28. "handle":"alice",
  29. "avatar_uri":"https://alice.com/avatar.png",
  30. "about":"Alice",
  31. "registered_at_time":0
  32. }]
  33. ' > ${DATA_PATH}/initial-members.json
  34. # Create a chain spec file
  35. docker run --rm -v ${DATA_PATH}:/data --entrypoint ./chain-spec-builder joystream/node:${RUNTIME} \
  36. new \
  37. --authority-seeds Alice \
  38. --sudo-account 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY \
  39. --deployment dev \
  40. --chain-spec-path /data/chain-spec.json \
  41. --initial-balances-path /data/initial-balances.json \
  42. --initial-members-path /data/initial-members.json
  43. # Convert the chain spec file to a raw chainspec file
  44. docker run --rm -v ${DATA_PATH}:/data joystream/node:${RUNTIME} build-spec \
  45. --raw --disable-default-bootnode \
  46. --chain /data/chain-spec.json > ~/tmp/chain-spec-raw.json
  47. NETWORK_ARG=
  48. if [ "$ATTACH_TO_NETWORK" != "" ]; then
  49. NETWORK_ARG="--network ${ATTACH_TO_NETWORK}"
  50. fi
  51. # Start a chain with generated chain spec
  52. # Add "-l ws=trace,ws::handler=info" to get websocket trace logs
  53. CONTAINER_ID=`docker run -d -v ${DATA_PATH}:/data -p 9944:9944 ${NETWORK_ARG} --name joystream-node joystream/node:${RUNTIME} \
  54. --validator --alice --unsafe-ws-external --rpc-cors=all -l runtime \
  55. --chain /data/chain-spec-raw.json`
  56. function cleanup() {
  57. docker logs ${CONTAINER_ID} --tail 15
  58. docker stop ${CONTAINER_ID}
  59. docker rm ${CONTAINER_ID}
  60. }
  61. trap cleanup EXIT
  62. # Initialize content-directory
  63. # sleep 15
  64. # yarn workspace @joystream/cd-schemas initialize:dev
  65. # NOTE: Skipping this step and let the scenarios do this setup instead
  66. # or align the scenario expectations of the initial state to match
  67. # with what we do here.
  68. if [ "$TARGET_RUNTIME" == "$RUNTIME" ]; then
  69. echo "Not Performing a runtime upgrade."
  70. else
  71. # Copy new runtime wasm file from target joystream/node image
  72. echo "Extracting wasm blob from target joystream/node image."
  73. id=`docker create joystream/node:${TARGET_RUNTIME}`
  74. docker cp $id:/joystream/runtime.compact.wasm ${DATA_PATH}
  75. docker rm $id
  76. # Display runtime version before runtime upgrade
  77. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
  78. echo "Performing runtime upgrade."
  79. DEBUG=* yarn workspace api-scripts tsnode-strict \
  80. src/dev-set-runtime-code.ts -- ${DATA_PATH}/runtime.compact.wasm
  81. echo "Runtime upgraded."
  82. fi
  83. # Display runtime version
  84. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime