test-release.sh 14 KB

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