test-release.sh 13 KB

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