test-release.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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_mid=250 rounds_max=500
  19. monero_addrs='3,99,2,22-24,101-104'
  20. dfl_tests='obj sha2 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 " sha2 - MMGen sha2 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=10 rounds_mid=25 rounds_max=50 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_sha2='MMGen SHA2 implementation'
  154. s_sha2='Testing SHA2 implementation'
  155. t_sha2=(
  156. "$python test/sha2test.py sha256 $rounds_max"
  157. "$python test/sha2test.py sha512 $rounds_max")
  158. f_sha2='SHA2 test complete'
  159. i_alts='Gen-only altcoin'
  160. s_alts='The following tests will test generation operations for all supported altcoins'
  161. t_alts=(
  162. "$scrambletest_py"
  163. "$test_py ref_altcoin"
  164. "$gentest_py --coin=btc 2 $rounds"
  165. "$gentest_py --coin=btc --type=compressed 2 $rounds"
  166. "$gentest_py --coin=btc --type=segwit 2 $rounds"
  167. "$gentest_py --coin=btc --type=bech32 2 $rounds"
  168. "$gentest_py --coin=ltc 2 $rounds"
  169. "$gentest_py --coin=ltc --type=compressed 2 $rounds"
  170. "$gentest_py --coin=ltc --type=segwit 2 $rounds"
  171. "$gentest_py --coin=ltc --type=bech32 2 $rounds"
  172. "$gentest_py --coin=etc 2 $rounds"
  173. "$gentest_py --coin=eth 2 $rounds"
  174. "$gentest_py --coin=zec 2 $rounds"
  175. "$gentest_py --coin=zec --type=zcash_z 2 $rounds_mid"
  176. "$gentest_py --coin=btc 2:ext $rounds"
  177. "$gentest_py --coin=btc --type=compressed 2:ext $rounds"
  178. "$gentest_py --coin=btc --type=segwit 2:ext $rounds"
  179. "$gentest_py --coin=ltc 2:ext $rounds"
  180. "$gentest_py --coin=ltc --type=compressed 2:ext $rounds"
  181. # "$gentest_py --coin=ltc --type=segwit 2:ext $rounds" # pycoin generates old-style LTC Segwit addrs
  182. "$gentest_py --coin=etc 2:ext $rounds"
  183. "$gentest_py --coin=eth 2:ext $rounds"
  184. "$gentest_py --coin=zec 2:ext $rounds"
  185. "$gentest_py --coin=zec --type=zcash_z 2:ext $rounds_mid"
  186. "$gentest_py --all 2:pycoin $rounds"
  187. "$gentest_py --all 2:pyethereum $rounds"
  188. "$gentest_py --all 2:keyconv $rounds_mid"
  189. "$gentest_py --all 2:zcash_mini $rounds_mid")
  190. if [ "$MINGW" ]; then
  191. t_alts[13]="# MSWin platform: skipping zcash z-addr generation and altcoin verification with third-party tools"
  192. i=14 end=${#t_alts[*]}
  193. while [ $i -lt $end ]; do unset t_alts[$i]; let i++; done
  194. fi
  195. f_alts='Gen-only altcoin tests completed'
  196. if [ "$MINGW" ]; then
  197. TMPDIR='/tmp/mmgen-test-release'
  198. else
  199. TMPDIR='/tmp/mmgen-test-release-'$(cat /dev/urandom | base32 - | head -n1 | cut -b 1-16)
  200. fi
  201. mkdir -p $TMPDIR
  202. i_monero='Monero'
  203. s_monero='Testing key-address file generation and wallet creation and sync operations for Monero'
  204. s_monero='The monerod (mainnet) daemon must be running for the following tests'
  205. t_monero=(
  206. "mmgen-walletgen -q -r0 -p1 -Llabel --outdir $TMPDIR -o words"
  207. "$mmgen_keygen -q --accept-defaults --outdir $TMPDIR --coin=xmr $TMPDIR/*.mmwords $monero_addrs"
  208. 'cs1=$(mmgen-tool -q --accept-defaults --coin=xmr keyaddrfile_chksum $TMPDIR/*-XMR*.akeys)'
  209. "$mmgen_keygen -q --use-old-ed25519 --accept-defaults --outdir $TMPDIR --coin=xmr $TMPDIR/*.mmwords $monero_addrs"
  210. 'cs2=$(mmgen-tool -q --accept-defaults --coin=xmr keyaddrfile_chksum $TMPDIR/*-XMR*.akeys)'
  211. '[ "$cs1" == "$cs2" ] || false'
  212. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR keyaddrlist2monerowallets $TMPDIR/*-XMR*.akeys addrs=23"
  213. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR keyaddrlist2monerowallets $TMPDIR/*-XMR*.akeys addrs=103-200"
  214. 'rm $TMPDIR/*-MoneroWallet*'
  215. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR keyaddrlist2monerowallets $TMPDIR/*-XMR*.akeys"
  216. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR syncmonerowallets $TMPDIR/*-XMR*.akeys addrs=3"
  217. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR syncmonerowallets $TMPDIR/*-XMR*.akeys addrs=23-29"
  218. "$mmgen_tool -q --accept-defaults --outdir $TMPDIR syncmonerowallets $TMPDIR/*-XMR*.akeys"
  219. )
  220. [ "$MINGW" ] && {
  221. t_monero[2]="# MSWin platform: skipping Monero wallet creation and sync tests; NOT verifying key-addr list"
  222. i=3 end=${#t_monero[*]}
  223. while [ $i -lt $end ]; do unset t_monero[$i]; let i++; done
  224. }
  225. [ "$monero_addrs" == '3,23' ] && {
  226. unset t_monero[12]
  227. unset t_monero[7]
  228. unset t_monero[3]
  229. }
  230. f_monero='Monero tests completed'
  231. i_eth='Ethereum'
  232. s_eth='Testing transaction and tracking wallet operations for Ethereum and Ethereum Classic'
  233. t_eth=(
  234. "$test_py --coin=eth ethdev"
  235. "$test_py --coin=etc ethdev"
  236. )
  237. f_eth='Ethereum tests completed'
  238. i_autosign='Autosign'
  239. s_autosign='The bitcoin, bitcoin-abc and litecoin mainnet and testnet daemons must be running for the following test'
  240. t_autosign=("$test_py autosign")
  241. f_autosign='Autosign test complete'
  242. i_autosign_minimal='Autosign Minimal'
  243. s_autosign_minimal='The bitcoin mainnet and testnet daemons must be running for the following test'
  244. t_autosign_minimal=("$test_py autosign_minimal")
  245. f_autosign_minimal='Autosign Minimal test complete'
  246. i_autosign_live='Autosign Live'
  247. s_autosign_live="The bitcoin mainnet and testnet daemons must be running for the following test\n"
  248. s_autosign_live+="${YELLOW}Mountpoint, '/etc/fstab' and removable device must be configured "
  249. s_autosign_live+="as described in 'mmgen-autosign --help'${RESET}"
  250. t_autosign_live=("$test_py autosign_live")
  251. f_autosign_live='Autosign Live test complete'
  252. i_btc='Bitcoin mainnet'
  253. s_btc='The bitcoin (mainnet) daemon must both be running for the following tests'
  254. t_btc=(
  255. "$test_py --exclude regtest"
  256. "$test_py --segwit"
  257. "$test_py --segwit-random"
  258. "$test_py --bech32"
  259. "$python scripts/compute-file-chksum.py $REFDIR/*testnet.rawtx >/dev/null 2>&1")
  260. f_btc='You may stop the bitcoin (mainnet) daemon if you wish'
  261. i_btc_tn='Bitcoin testnet'
  262. s_btc_tn='The bitcoin testnet daemon must both be running for the following tests'
  263. t_btc_tn=(
  264. "$test_py --testnet=1"
  265. "$test_py --testnet=1 --segwit"
  266. "$test_py --testnet=1 --segwit-random"
  267. "$test_py --testnet=1 --bech32")
  268. f_btc_tn='You may stop the bitcoin testnet daemon if you wish'
  269. i_btc_rt='Bitcoin regtest'
  270. s_btc_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
  271. t_btc_rt=(
  272. "$test_py regtest"
  273. )
  274. f_btc_rt='Regtest (Bob and Alice) mode tests for BTC completed'
  275. i_bch='Bitcoin cash (BCH)'
  276. s_bch='The bitcoin cash daemon (Bitcoin ABC) must both be running for the following tests'
  277. t_bch=("$test_py --coin=bch --exclude regtest")
  278. f_bch='You may stop the Bitcoin ABC daemon if you wish'
  279. i_bch_rt='Bitcoin cash (BCH) regtest'
  280. s_bch_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
  281. t_bch_rt=("$test_py --coin=bch regtest")
  282. f_bch_rt='Regtest (Bob and Alice) mode tests for BCH completed'
  283. i_ltc='Litecoin'
  284. s_ltc='The litecoin daemon must both be running for the following tests'
  285. t_ltc=(
  286. "$test_py --coin=ltc --exclude regtest"
  287. "$test_py --coin=ltc --segwit"
  288. "$test_py --coin=ltc --segwit-random"
  289. "$test_py --coin=ltc --bech32")
  290. f_ltc='You may stop the litecoin daemon if you wish'
  291. i_ltc_tn='Litecoin testnet'
  292. s_ltc_tn='The litecoin testnet daemon must both be running for the following tests'
  293. t_ltc_tn=(
  294. "$test_py --coin=ltc --testnet=1 --exclude regtest"
  295. "$test_py --coin=ltc --testnet=1 --segwit"
  296. "$test_py --coin=ltc --testnet=1 --segwit-random"
  297. "$test_py --coin=ltc --testnet=1 --bech32")
  298. f_ltc_tn='You may stop the litecoin testnet daemon if you wish'
  299. i_ltc_rt='Litecoin regtest'
  300. s_ltc_rt="The following tests will test MMGen's regtest (Bob and Alice) mode"
  301. t_ltc_rt=("$test_py --coin=ltc regtest")
  302. f_ltc_rt='Regtest (Bob and Alice) mode tests for LTC completed'
  303. i_tool2='Tooltest2'
  304. s_tool2="The following tests will run '$tooltest2_py' for all supported coins"
  305. t_tool2=(
  306. "$tooltest2_py --quiet"
  307. "$tooltest2_py --quiet --coin=btc"
  308. "$tooltest2_py --quiet --coin=btc --testnet=1"
  309. "$tooltest2_py --quiet --coin=ltc"
  310. "$tooltest2_py --quiet --coin=ltc --testnet=1"
  311. "$tooltest2_py --quiet --coin=bch"
  312. "$tooltest2_py --quiet --coin=bch --testnet=1"
  313. "$tooltest2_py --quiet --coin=zec"
  314. "$tooltest2_py --quiet --coin=zec --type=zcash_z"
  315. "$tooltest2_py --quiet --coin=xmr"
  316. "$tooltest2_py --quiet --coin=dash"
  317. "$tooltest2_py --quiet --coin=eth"
  318. "$tooltest2_py --quiet --coin=eth --testnet=1"
  319. "$tooltest2_py --quiet --coin=eth --token=mm1"
  320. "$tooltest2_py --quiet --coin=eth --token=mm1 --testnet=1"
  321. "$tooltest2_py --quiet --coin=etc")
  322. f_tool2='tooltest2 tests completed'
  323. i_tool='Tooltest'
  324. s_tool="The following tests will run '$tooltest_py' for all supported coins"
  325. t_tool=(
  326. "$tooltest_py --coin=btc cryptocoin"
  327. "$tooltest_py --coin=btc mnemonic"
  328. "$tooltest_py --coin=ltc cryptocoin"
  329. "$tooltest_py --coin=eth cryptocoin"
  330. "$tooltest_py --coin=etc cryptocoin"
  331. "$tooltest_py --coin=dash cryptocoin"
  332. "$tooltest_py --coin=doge cryptocoin"
  333. "$tooltest_py --coin=emc cryptocoin"
  334. "$tooltest_py --coin=zec cryptocoin")
  335. [ "$MINGW" ] || {
  336. t_tool_len=${#t_tool[*]}
  337. t_tool[$t_tool_len]="$tooltest_py --coin=zec --type=zcash_z cryptocoin"
  338. }
  339. f_tool='tooltest tests completed'
  340. i_gen='Gentest'
  341. s_gen="The following tests will run '$gentest_py' on mainnet and testnet for all supported coins"
  342. t_gen=(
  343. "$gentest_py -q 2 $REFDIR/btcwallet.dump"
  344. "$gentest_py -q --type=segwit 2 $REFDIR/btcwallet-segwit.dump"
  345. "$gentest_py -q --type=bech32 2 $REFDIR/btcwallet-bech32.dump"
  346. "$gentest_py -q 1:2 $rounds"
  347. "$gentest_py -q --type=segwit 1:2 $rounds"
  348. "$gentest_py -q --type=bech32 1:2 $rounds"
  349. "$gentest_py -q --testnet=1 2 $REFDIR/btcwallet-testnet.dump"
  350. "$gentest_py -q --testnet=1 1:2 $rounds"
  351. "$gentest_py -q --testnet=1 --type=segwit 1:2 $rounds"
  352. "$gentest_py -q --coin=ltc 2 $REFDIR/litecoin/ltcwallet.dump"
  353. "$gentest_py -q --coin=ltc --type=segwit 2 $REFDIR/litecoin/ltcwallet-segwit.dump"
  354. "$gentest_py -q --coin=ltc --type=bech32 2 $REFDIR/litecoin/ltcwallet-bech32.dump"
  355. "$gentest_py -q --coin=ltc 1:2 $rounds"
  356. "$gentest_py -q --coin=ltc --type=segwit 1:2 $rounds"
  357. "$gentest_py -q --coin=ltc --testnet=1 2 $REFDIR/litecoin/ltcwallet-testnet.dump"
  358. "$gentest_py -q --coin=ltc --testnet=1 1:2 $rounds"
  359. "$gentest_py -q --coin=ltc --testnet=1 --type=segwit 1:2 $rounds")
  360. f_gen='gentest tests completed'
  361. [ -d .git -a -n "$INSTALL" -a -z "$TESTING" ] && {
  362. check
  363. uninstall
  364. install
  365. cd .test-release/pydist/mmgen-*
  366. }
  367. [ "$INSTALL_ONLY" ] && exit
  368. prompt_skip() {
  369. echo -n "Enter 's' to skip, or ENTER to continue: "; read -n1; echo
  370. [ "$REPLY" == 's' ] && return 0
  371. return 1
  372. }
  373. run_tests() {
  374. for t in $1; do
  375. eval echo -e \${GREEN}'###' Running $(echo \$i_$t) tests\$RESET
  376. eval echo -e $(echo \$s_$t)
  377. [ "$PAUSE" ] && prompt_skip && continue
  378. CUR_TEST=$t
  379. eval "do_test \"\${t_$t[@]}\""
  380. eval echo -e \$GREEN$(echo \$f_$t)\$RESET
  381. done
  382. }
  383. check_args() {
  384. for i in $tests; do
  385. echo "$dfl_tests $add_tests" | grep -q "\<$i\>" || { echo "$i: unrecognized argument"; exit; }
  386. done
  387. }
  388. tests=$dfl_tests
  389. [ "$*" ] && tests="$*"
  390. check_args
  391. echo "Running tests: $tests"
  392. START=$(date +%s)
  393. run_tests "$tests"
  394. TIME=$(($(date +%s)-START))
  395. MS=$(printf %02d:%02d $((TIME/60)) $((TIME%60)))
  396. [ "$NO_TMPFILE_REMOVAL" ] || rm -rf /tmp/mmgen-test-release-*
  397. echo -e "${GREEN}All OK. Total elapsed time: $MS$RESET"