test-setup-new-chain.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. # Start a chain with generated chain spec
  50. export JOYSTREAM_NODE_TAG=${RUNTIME}
  51. CONTAINER_ID=`docker-compose -f ../../docker-compose.yml run -d -v ${DATA_PATH}:/data --name joystream-node \
  52. -p 9944:9944 -p 9933:9933 joystream-node \
  53. --alice --validator --unsafe-ws-external --unsafe-rpc-external \
  54. --rpc-methods Unsafe --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. sleep 3
  63. # Display runtime version
  64. yarn workspace api-scripts tsnode-strict src/status.ts | grep Runtime
  65. # Init chain state
  66. echo 'executing scenario'
  67. ./run-test-scenario.sh setup-new-chain