test-release.sh 8.0 KB

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