test-release.sh 11 KB

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