test-release.sh 13 KB

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