test-release.sh 7.3 KB

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