test-release.sh 10 KB

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