test-release.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # Tested on Linux, MinGW-64
  3. PROGNAME=$(basename $0)
  4. while getopts hint OPT
  5. do
  6. case "$OPT" in
  7. h) printf " %-16s Test MMGen release\n" "${PROGNAME^^}:"
  8. echo " USAGE: $PROGNAME [options] branch [tests]"
  9. echo " OPTIONS: '-h' Print this help message"
  10. echo " '-i' Install only; don't run tests"
  11. echo " '-n' Don't install; test in place"
  12. echo " '-t' Print the tests without running them"
  13. echo " AVAILABLE TESTS:"
  14. echo " 1 - main"
  15. echo " 2 - tooltest"
  16. echo " 3 - gentest"
  17. echo " 4 - regtest"
  18. echo " By default, all tests are run"
  19. exit ;;
  20. i) INSTALL_ONLY=1 ;;
  21. n) NO_INSTALL=1 ;;
  22. t) TESTING=1 ;;
  23. *) exit ;;
  24. esac
  25. done
  26. shift $((OPTIND-1))
  27. set -e
  28. GREEN="\e[32;1m" YELLOW="\e[33;1m" RESET="\e[0m"
  29. BRANCH=$1; shift
  30. REFDIR=test/ref
  31. if uname -a | grep -qi mingw; then SUDO='' MINGW=1; else SUDO='sudo' MINGW=''; fi
  32. function check {
  33. [ "$BRANCH" ] || { echo 'No branch specified. Exiting'; exit; }
  34. [ "$(git diff $BRANCH)" == "" ] || {
  35. echo "Unmerged changes from branch '$BRANCH'. Exiting"
  36. exit
  37. }
  38. git diff $BRANCH >/dev/null 2>&1 || exit
  39. }
  40. function install {
  41. set -x
  42. eval "$SUDO rm -rf .test-release"
  43. git clone --branch $BRANCH --single-branch . .test-release
  44. cd .test-release
  45. ./setup.py sdist
  46. mkdir pydist && cd pydist
  47. if [ "$MINGW" ]; then unzip ../dist/mmgen-*.zip; else tar zxvf ../dist/mmgen-*gz; fi
  48. cd mmgen-*
  49. scripts/deinstall.sh
  50. [ "$MINGW" ] && ./setup.py build --compiler=mingw32
  51. eval "$SUDO ./setup.py install"
  52. }
  53. [ -z "$TESTING" ] && LS='\n'
  54. function do_test {
  55. set +x
  56. for i in "$@"; do
  57. echo -e "$LS${GREEN}Running:$RESET $YELLOW$i$RESET"
  58. [ "$TESTING" ] || eval "$i"
  59. done
  60. }
  61. T1=('test/test.py -On'
  62. 'test/test.py -On --segwit dfl_wallet main ref ref_other'
  63. 'test/test.py -On --coin=bch dfl_wallet main ref ref_other'
  64. 'test/test.py -On --segwit-random dfl_wallet main')
  65. T2=('test/tooltest.py' 'test/tooltest.py --testnet=1') # tooltest tests both segwit and non-segwit
  66. T3=("test/gentest.py -q 2 $REFDIR/btcwallet.dump"
  67. "test/gentest.py -q --testnet=1 2 $REFDIR/btcwallet-testnet.dump"
  68. 'test/gentest.py -q 1:2 10'
  69. 'test/gentest.py -q --segwit 1:2 10'
  70. # "scripts/tx-old2new.py -S $REFDIR/tx_*raw >/dev/null 2>&1"
  71. "scripts/compute-file-chksum.py $REFDIR/*testnet.rawtx >/dev/null 2>&1")
  72. T4=('test/test.py -On regtest')
  73. [ -d .git -a -z "$NO_INSTALL" -a -z "$TESTING" ] && {
  74. check
  75. (install)
  76. eval "cd .test-release/pydist/mmgen-*"
  77. }
  78. [ "$INSTALL_ONLY" ] && exit
  79. function run_tests {
  80. for t in $1; do
  81. [ $t == 4 ] && LS=''
  82. eval "do_test \"\${T$t[@]}\""
  83. done
  84. }
  85. if [ "$*" ]; then
  86. run_tests "$*"
  87. else
  88. echo 'Bitcoin and Bitcoin ABC must both be running for the following tests'
  89. echo 'The bitcoin-abc daemon must be listening on RPC port 8442 (-rpcport 8442)'
  90. echo -n 'Hit ENTER to continue: '; read
  91. run_tests '1'
  92. echo 'The bitcoin (mainnet) and testnet daemons must both be running for the following tests'
  93. echo -n 'Hit ENTER to continue: '; read
  94. run_tests '2 3'
  95. echo 'You may stop the mainnet and testnet daemons now'
  96. echo -n 'Hit ENTER to continue: '; read
  97. run_tests '4'
  98. fi
  99. echo -e "$LS${GREEN}All OK$RESET"