test-release.sh 8.8 KB

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