test-release.sh 12 KB

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