test-release.sh 15 KB

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