run-tests.sh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. if [ "$TARGET_RUNTIME" == "$RUNTIME" ]; then
  63. echo "Not Performing a runtime upgrade."
  64. else
  65. # Copy new runtime wasm file from target joystream/node image
  66. echo "Extracting wasm blob from target joystream/node image."
  67. id=`docker create joystream/node:${TARGET_RUNTIME}`
  68. docker cp $id:/joystream/runtime.compact.wasm ${DATA_PATH}
  69. docker rm $id
  70. # Display runtime version before runtime upgrade
  71. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
  72. echo "Performing runtime upgrade."
  73. yarn workspace api-scripts tsnode-strict \
  74. src/dev-set-runtime-code.ts -- ${DATA_PATH}/runtime.compact.wasm
  75. echo "Runtime upgraded."
  76. fi
  77. # Display runtime version
  78. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
  79. ./run-test-scenario.sh $1