test-release.sh 12 KB

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