test-release.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. #!/bin/bash
  2. # Tested on Linux, MinGW-64
  3. # MinGW's bash 3.1.17 doesn't do ${var^^}
  4. umask 0022
  5. export MMGEN_TEST_SUITE=1
  6. export MMGEN_NO_LICENSE=1
  7. export PYTHONPATH=.
  8. test_py='test/test.py -n'
  9. objtest_py='test/objtest.py'
  10. tooltest_py='test/tooltest.py'
  11. gentest_py='test/gentest.py'
  12. scrambletest_py='test/scrambletest.py'
  13. mmgen_tool='cmds/mmgen-tool'
  14. mmgen_keygen='cmds/mmgen-keygen'
  15. python='python3'
  16. rounds=100 rounds_low=20 rounds_spec=500 gen_rounds=10
  17. monero_addrs='3,99,2,22-24,101-104'
  18. dfl_tests='obj sha256 alts monero eth autosign btc btc_tn btc_rt bch bch_rt ltc ltc_tn ltc_rt tool gen'
  19. add_tests='autosign_minimal'
  20. PROGNAME=$(basename $0)
  21. while getopts hbCfilnPRtvV OPT
  22. do
  23. case "$OPT" in
  24. h) printf " %-16s Test MMGen release\n" "${PROGNAME}:"
  25. echo " USAGE: $PROGNAME [options] [branch] [tests]"
  26. echo " OPTIONS: '-h' Print this help message"
  27. echo " '-b' Buffer keypresses for all invocations of 'test/test.py'"
  28. echo " '-C' Run tests in coverage mode"
  29. echo " '-f' Speed up the tests by using fewer rounds"
  30. echo " '-i' Install only; don't run tests"
  31. echo " '-l' List the test name symbols"
  32. echo " '-n' Don't install; test in place"
  33. echo " '-P' Don't pause between tests"
  34. echo " '-R' Don't remove temporary files after program has exited"
  35. echo " '-t' Print the tests without running them"
  36. echo " '-v' Run test/test.py with '--exact-output' and other commands with '--verbose' switch"
  37. echo " '-V' Run test/test.py and other commands with '--verbose' switch"
  38. echo " AVAILABLE TESTS:"
  39. echo " obj - data objects"
  40. echo " sha256 - MMGen sha256 implementation"
  41. echo " alts - operations for all supported gen-only altcoins"
  42. echo " monero - operations for Monero"
  43. echo " eth - operations for Ethereum"
  44. echo " autosign - autosign"
  45. echo " btc - bitcoin"
  46. echo " btc_tn - bitcoin testnet"
  47. echo " btc_rt - bitcoin regtest"
  48. echo " bch - bitcoin cash (BCH)"
  49. echo " bch_rt - bitcoin cash (BCH) regtest"
  50. echo " ltc - litecoin"
  51. echo " ltc_tn - litecoin testnet"
  52. echo " ltc_rt - litecoin regtest"
  53. echo " tool - tooltest (all supported coins)"
  54. echo " gen - gentest (all supported coins)"
  55. echo " By default, all tests are run"
  56. exit ;;
  57. b) test_py+=" --buf-keypress" ;;
  58. C) mkdir -p 'test/trace'
  59. touch 'test/trace.acc'
  60. test_py+=" --coverage"
  61. tooltest_py+=" --coverage"
  62. scrambletest_py+=" --coverage"
  63. python="python3 -m trace --count --file=test/trace.acc --coverdir=test/trace"
  64. objtest_py="$python $objtest_py"
  65. gentest_py="$python $gentest_py"
  66. mmgen_tool="$python $mmgen_tool"
  67. mmgen_keygen="$python $mmgen_keygen"
  68. rounds=2 rounds_low=2 rounds_spec=2 gen_rounds=2 monero_addrs='3,23,105' ;;
  69. f) rounds=2 rounds_low=2 rounds_spec=2 gen_rounds=2 monero_addrs='3,23,105' ;;
  70. i) INSTALL_ONLY=1 ;;
  71. l) echo -e "Default tests:\n $dfl_tests"
  72. echo -e "Additional tests:\n $add_tests"
  73. exit ;;
  74. n) NO_INSTALL=1 ;;
  75. P) NO_PAUSE=1 ;;
  76. R) NO_TMPFILE_REMOVAL=1 ;;
  77. t) TESTING=1 ;;
  78. v) EXACT_OUTPUT=1 test_py+=" --exact-output" ;&
  79. V) VERBOSE=1 [ "$EXACT_OUTPUT" ] || test_py+=" --verbose"
  80. tooltest_py+=" --verbose" gentest_py+=" --verbose" mmgen_tool+=" --verbose"
  81. scrambletest_py+=" --verbose" ;;
  82. *) exit ;;
  83. esac
  84. done
  85. [ "$EXACT_OUTPUT" -o "$VERBOSE" ] || objtest_py+=" -S"
  86. shift $((OPTIND-1))
  87. REFDIR='test/ref'
  88. if uname -a | grep -qi mingw; then SUDO='' MINGW=1; else SUDO='sudo' MINGW=''; fi
  89. [ "$MINGW" ] || RED="\e[31;1m" GREEN="\e[32;1m" YELLOW="\e[33;1m" RESET="\e[0m"
  90. [ "$NO_INSTALL" ] || {
  91. BRANCH=$1; shift
  92. BRANCHES=$(git branch)
  93. FOUND_BRANCH=$(for b in ${BRANCHES/\*}; do [ "$b" == "$BRANCH" ] && echo ok; done)
  94. [ "$FOUND_BRANCH" ] || { echo "Branch '$BRANCH' not found!"; exit; }
  95. }
  96. set -e
  97. check() {
  98. [ "$BRANCH" ] || { echo 'No branch specified. Exiting'; exit; }
  99. [ "$(git diff $BRANCH)" == "" ] || {
  100. echo "Unmerged changes from branch '$BRANCH'. Exiting"
  101. exit
  102. }
  103. git diff $BRANCH >/dev/null 2>&1 || exit
  104. }
  105. install() {
  106. set -x
  107. eval "$SUDO rm -rf .test-release"
  108. git clone --branch $BRANCH --single-branch . .test-release
  109. cd .test-release
  110. ./setup.py sdist
  111. mkdir pydist && cd pydist
  112. if [ "$MINGW" ]; then unzip ../dist/mmgen-*.zip; else tar zxvf ../dist/mmgen-*gz; fi
  113. cd mmgen-*
  114. scripts/deinstall.sh
  115. [ "$MINGW" ] && ./setup.py build --compiler=mingw32
  116. eval "$SUDO ./setup.py install"
  117. }
  118. do_test() {
  119. set +x
  120. for i in "$@"; do
  121. LS='\n'
  122. [ "$TESTING" ] && LS=''
  123. echo $i | grep -q 'gentest' && LS=''
  124. echo -e "$LS${GREEN}Running:$RESET $YELLOW$i$RESET"
  125. [ "$TESTING" ] || eval "$i" || { echo -e $RED"Test $CUR_TEST failed at command '$i'"$RESET; exit; }
  126. done
  127. }
  128. i_obj='Data object'
  129. s_obj='Testing data objects'
  130. t_obj=(
  131. "$objtest_py --coin=btc"
  132. "$objtest_py --coin=btc --testnet=1"
  133. "$objtest_py --coin=ltc"
  134. "$objtest_py --coin=ltc --testnet=1")
  135. f_obj='Data object test complete'
  136. i_sha256='MMGen sha256 implementation'
  137. s_sha256='Testing sha256 implementation'
  138. t_sha256=("$python test/sha256test.py $rounds_spec")
  139. f_sha256='Sha256 test complete'
  140. i_alts='Gen-only altcoin'
  141. s_alts='The following tests will test generation operations for all supported altcoins'
  142. t_alts=(
  143. "$scrambletest_py"
  144. "$test_py ref_alt"
  145. "$gentest_py --coin=btc 2 $rounds"
  146. "$gentest_py --coin=btc --type=compressed 2 $rounds"
  147. "$gentest_py --coin=btc --type=segwit 2 $rounds"
  148. "$gentest_py --coin=btc --type=bech32 2 $rounds"
  149. "$gentest_py --coin=ltc 2 $rounds"
  150. "$gentest_py --coin=ltc --type=compressed 2 $rounds"
  151. "$gentest_py --coin=ltc --type=segwit 2 $rounds"
  152. "$gentest_py --coin=ltc --type=bech32 2 $rounds"
  153. "$gentest_py --coin=etc 2 $rounds"
  154. "$gentest_py --coin=eth 2 $rounds"
  155. "$gentest_py --coin=zec 2 $rounds"
  156. "$gentest_py --coin=zec --type=zcash_z 2 $rounds_spec"
  157. "$gentest_py --coin=btc 2:ext $rounds"
  158. "$gentest_py --coin=btc --type=compressed 2:ext $rounds"
  159. "$gentest_py --coin=btc --type=segwit 2:ext $rounds"
  160. "$gentest_py --coin=ltc 2:ext $rounds"
  161. "$gentest_py --coin=ltc --type=compressed 2:ext $rounds"
  162. # "$gentest_py --coin=ltc --type=segwit 2:ext $rounds" # pycoin generates old-style LTC Segwit addrs
  163. "$gentest_py --coin=etc 2:ext $rounds"
  164. "$gentest_py --coin=eth 2:ext $rounds"
  165. "$gentest_py --coin=zec 2:ext $rounds"
  166. "$gentest_py --coin=zec --type=zcash_z 2:ext $rounds_spec"
  167. "$gentest_py --all 2:pycoin $rounds_low"
  168. "$gentest_py --all 2:pyethereum $rounds_low"
  169. "$gentest_py --all 2:keyconv $rounds_low"
  170. "$gentest_py --all 2:zcash_mini $rounds_low")
  171. if [ "$MINGW" ]; then
  172. t_alts[13]="# MSWin platform: skipping zcash z-addr generation and altcoin verification with third-party tools"
  173. i=14 end=${#t_alts[*]}
  174. while [ $i -lt $end ]; do unset t_alts[$i]; let i++; done
  175. fi
  176. f_alts='Gen-only altcoin tests completed'
  177. if [ "$MINGW" ]; then
  178. TMPDIR='/tmp/mmgen-test-release'
  179. else
  180. TMPDIR='/tmp/mmgen-test-release-'$(cat /dev/urandom | base32 - | head -n1 | cut -b 1-16)
  181. fi
  182. mkdir -p $TMPDIR
  183. i_monero='Monero'
  184. s_monero='Testing key-address file generation and wallet creation and sync operations for Monero'
  185. s_monero='The monerod (mainnet) daemon must be running for the following tests'
  186. t_monero=(
  187. "mmgen-walletgen -q -r0 -p1 -Llabel --outdir $TMPDIR -o words"
  188. "$mmgen_keygen -q --accept-defaults --outdir $TMPDIR --coin=xmr $TMPDIR/*.mmwords $monero_addrs"
  189. 'cs1=$(mmgen-tool -q --accept-defaults --coin=xmr keyaddrfile_chksum $TMPDIR/*-XMR*.akeys)'
  190. "$mmgen_keygen -q --use-old-ed25519 --accept-defaults --outdir $TMPDIR --coin=xmr $TMPDIR/*.mmwords $monero_addrs"
  191. 'cs2=$(mmgen-tool -q --accept-defaults --coin=xmr keyaddrfile_chksum $TMPDIR/*-XMR*.akeys)'
  192. '[ "$cs1" == "$cs2" ] || false'
  193. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR keyaddrlist2monerowallets $TMPDIR/*-XMR*.akeys addrs=23"
  194. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR keyaddrlist2monerowallets $TMPDIR/*-XMR*.akeys addrs=103-200"
  195. 'rm $TMPDIR/*-MoneroWallet*'
  196. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR keyaddrlist2monerowallets $TMPDIR/*-XMR*.akeys"
  197. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR syncmonerowallets $TMPDIR/*-XMR*.akeys addrs=3"
  198. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR syncmonerowallets $TMPDIR/*-XMR*.akeys addrs=23-29"
  199. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR syncmonerowallets $TMPDIR/*-XMR*.akeys"
  200. )
  201. [ "$MINGW" ] && {
  202. t_monero[2]="# MSWin platform: skipping Monero wallet creation and sync tests; NOT verifying key-addr list"
  203. i=3 end=${#t_monero[*]}
  204. while [ $i -lt $end ]; do unset t_monero[$i]; let i++; done
  205. }
  206. f_monero='Monero tests completed'
  207. i_eth='Ethereum'
  208. s_eth='Testing transaction and tracking wallet operations for Ethereum and Ethereum Classic'
  209. t_eth=(
  210. "$test_py --coin=eth ref_tx_chk"
  211. "$test_py --coin=eth --testnet=1 ref_tx_chk"
  212. "$test_py --coin=etc ref_tx_chk"
  213. "$test_py --coin=eth ethdev"
  214. "$test_py --coin=etc ethdev"
  215. )
  216. f_eth='Ethereum tests completed'
  217. i_autosign='Autosign'
  218. s_autosign='The bitcoin, bitcoin-abc and litecoin mainnet and testnet daemons must be running for the following test'
  219. t_autosign=("$test_py autosign")
  220. f_autosign='Autosign test complete'
  221. i_autosign_minimal='Autosign'
  222. s_autosign_minimal='The bitcoin, bitcoin-abc and litecoin mainnet and testnet daemons must be running for the following test'
  223. t_autosign_minimal=("$test_py autosign_minimal")
  224. f_autosign_minimal='Autosign test complete'
  225. i_btc='Bitcoin mainnet'
  226. s_btc='The bitcoin (mainnet) daemon must both be running for the following tests'
  227. t_btc=(
  228. "$test_py"
  229. "$test_py --segwit dfl_wallet main ref ref_files"
  230. "$test_py --segwit-random dfl_wallet main"
  231. "$test_py --bech32 dfl_wallet main ref ref_files"
  232. "$tooltest_py rpc"
  233. "$python scripts/compute-file-chksum.py $REFDIR/*testnet.rawtx >/dev/null 2>&1")
  234. f_btc='You may stop the bitcoin (mainnet) daemon if you wish'
  235. i_btc_tn='Bitcoin testnet'
  236. s_btc_tn='The bitcoin testnet daemon must both be running for the following tests'
  237. t_btc_tn=(
  238. "$test_py --testnet=1"
  239. "$test_py --testnet=1 --segwit dfl_wallet main ref ref_files"
  240. "$test_py --testnet=1 --segwit-random dfl_wallet main"
  241. "$test_py --testnet=1 --bech32 dfl_wallet main ref ref_files"
  242. "$tooltest_py --testnet=1 rpc")
  243. f_btc_tn='You may stop the bitcoin testnet daemon if you wish'
  244. i_btc_rt='Bitcoin regtest'
  245. s_btc_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
  246. t_btc_rt=(
  247. "$test_py regtest"
  248. # "$test_py regtest_split" # no official B2X support, so skip
  249. )
  250. f_btc_rt='Regtest (Bob and Alice) mode tests for BTC completed'
  251. i_bch='Bitcoin cash (BCH)'
  252. s_bch='The bitcoin cash daemon (Bitcoin ABC) must both be running for the following tests'
  253. t_bch=("$test_py --coin=bch dfl_wallet main ref ref_files")
  254. f_bch='You may stop the Bitcoin ABC daemon if you wish'
  255. i_bch_rt='Bitcoin cash (BCH) regtest'
  256. s_bch_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
  257. t_bch_rt=("$test_py --coin=bch regtest")
  258. f_bch_rt='Regtest (Bob and Alice) mode tests for BCH completed'
  259. i_b2x='Bitcoin 2X (B2X)'
  260. s_b2x='The bitcoin 2X daemon (BTC1) must both be running for the following tests'
  261. t_b2x=("$test_py --coin=b2x dfl_wallet main ref ref_files")
  262. f_b2x='You may stop the Bitcoin 2X daemon if you wish'
  263. i_b2x_rt='Bitcoin 2X (B2X) regtest'
  264. s_b2x_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
  265. t_b2x_rt=("$test_py --coin=b2x regtest")
  266. f_b2x_rt='Regtest (Bob and Alice) mode tests for B2X completed'
  267. i_ltc='Litecoin'
  268. s_ltc='The litecoin daemon must both be running for the following tests'
  269. t_ltc=(
  270. "$test_py --coin=ltc dfl_wallet main ref ref_files"
  271. "$test_py --coin=ltc --segwit dfl_wallet main ref ref_files"
  272. "$test_py --coin=ltc --segwit-random dfl_wallet main"
  273. "$test_py --coin=ltc --bech32 dfl_wallet main ref ref_files"
  274. "$tooltest_py --coin=ltc rpc"
  275. )
  276. f_ltc='You may stop the litecoin daemon if you wish'
  277. i_ltc_tn='Litecoin testnet'
  278. s_ltc_tn='The litecoin testnet daemon must both be running for the following tests'
  279. t_ltc_tn=(
  280. "$test_py --coin=ltc --testnet=1"
  281. "$test_py --coin=ltc --testnet=1 --segwit dfl_wallet main ref ref_files"
  282. "$test_py --coin=ltc --testnet=1 --segwit-random dfl_wallet main"
  283. "$test_py --coin=ltc --testnet=1 --bech32 dfl_wallet main ref ref_files"
  284. "$tooltest_py --coin=ltc --testnet=1 rpc")
  285. f_ltc_tn='You may stop the litecoin testnet daemon if you wish'
  286. i_ltc_rt='Litecoin regtest'
  287. s_ltc_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
  288. t_ltc_rt=("$test_py --coin=ltc regtest")
  289. f_ltc_rt='Regtest (Bob and Alice) mode tests for LTC completed'
  290. i_tool='Tooltest'
  291. s_tool="The following tests will run '$tooltest_py' for all supported coins"
  292. t_tool=(
  293. "$tooltest_py --coin=btc util"
  294. "$tooltest_py --coin=btc cryptocoin"
  295. "$tooltest_py --coin=btc mnemonic"
  296. "$tooltest_py --coin=ltc cryptocoin"
  297. "$tooltest_py --coin=eth cryptocoin"
  298. "$tooltest_py --coin=etc cryptocoin"
  299. "$tooltest_py --coin=dash cryptocoin"
  300. "$tooltest_py --coin=doge cryptocoin"
  301. "$tooltest_py --coin=emc cryptocoin"
  302. "$tooltest_py --coin=zec cryptocoin")
  303. [ "$MINGW" ] || {
  304. t_tool_len=${#t_tool[*]}
  305. t_tool[$t_tool_len]="$tooltest_py --coin=zec --type=zcash_z cryptocoin"
  306. }
  307. f_tool='tooltest tests completed'
  308. i_gen='Gentest'
  309. s_gen="The following tests will run '$gentest_py' on mainnet and testnet for all supported coins"
  310. t_gen=(
  311. "$gentest_py -q 2 $REFDIR/btcwallet.dump"
  312. "$gentest_py -q --type=segwit 2 $REFDIR/btcwallet-segwit.dump"
  313. "$gentest_py -q --type=bech32 2 $REFDIR/btcwallet-bech32.dump"
  314. "$gentest_py -q 1:2 $gen_rounds"
  315. "$gentest_py -q --type=segwit 1:2 $gen_rounds"
  316. "$gentest_py -q --type=bech32 1:2 $gen_rounds"
  317. "$gentest_py -q --testnet=1 2 $REFDIR/btcwallet-testnet.dump"
  318. "$gentest_py -q --testnet=1 1:2 $gen_rounds"
  319. "$gentest_py -q --testnet=1 --type=segwit 1:2 $gen_rounds"
  320. "$gentest_py -q --coin=ltc 2 $REFDIR/litecoin/ltcwallet.dump"
  321. "$gentest_py -q --coin=ltc --type=segwit 2 $REFDIR/litecoin/ltcwallet-segwit.dump"
  322. "$gentest_py -q --coin=ltc --type=bech32 2 $REFDIR/litecoin/ltcwallet-bech32.dump"
  323. "$gentest_py -q --coin=ltc 1:2 $gen_rounds"
  324. "$gentest_py -q --coin=ltc --type=segwit 1:2 $gen_rounds"
  325. "$gentest_py -q --coin=ltc --testnet=1 2 $REFDIR/litecoin/ltcwallet-testnet.dump"
  326. "$gentest_py -q --coin=ltc --testnet=1 1:2 $gen_rounds"
  327. "$gentest_py -q --coin=ltc --testnet=1 --type=segwit 1:2 $gen_rounds")
  328. f_gen='gentest tests completed'
  329. [ -d .git -a -z "$NO_INSTALL" -a -z "$TESTING" ] && {
  330. check
  331. (install)
  332. eval "cd .test-release/pydist/mmgen-*"
  333. }
  334. [ "$INSTALL_ONLY" ] && exit
  335. skip_maybe() {
  336. echo -n "Enter 's' to skip, or ENTER to continue: "; read
  337. [ "$REPLY" == 's' ] && return 0
  338. return 1
  339. }
  340. run_tests() {
  341. for t in $1; do
  342. eval echo -e \${GREEN}'###' Running $(echo \$i_$t) tests\$RESET
  343. [ "$PAUSE" ] && { eval echo $(echo \$s_$t); skip_maybe && continue; }
  344. # echo RUNNING
  345. CUR_TEST=$t
  346. eval "do_test \"\${t_$t[@]}\""
  347. eval echo -e \$GREEN$(echo \$f_$t)\$RESET
  348. done
  349. }
  350. check_args() {
  351. for i in $tests; do
  352. echo "$dfl_tests $add_tests" | grep -q "\<$i\>" || { echo "$i: unrecognized argument"; exit; }
  353. done
  354. }
  355. tests=$dfl_tests
  356. [ "$*" ] && tests="$*"
  357. [ "$NO_PAUSE" ] || PAUSE=1
  358. check_args
  359. echo "Running tests: $tests"
  360. run_tests "$tests"
  361. [ "$NO_TMPFILE_REMOVAL" ] || rm -rf /tmp/mmgen-test-release-*
  362. echo -e "${GREEN}All OK$RESET"