test-release.sh 16 KB

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