test-release.sh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #!/bin/bash
  2. # Tested on Linux, MinGW-64
  3. # MinGW's bash 3.1.17 doesn't do ${var^^}
  4. dfl_tests='obj btc btc_tn btc_rt bch bch_rt ltc ltc_tn ltc_rt tool gen'
  5. PROGNAME=$(basename $0)
  6. while getopts hinPt OPT
  7. do
  8. case "$OPT" in
  9. h) printf " %-16s Test MMGen release\n" "${PROGNAME}:"
  10. echo " USAGE: $PROGNAME [options] branch [tests]"
  11. echo " OPTIONS: '-h' Print this help message"
  12. echo " '-i' Install only; don't run tests"
  13. echo " '-n' Don't install; test in place"
  14. echo " '-P' Don't pause between tests"
  15. echo " '-t' Print the tests without running them"
  16. echo " AVAILABLE TESTS:"
  17. echo " obj - data objects"
  18. echo " btc - bitcoin"
  19. echo " btc_tn - bitcoin testnet"
  20. echo " btc_rt - bitcoin regtest"
  21. echo " bch - bitcoin cash (BCH)"
  22. echo " bch_rt - bitcoin cash (BCH) regtest"
  23. echo " ltc - litecoin"
  24. echo " ltc_tn - litecoin testnet"
  25. echo " ltc_rt - litecoin regtest"
  26. echo " tool - tooltest (all supported coins)"
  27. echo " gen - gentest (all supported coins)"
  28. echo " By default, all tests are run"
  29. exit ;;
  30. i) INSTALL_ONLY=1 ;;
  31. n) NO_INSTALL=1 ;;
  32. P) NO_PAUSE=1 ;;
  33. t) TESTING=1 ;;
  34. *) exit ;;
  35. esac
  36. done
  37. shift $((OPTIND-1))
  38. RED="\e[31;1m" GREEN="\e[32;1m" YELLOW="\e[33;1m" RESET="\e[0m"
  39. BRANCH=$1; shift
  40. BRANCHES=$(git branch)
  41. FOUND_BRANCH=$(for b in ${BRANCHES/\*}; do [ "$b" == "$BRANCH" ] && echo ok; done)
  42. [ "$FOUND_BRANCH" ] || { echo "Branch '$BRANCH' not found!"; exit; }
  43. set -e
  44. REFDIR=test/ref
  45. if uname -a | grep -qi mingw; then SUDO='' MINGW=1; else SUDO='sudo' MINGW=''; fi
  46. function check {
  47. [ "$BRANCH" ] || { echo 'No branch specified. Exiting'; exit; }
  48. [ "$(git diff $BRANCH)" == "" ] || {
  49. echo "Unmerged changes from branch '$BRANCH'. Exiting"
  50. exit
  51. }
  52. git diff $BRANCH >/dev/null 2>&1 || exit
  53. }
  54. function install {
  55. set -x
  56. eval "$SUDO rm -rf .test-release"
  57. git clone --branch $BRANCH --single-branch . .test-release
  58. cd .test-release
  59. ./setup.py sdist
  60. mkdir pydist && cd pydist
  61. if [ "$MINGW" ]; then unzip ../dist/mmgen-*.zip; else tar zxvf ../dist/mmgen-*gz; fi
  62. cd mmgen-*
  63. scripts/deinstall.sh
  64. [ "$MINGW" ] && ./setup.py build --compiler=mingw32
  65. eval "$SUDO ./setup.py install"
  66. }
  67. function do_test {
  68. set +x
  69. for i in "$@"; do
  70. LS='\n'
  71. [ "$TESTING" ] && LS=''
  72. echo $i | grep -q 'gentest' && LS=''
  73. echo -e "$LS${GREEN}Running:$RESET $YELLOW$i$RESET"
  74. [ "$TESTING" ] || eval "$i" || { echo -e $RED'Test failed!'$RESET; exit; }
  75. done
  76. }
  77. i_obj='Data objects'
  78. s_obj='Testing data objects'
  79. t_obj=(
  80. 'test/objtest.py --coin=btc -S'
  81. 'test/objtest.py --coin=btc --testnet=1 -S'
  82. 'test/objtest.py --coin=ltc -S'
  83. 'test/objtest.py --coin=ltc --testnet=1 -S')
  84. f_obj='Data object test complete'
  85. i_btc='Bitcoin mainnet'
  86. s_btc='The bitcoin (mainnet) daemon must both be running for the following tests'
  87. t_btc=(
  88. 'test/test.py -On'
  89. 'test/test.py -On --segwit dfl_wallet main ref ref_other'
  90. 'test/test.py -On --segwit-random dfl_wallet main'
  91. 'test/tooltest.py rpc'
  92. "scripts/compute-file-chksum.py $REFDIR/*testnet.rawtx >/dev/null 2>&1")
  93. f_btc='You may stop the bitcoin (mainnet) daemon if you wish'
  94. i_btc_tn='Bitcoin testnet'
  95. s_btc_tn='The bitcoin testnet daemon must both be running for the following tests'
  96. t_btc_tn=(
  97. 'test/test.py -On --testnet=1'
  98. 'test/test.py -On --testnet=1 --segwit dfl_wallet main ref ref_other'
  99. 'test/test.py -On --testnet=1 --segwit-random dfl_wallet main'
  100. 'test/tooltest.py --testnet=1 rpc')
  101. f_btc_tn='You may stop the bitcoin testnet daemon if you wish'
  102. i_btc_rt='Bitcoin regtest'
  103. s_btc_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
  104. t_btc_rt=('test/test.py -On regtest')
  105. f_btc_rt="Regtest (Bob and Alice) mode tests for BTC completed"
  106. i_bch='Bitcoin cash (BCH)'
  107. s_bch='The bitcoin cash daemon (Bitcoin ABC) must both be running for the following tests'
  108. t_bch=('test/test.py -On --coin=bch dfl_wallet main ref ref_other')
  109. f_bch='You may stop the Bitcoin ABC daemon if you wish'
  110. i_bch_rt='Bitcoin cash (BCH) regtest'
  111. s_bch_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
  112. t_bch_rt=('test/test.py --coin=bch -On regtest')
  113. f_bch_rt="Regtest (Bob and Alice) mode tests for BCH completed"
  114. i_ltc='Litecoin'
  115. s_ltc='The litecoin daemon must both be running for the following tests'
  116. t_ltc=(
  117. 'test/test.py --coin=ltc -On dfl_wallet main'
  118. 'test/test.py --coin=ltc --segwit -On dfl_wallet main'
  119. 'test/test.py --coin=ltc --segwit-random -On dfl_wallet main'
  120. 'test/tooltest.py --coin=ltc rpc'
  121. )
  122. f_ltc='You may stop the litecoin daemon if you wish'
  123. i_ltc_tn='Litecoin testnet'
  124. s_ltc_tn='The litecoin testnet daemon must both be running for the following tests'
  125. t_ltc_tn=(
  126. 'test/test.py --coin=ltc -On --testnet=1'
  127. 'test/test.py --coin=ltc -On --testnet=1 --segwit dfl_wallet main ref ref_other'
  128. 'test/test.py --coin=ltc -On --testnet=1 --segwit-random dfl_wallet main'
  129. 'test/tooltest.py --coin=ltc --testnet=1 rpc')
  130. f_ltc_tn='You may stop the litecoin testnet daemon if you wish'
  131. i_ltc_rt='Litecoin regtest'
  132. s_ltc_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
  133. t_ltc_rt=('test/test.py --coin=ltc -On regtest')
  134. f_ltc_rt="Regtest (Bob and Alice) mode tests for LTC completed"
  135. i_tool='Tooltest'
  136. s_tool='The following tests will run test/tooltest.py for all supported coins'
  137. t_tool=(
  138. 'test/tooltest.py --coin=btc util'
  139. 'test/tooltest.py --coin=btc cryptocoin'
  140. 'test/tooltest.py --coin=btc mnemonic'
  141. 'test/tooltest.py --coin=ltc util'
  142. 'test/tooltest.py --coin=ltc cryptocoin'
  143. 'test/tooltest.py --coin=ltc mnemonic'
  144. )
  145. f_tool="tooltest tests completed"
  146. i_gen='Gentest'
  147. s_gen='The following tests will run test/gentest.py on mainnet and testnet for all supported coins'
  148. t_gen=(
  149. "test/gentest.py -q 2 $REFDIR/btcwallet.dump"
  150. 'test/gentest.py -q 1:2 10'
  151. 'test/gentest.py -q --segwit 1:2 10'
  152. "test/gentest.py -q --testnet=1 2 $REFDIR/btcwallet-testnet.dump"
  153. 'test/gentest.py -q --testnet=1 1:2 10'
  154. 'test/gentest.py -q --testnet=1 --segwit 1:2 10'
  155. "test/gentest.py -q --coin=ltc 2 $REFDIR/litecoin/ltcwallet.dump"
  156. 'test/gentest.py -q --coin=ltc 1:2 10'
  157. 'test/gentest.py -q --coin=ltc --segwit 1:2 10'
  158. "test/gentest.py -q --coin=ltc --testnet=1 2 $REFDIR/litecoin/ltcwallet-testnet.dump"
  159. 'test/gentest.py -q --coin=ltc --testnet=1 1:2 10'
  160. 'test/gentest.py -q --coin=ltc --testnet=1 --segwit 1:2 10'
  161. )
  162. f_gen="gentest tests completed"
  163. [ -d .git -a -z "$NO_INSTALL" -a -z "$TESTING" ] && {
  164. check
  165. (install)
  166. eval "cd .test-release/pydist/mmgen-*"
  167. }
  168. [ "$INSTALL_ONLY" ] && exit
  169. function skip_maybe {
  170. echo -n "Enter 's' to skip, or ENTER to continue: "; read
  171. [ "$REPLY" == 's' ] && return 0
  172. return 1
  173. }
  174. function run_tests {
  175. for t in $1; do
  176. eval echo -e \${GREEN}'###' Running $(echo \$i_$t) tests\$RESET
  177. [ "$PAUSE" ] && { eval echo $(echo \$s_$t); skip_maybe && continue; }
  178. # echo RUNNING
  179. eval "do_test \"\${t_$t[@]}\""
  180. eval echo -e \$GREEN$(echo \$f_$t)\$RESET
  181. done
  182. }
  183. tests=$dfl_tests
  184. [ "$*" ] && tests="$*"
  185. [ "$NO_PAUSE" ] || PAUSE=1
  186. run_tests "$tests"
  187. echo -e "${GREEN}All OK$RESET"