test-setup-new-chain.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 where the initial members and balances files and generated chainspec files will be located.
  7. DATA_PATH=${DATA_PATH:=~/tmp}
  8. mkdir -p ${DATA_PATH}
  9. # Initial account balance for sudo account
  10. # Will be the source of funds for all new accounts that are created in the tests.
  11. SUDO_INITIAL_BALANCE=${SUDO_INITIAL_BALANCE:=100000000}
  12. export SUDO_ACCOUNT_URI=${SUDO_ACCOUNT_URI:="//Alice"}
  13. SUDO_ACCOUNT=$(subkey inspect ${SUDO_ACCOUNT_URI} --output-type json | jq .ss58Address -r)
  14. export TREASURY_ACCOUNT_URI=${SUDO_ACCOUNT_URI}
  15. # The docker image tag to use for joystream/node
  16. RUNTIME=${RUNTIME:=latest}
  17. echo "{
  18. \"balances\":[
  19. [\"$SUDO_ACCOUNT\", $SUDO_INITIAL_BALANCE]
  20. ]
  21. }" > ${DATA_PATH}/initial-balances.json
  22. # Make sudo a member as well - do we really need this ?
  23. # echo "
  24. # [{
  25. # \"member_id\":0,
  26. # \"root_account\":\"$SUDO_ACCOUNT\",
  27. # \"controller_account\":\"$SUDO_ACCOUNT\",
  28. # \"handle\":\"sudosudo\",
  29. # \"avatar_uri\":\"https://sudo.com/avatar.png\",
  30. # \"about\":\"Sudo\",
  31. # \"registered_at_time\":0
  32. # }]
  33. # " > ${DATA_PATH}/initial-members.json
  34. echo "creating chainspec file"
  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 ${SUDO_ACCOUNT} \
  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. echo "converting chainspec to raw format"
  45. # Convert the chain spec file to a raw chainspec file
  46. docker run --rm -v ${DATA_PATH}:/data joystream/node:${RUNTIME} build-spec \
  47. --raw --disable-default-bootnode \
  48. --chain /data/chain-spec.json > ~/tmp/chain-spec-raw.json
  49. NETWORK_ARG=
  50. if [ "$ATTACH_TO_NETWORK" != "" ]; then
  51. NETWORK_ARG="--network ${ATTACH_TO_NETWORK}"
  52. fi
  53. echo "starting joystream-node container"
  54. # Start a chain with generated chain spec
  55. # Add "-l ws=trace,ws::handler=info" to get websocket trace logs
  56. CONTAINER_ID=`docker run -d -v ${DATA_PATH}:/data -p 9944:9944 ${NETWORK_ARG} --name joystream-node joystream/node:${RUNTIME} \
  57. --validator --alice --unsafe-ws-external --rpc-cors=all -l runtime \
  58. --chain /data/chain-spec-raw.json`
  59. function cleanup() {
  60. docker logs ${CONTAINER_ID} --tail 15
  61. docker stop ${CONTAINER_ID}
  62. docker rm ${CONTAINER_ID}
  63. }
  64. trap cleanup EXIT
  65. sleep 3
  66. # Display runtime version
  67. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
  68. # Init chain state
  69. echo 'executing scenario'
  70. ./run-test-scenario.sh setup-new-chain