tooltest2.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2019 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. test/tooltest2.py: Simple tests for the 'mmgen-tool' utility
  20. """
  21. # TODO: move all non-interactive 'mmgen-tool' tests in 'test.py' here
  22. # TODO: move all(?) tests in 'tooltest.py' here (or duplicate them?)
  23. import sys,os,time
  24. from subprocess import Popen,PIPE
  25. from decimal import Decimal
  26. repo_root = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),os.pardir)))
  27. os.chdir(repo_root)
  28. sys.path[0] = repo_root
  29. os.environ['MMGEN_TEST_SUITE'] = '1'
  30. # Import these _after_ prepending repo_root to sys.path
  31. from mmgen.common import *
  32. from test.common import *
  33. from mmgen.obj import is_wif,is_coin_addr
  34. from mmgen.seed import is_mnemonic
  35. NL = ('\n','\r\n')[g.platform=='win']
  36. def is_str(s): return type(s) == str
  37. def md5_hash(s):
  38. from hashlib import md5
  39. return md5(s.encode()).hexdigest()
  40. def md5_hash_strip(s):
  41. import re
  42. s = re.sub('\x1b\[[;0-9]+?m','',s) # strip ANSI color sequences
  43. s = s.replace(NL,'\n') # fix DOS newlines
  44. return md5_hash(s.strip())
  45. opts_data = {
  46. 'text': {
  47. 'desc': "Simple test suite for the 'mmgen-tool' utility",
  48. 'usage':'[options] [command]',
  49. 'options': """
  50. -h, --help Print this help message
  51. -C, --coverage Produce code coverage info using trace module
  52. -d, --die-on-missing Abort if no test data found for given command
  53. --, --longhelp Print help message for long options (common options)
  54. -l, --list-tests List the test groups in this test suite
  55. -L, --list-tested-cmds Output the 'mmgen-tool' commands that are tested by this test suite
  56. -n, --names Print command names instead of descriptions
  57. -q, --quiet Produce quieter output
  58. -s, --system Test scripts and modules installed on system rather than
  59. those in the repo root
  60. -t, --type= Specify coin type
  61. -f, --fork Run commands via tool executable instead of importing tool module
  62. -t, --traceback Run tool inside traceback script
  63. -v, --verbose Produce more verbose output
  64. """,
  65. 'notes': """
  66. If no command is given, the whole suite of tests is run.
  67. """
  68. }
  69. }
  70. sample_text_hexdump = (
  71. '000000: 5468 6520 5469 6d65 7320 3033 2f4a 616e{n}' +
  72. '000010: 2f32 3030 3920 4368 616e 6365 6c6c 6f72{n}' +
  73. '000020: 206f 6e20 6272 696e 6b20 6f66 2073 6563{n}' +
  74. '000030: 6f6e 6420 6261 696c 6f75 7420 666f 7220{n}' +
  75. '000040: 6261 6e6b 73').format(n=NL)
  76. kafile_opts = ['-p1','-Ptest/ref/keyaddrfile_password']
  77. kafile_code = (
  78. "\nopt.hash_preset = '1'" +
  79. "\nopt.set_by_user = ['hash_preset']" +
  80. "\nopt.use_old_ed25519 = None" +
  81. "\nopt.passwd_file = 'test/ref/keyaddrfile_password'" )
  82. tests = {
  83. 'Mnemonic': {
  84. 'hex2mn': [
  85. ( ['deadbeefdeadbeefdeadbeefdeadbeef'],
  86. 'table cast forgive master funny gaze sadness ripple million paint moral match' ),
  87. ( ['deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'],
  88. ('swirl maybe anymore mix scale stray fog use approach page crime rhyme ' +
  89. 'class former strange window snap soon') ),
  90. ( ['deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'],
  91. ('swell type milk figure cheese phone fill black test bloom heard comfort ' +
  92. 'image terrible radio lesson own reply battle goal goodbye need laugh stream') ),
  93. ( ['ffffffffffffffffffffffffffffffff'],
  94. 'yellow yeah show bowl season spider cling defeat poison law shelter reflect' ),
  95. ( ['ffffffffffffffffffffffffffffffffffffffffffffffff'],
  96. ('yeah youth quit fail perhaps drum out person young click skin ' +
  97. 'weird inside silently perfectly together anyone memory') ),
  98. ( ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
  99. ('wrote affection object cell opinion here laughter stare honest north cost begin ' +
  100. 'murder something yourself effort acid dot doubt game broke tell guilt innocent') ),
  101. ( ['0000000000000000000000000000000000000000000000000000000000000001'],
  102. ('able able able able able able able able able able able able ' +
  103. 'able able able able able able able able able able able about') ),
  104. ],
  105. 'mn2hex': [
  106. ( ['table cast forgive master funny gaze sadness ripple million paint moral match'],
  107. 'deadbeefdeadbeefdeadbeefdeadbeef' ),
  108. ( ['swirl maybe anymore mix scale stray fog use approach page crime rhyme ' +
  109. 'class former strange window snap soon'],
  110. 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'),
  111. ( ['swell type milk figure cheese phone fill black test bloom heard comfort ' +
  112. 'image terrible radio lesson own reply battle goal goodbye need laugh stream'],
  113. 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' ),
  114. ( ['yellow yeah show bowl season spider cling defeat poison law shelter reflect'],
  115. 'ffffffffffffffffffffffffffffffff' ),
  116. ( ['yeah youth quit fail perhaps drum out person young click skin ' +
  117. 'weird inside silently perfectly together anyone memory'],
  118. 'ffffffffffffffffffffffffffffffffffffffffffffffff' ) ,
  119. ( ['wrote affection object cell opinion here laughter stare honest north cost begin ' +
  120. 'murder something yourself effort acid dot doubt game broke tell guilt innocent'],
  121. 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'),
  122. ( ['able able able able able able able able able able able able ' +
  123. 'able able able able able able able able able able able about'],
  124. '0000000000000000000000000000000000000000000000000000000000000001'),
  125. ],
  126. 'mn_rand128': [ ( [], is_mnemonic, ['-r0']), ( ['wordlist=tirosh'], is_mnemonic, ['-r0']), ],
  127. 'mn_rand192': [ ( [], is_mnemonic, ['-r0']), ( ['wordlist=tirosh'], is_mnemonic, ['-r0']), ],
  128. 'mn_rand256': [ ( [], is_mnemonic, ['-r0']), ( ['wordlist=tirosh'], is_mnemonic, ['-r0']), ],
  129. 'mn_stats': [ ( [], is_str ), ( ['wordlist=tirosh'], is_str ), ],
  130. 'mn_printlist': [ ( [], is_str ), ( ['wordlist=tirosh'], is_str ), ],
  131. },
  132. 'Util': {
  133. 'hextob32': [
  134. ( ['deadbeef'], 'DPK3PXP' ),
  135. ( ['deadbeefdeadbeef'], 'N5LN657PK3PXP' ),
  136. ( ['ffffffffffffffff'], 'P777777777777' ),
  137. ( ['0000000000000000'], '' ),
  138. ( ['0000000000000000','pad=10'], 'AAAAAAAAAA' ),
  139. ( ['ff','pad=10'], 'AAAAAAAAH7' ),
  140. ],
  141. 'b32tohex': [
  142. ( ['DPK3PXP'], 'deadbeef' ),
  143. ( ['N5LN657PK3PXP'], 'deadbeefdeadbeef' ),
  144. ( ['P777777777777'], 'ffffffffffffffff' ),
  145. ( ['','pad=16'], '0000000000000000' ),
  146. ( ['AAAAAAAAAA','pad=16'], '0000000000000000' ),
  147. ( ['AAAAAAAAH7','pad=2'], 'ff' ),
  148. ],
  149. 'hextob58chk': [
  150. ( ['deadbeef'], 'eFGDJPketnz' ),
  151. ( ['deadbeefdeadbeef'], '5CizhNNRPYpBjrbYX' ),
  152. ( ['ffffffffffffffff'], '5qCHTcgbQwprzjWrb' ),
  153. ( ['0000000000000000'], '111111114FCKVB' ),
  154. ( [''], '3QJmnh' ),
  155. ( ['000000000000000000000000000000000000000000'], '1111111111111111111114oLvT2' ),
  156. ],
  157. 'b58chktohex': [
  158. ( ['eFGDJPketnz'], 'deadbeef' ),
  159. ( ['5CizhNNRPYpBjrbYX'], 'deadbeefdeadbeef' ),
  160. ( ['5qCHTcgbQwprzjWrb'], 'ffffffffffffffff' ),
  161. ( ['111111114FCKVB'], '0000000000000000' ),
  162. ( ['3QJmnh'], '' ),
  163. ( ['1111111111111111111114oLvT2'], '000000000000000000000000000000000000000000' ),
  164. ],
  165. 'bytestob58': [
  166. ( [b'\xde\xad\xbe\xef'], '6h8cQN' ),
  167. ( [b'\xde\xad\xbe\xef\xde\xad\xbe\xef'], 'eFGDJURJykA' ),
  168. ( [b'\xff\xff\xff\xff\xff\xff\xff\xff'], 'jpXCZedGfVQ' ),
  169. ( [b'\x00\x00\x00\x00\x00\x00\x00\x00'], '' ),
  170. ( [b'\x00\x00\x00\x00\x00\x00\x00\x00','pad=10'], '1111111111' ),
  171. ( [b'\xff','pad=10'], '111111115Q' ),
  172. ],
  173. 'b58tobytes': [
  174. ( ['6h8cQN'], b'\xde\xad\xbe\xef' ),
  175. ( ['eFGDJURJykA'], b'\xde\xad\xbe\xef\xde\xad\xbe\xef' ),
  176. ( ['jpXCZedGfVQ'], b'\xff\xff\xff\xff\xff\xff\xff\xff' ),
  177. ( ['','pad=16'], b'\x00\x00\x00\x00\x00\x00\x00\x00' ),
  178. ( ['1111111111','pad=16'], b'\x00\x00\x00\x00\x00\x00\x00\x00' ),
  179. ( ['111111115Q','pad=2'], b'\xff' ),
  180. ],
  181. 'hextob58': [
  182. ( ['deadbeef'], '6h8cQN' ),
  183. ( ['deadbeefdeadbeef'], 'eFGDJURJykA' ),
  184. ( ['ffffffffffffffff'], 'jpXCZedGfVQ' ),
  185. ( ['0000000000000000'], '' ),
  186. ( ['0000000000000000','pad=10'], '1111111111' ),
  187. ( ['ff','pad=10'], '111111115Q' ),
  188. ],
  189. 'b58tohex': [
  190. ( ['6h8cQN'], 'deadbeef' ),
  191. ( ['eFGDJURJykA'], 'deadbeefdeadbeef' ),
  192. ( ['jpXCZedGfVQ'], 'ffffffffffffffff' ),
  193. ( ['','pad=16'], '0000000000000000' ),
  194. ( ['1111111111','pad=16'], '0000000000000000' ),
  195. ( ['111111115Q','pad=2'], 'ff' ),
  196. ],
  197. 'bytespec': [
  198. ( ['1G'], str(1024*1024*1024) ),
  199. ( ['1234G'], str(1234*1024*1024*1024) ),
  200. ( ['1GB'], str(1000*1000*1000) ),
  201. ( ['1234GB'], str(1234*1000*1000*1000) ),
  202. ( ['1.234MB'], str(1234*1000) ),
  203. ( ['1.234567M'], str(int(Decimal('1.234567')*1024*1024)) ),
  204. ( ['1234'], str(1234) ),
  205. ],
  206. 'hash160': [ # TODO: check that hextob58chk(hash160) = pubhex2addr
  207. ( ['deadbeef'], 'f04df4c4b30d2b7ac6e1ed2445aeb12a9cb4d2ec' ),
  208. ( ['000000000000000000000000000000000000000000'], '2db95e704e2d9b0474acf76182f3f985b7064a8a' ),
  209. ( [''], 'b472a266d0bd89c13706a4132ccfb16f7c3b9fcb' ),
  210. ( ['ffffffffffffffff'], 'f86221f5a1fca059a865c0b7d374dfa9d5f3aeb4' ),
  211. ],
  212. 'hash256': [
  213. ( ['deadbeef'], 'e107944e77a688feae4c2d4db5951923812dd0f72026a11168104ee1b248f8a9' ),
  214. ( ['000000000000000000000000000000000000000000'], 'fd5181fcd097a334ab340569e5edcd09f702fef7994abab01f4b66e86b32ebbe' ),
  215. ( [''], '5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456' ),
  216. ( ['ffffffffffffffff'], '57b2d2c3455e0f76c61c5237ff04fc9fc0f3fe691e587ea9c951949e1a5e0fed' ),
  217. ],
  218. 'hexdump': [
  219. ( [sample_text.encode()], sample_text_hexdump ),
  220. ],
  221. 'unhexdump': [
  222. ( [sample_text_hexdump.encode()], sample_text.encode() ),
  223. ],
  224. 'hexlify': [
  225. ( [b'foobar'], '666f6f626172' ),
  226. ],
  227. 'unhexlify': [
  228. ( ['666f6f626172'], 'foobar' ),
  229. ],
  230. 'hexreverse': [
  231. ( ['deadbeefcafe'], 'fecaefbeadde' ),
  232. ],
  233. 'id6': [
  234. ( [sample_text.encode()], 'a6d72b' ),
  235. ],
  236. 'id8': [
  237. ( [sample_text.encode()], '687C09C2' ),
  238. ],
  239. 'str2id6': [
  240. ( ['74ev zjeq Zw2g DspF RKpE 7H'], '70413d' ), # checked
  241. ],
  242. 'randhex': [
  243. ( [], {'boolfunc':is_hex_str,'len':64}, ['-r0'] ),
  244. ( ['nbytes=16'], {'boolfunc':is_hex_str,'len':32}, ['-r0'] ),
  245. ( ['nbytes=6'], {'boolfunc':is_hex_str,'len':12}, ['-r0'] ),
  246. ],
  247. 'randb58': [
  248. ( [], {'boolfunc':is_b58_str,'len':44}, ['-r0'] ),
  249. ( ['nbytes=16'], {'boolfunc':is_b58_str,'len':22}, ['-r0'] ),
  250. ( ['nbytes=12','pad=false'], is_b58_str, ['-r0'] ),
  251. ],
  252. },
  253. 'Wallet': {
  254. 'gen_key': [
  255. ( ['98831F3A:11','wallet=test/ref/98831F3A.mmwords'],
  256. '5JKLcdYbhP6QQ4BXc9HtjfqJ79FFRXP2SZTKUyEuyXJo9QSFUkv'
  257. ),
  258. ( ['98831F3A:C:11','wallet=test/ref/98831F3A.mmwords'],
  259. 'L2LwXv94XTU2HjCbJPXCFuaHjrjucGipWPWUi1hkM5EykgektyqR'
  260. ),
  261. ( ['98831F3A:B:11','wallet=test/ref/98831F3A.mmwords'],
  262. 'L2K4Y9MWb5oUfKKZtwdgCm6FLZdUiWJDHjh9BYxpEvtfcXt4iM5g'
  263. ),
  264. ( ['98831F3A:S:11','wallet=test/ref/98831F3A.mmwords'],
  265. 'KwmkkfC9GghnJhnKoRXRn5KwGCgXrCmDw6Uv83NzE4kJS5axCR9A'
  266. ),
  267. ],
  268. 'gen_addr': [
  269. ( ['98831F3A:11','wallet=test/ref/98831F3A.mmwords'],
  270. '12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm'
  271. ),
  272. ( ['98831F3A:L:11','wallet=test/ref/98831F3A.mmwords'],
  273. '12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm'
  274. ),
  275. ( ['98831F3A:C:11','wallet=test/ref/98831F3A.mmwords'],
  276. '1MPsZ7BY9qikqfPxqmrovE8gLDX2rYArZk'
  277. ),
  278. ( ['98831F3A:B:11','wallet=test/ref/98831F3A.mmwords'],
  279. 'bc1qxptlvmwaymaxa7pxkr2u5pn7c0508stcncv7ms'
  280. ),
  281. ( ['98831F3A:S:11','wallet=test/ref/98831F3A.mmwords'],
  282. '3Eevao3DRVXnYym3tdrJDqS3Wc39PQzahn'
  283. ),
  284. ],
  285. 'get_subseed': [
  286. ( ['3s','wallet=test/ref/98831F3A.mmwords'], '4018EB17' ),
  287. ( ['200','wallet=test/ref/98831F3A.mmwords'], '2B05AE73' ),
  288. ],
  289. 'get_subseed_by_seed_id': [
  290. ( ['4018EB17','wallet=test/ref/98831F3A.mmwords'], '3S' ),
  291. ( ['2B05AE73','wallet=test/ref/98831F3A.mmwords'], None ),
  292. ( ['2B05AE73','wallet=test/ref/98831F3A.mmwords','last_idx=200'], '200L' ),
  293. ],
  294. 'list_subseeds': [
  295. ( ['1-5','wallet=test/ref/98831F3A.mmwords'],
  296. (md5_hash_strip,'996c047e8543d5dde6f82efc3214a6a1')
  297. ),
  298. ],
  299. },
  300. 'Coin': {
  301. 'addr2pubhash': {
  302. 'btc_mainnet': [
  303. ( ['12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm'], '118089d66b4a5853765e94923abdd5de4616c6e5' ),
  304. ( ['3Eevao3DRVXnYym3tdrJDqS3Wc39PQzahn'], '8e34586186551f6320fa3eb2d238a9c61ab8264b' ),
  305. ( ['bc1qxptlvmwaymaxa7pxkr2u5pn7c0508stcncv7ms'], '3057f66ddd26fa6ef826b0d5ca067ec3e8f3c178' ),
  306. ],
  307. },
  308. 'pubhash2addr': {
  309. 'btc_mainnet': [
  310. ( ['118089d66b4a5853765e94923abdd5de4616c6e5'], '12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm',
  311. None, 'opt.type="legacy"' ),
  312. ( ['8e34586186551f6320fa3eb2d238a9c61ab8264b'], '3Eevao3DRVXnYym3tdrJDqS3Wc39PQzahn',
  313. ['--type=segwit'], 'opt.type="segwit"' ),
  314. ( ['3057f66ddd26fa6ef826b0d5ca067ec3e8f3c178'], 'bc1qxptlvmwaymaxa7pxkr2u5pn7c0508stcncv7ms',
  315. ['--type=bech32'], 'opt.type="bech32"' ),
  316. ],
  317. },
  318. 'addr2scriptpubkey': {
  319. 'btc_mainnet': [
  320. ( ['12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm'], '76a914118089d66b4a5853765e94923abdd5de4616c6e588ac' ),
  321. ( ['3Eevao3DRVXnYym3tdrJDqS3Wc39PQzahn'], 'a9148e34586186551f6320fa3eb2d238a9c61ab8264b87' ),
  322. ( ['bc1qxptlvmwaymaxa7pxkr2u5pn7c0508stcncv7ms'], '00143057f66ddd26fa6ef826b0d5ca067ec3e8f3c178' ),
  323. ],
  324. },
  325. 'scriptpubkey2addr': {
  326. 'btc_mainnet': [
  327. ( ['76a914118089d66b4a5853765e94923abdd5de4616c6e588ac'], '12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm' ),
  328. ( ['a9148e34586186551f6320fa3eb2d238a9c61ab8264b87'], '3Eevao3DRVXnYym3tdrJDqS3Wc39PQzahn' ),
  329. ( ['00143057f66ddd26fa6ef826b0d5ca067ec3e8f3c178'], 'bc1qxptlvmwaymaxa7pxkr2u5pn7c0508stcncv7ms' ),
  330. ],
  331. },
  332. 'hex2wif': {
  333. 'btc_mainnet': [
  334. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  335. '5HwzecKMWD82ppJK3qMKpC7ohXXAwcyAN5VgdJ9PLFaAzpBG4sX',
  336. None, 'opt.type="legacy"' ),
  337. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  338. 'KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm',
  339. ['--type=compressed'], 'opt.type="compressed"' ),
  340. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  341. 'KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm',
  342. ['--type=segwit'], 'opt.type="segwit"' ),
  343. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  344. 'KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm',
  345. ['--type=bech32'], 'opt.type="bech32"' ),
  346. ],
  347. },
  348. 'privhex2addr': {
  349. 'btc_mainnet': [
  350. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  351. '1C5VPtgq9xQ6AcTgMAR3J6GDrs72HC4pS1',
  352. None, 'opt.type="legacy"' ),
  353. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  354. '1Kz9fVSUMshzPejpzW9D95kScgA3rY6QxF',
  355. ['--type=compressed'], 'opt.type="compressed"' ),
  356. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  357. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg',
  358. ['--type=segwit'], 'opt.type="segwit"' ),
  359. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  360. 'bc1q6pqnfwwakuuejpm9w52ds342f9d5u36v0qnz7c',
  361. ['--type=bech32'], 'opt.type="bech32"' ),
  362. ],
  363. },
  364. 'privhex2pubhex': {
  365. 'btc_mainnet': [
  366. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  367. '044281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e972757f3254c322eeaa3cb6bf97cc5ecf8d4387b0df2c0b1e6ee18fe3a6977a7d57a',
  368. None, 'opt.type="legacy"' ),
  369. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  370. '024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727',
  371. ['--type=compressed'], 'opt.type="compressed"' ),
  372. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  373. '024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727',
  374. ['--type=segwit'], 'opt.type="segwit"' ),
  375. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  376. '024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727',
  377. ['--type=bech32'], 'opt.type="bech32"' ),
  378. ],
  379. },
  380. 'pubhex2addr': {
  381. 'btc_mainnet': [
  382. ( ['044281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e972757f3254c322eeaa3cb6bf97cc5ecf8d4387b0df2c0b1e6ee18fe3a6977a7d57a'],
  383. '1C5VPtgq9xQ6AcTgMAR3J6GDrs72HC4pS1',
  384. None, 'opt.type="legacy"' ),
  385. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  386. '1Kz9fVSUMshzPejpzW9D95kScgA3rY6QxF',
  387. ['--type=compressed'], 'opt.type="compressed"' ),
  388. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  389. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg',
  390. ['--type=segwit'], 'opt.type="segwit"' ),
  391. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  392. 'bc1q6pqnfwwakuuejpm9w52ds342f9d5u36v0qnz7c',
  393. ['--type=bech32'], 'opt.type="bech32"' ),
  394. ],
  395. },
  396. 'pubhex2redeem_script': {
  397. 'btc_mainnet': [
  398. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  399. '0014d04134b9ddb7399907657514d846aa495b4e474c',
  400. ['--type=segwit'], 'opt.type="segwit"' ),
  401. ],
  402. },
  403. 'redeem_script2addr': {
  404. 'btc_mainnet': [
  405. ( ['0014d04134b9ddb7399907657514d846aa495b4e474c'],
  406. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg',
  407. ['--type=segwit'], 'opt.type="segwit"' ),
  408. ],
  409. },
  410. 'randpair': {
  411. 'btc_mainnet': [ ( [], [is_wif,is_coin_addr], ['-r0'] ) ],
  412. 'btc_testnet': [ ( [], [is_wif,is_coin_addr], ['-r0'] ) ],
  413. },
  414. 'randwif': {
  415. 'btc_mainnet': [ ( [], is_wif, ['-r0'] ) ],
  416. 'btc_testnet': [ ( [], is_wif, ['-r0'] ) ],
  417. },
  418. 'wif2addr': {
  419. 'btc_mainnet': [
  420. ( ['5HwzecKMWD82ppJK3qMKpC7ohXXAwcyAN5VgdJ9PLFaAzpBG4sX'],
  421. '1C5VPtgq9xQ6AcTgMAR3J6GDrs72HC4pS1', ['--type=legacy'], 'opt.type="legacy"' ),
  422. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  423. '1Kz9fVSUMshzPejpzW9D95kScgA3rY6QxF', ['--type=compressed'], 'opt.type="compressed"' ),
  424. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  425. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg', ['--type=segwit'], 'opt.type="segwit"' ),
  426. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  427. 'bc1q6pqnfwwakuuejpm9w52ds342f9d5u36v0qnz7c', ['--type=bech32'], 'opt.type="bech32"' ),
  428. ],
  429. },
  430. 'wif2hex': {
  431. 'btc_mainnet': [
  432. ( ['5HwzecKMWD82ppJK3qMKpC7ohXXAwcyAN5VgdJ9PLFaAzpBG4sX'],
  433. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  434. None, 'opt.type="legacy"' ),
  435. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  436. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  437. ['--type=compressed'], 'opt.type="compressed"' ),
  438. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  439. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  440. ['--type=segwit'], 'opt.type="segwit"' ),
  441. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  442. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  443. ['--type=bech32'], 'opt.type="bech32"' ),
  444. ],
  445. },
  446. 'wif2redeem_script': {
  447. 'btc_mainnet': [
  448. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  449. '0014d04134b9ddb7399907657514d846aa495b4e474c',
  450. ['--type=segwit'], 'opt.type="segwit"' ),
  451. ],
  452. },
  453. 'wif2segwit_pair': {
  454. 'btc_mainnet': [
  455. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  456. ('0014d04134b9ddb7399907657514d846aa495b4e474c','3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg'),
  457. ['--type=segwit'], 'opt.type="segwit"' ),
  458. ],
  459. },
  460. },
  461. # TODO: compressed address files are missing
  462. # 'addrfile_compressed_chk':
  463. # 'btc': ('A33C 4FDE F515 F5BC','6C48 AA57 2056 C8C8'),
  464. # 'ltc': ('3FC0 8F03 C2D6 BD19','4C0A 49B6 2DD1 1BE0'),
  465. 'File': {
  466. 'addrfile_chksum': {
  467. 'btc_mainnet': [
  468. ( ['test/ref/98831F3A[1,31-33,500-501,1010-1011].addrs'],
  469. '6FEF 6FB9 7B13 5D91'),
  470. ( ['test/ref/98831F3A-S[1,31-33,500-501,1010-1011].addrs'],
  471. '06C1 9C87 F25C 4EE6'),
  472. ( ['test/ref/98831F3A-B[1,31-33,500-501,1010-1011].addrs'],
  473. '9D2A D4B6 5117 F02E'),
  474. ],
  475. 'btc_testnet': [
  476. ( ['test/ref/98831F3A[1,31-33,500-501,1010-1011].testnet.addrs'],
  477. '424E 4326 CFFE 5F51'),
  478. ( ['test/ref/98831F3A-S[1,31-33,500-501,1010-1011].testnet.addrs'],
  479. '072C 8B07 2730 CB7A'),
  480. ( ['test/ref/98831F3A-B[1,31-33,500-501,1010-1011].testnet.addrs'],
  481. '0527 9C39 6C1B E39A'),
  482. ],
  483. 'ltc_mainnet': [
  484. ( ['test/ref/litecoin/98831F3A-LTC[1,31-33,500-501,1010-1011].addrs'],
  485. 'AD52 C3FE 8924 AAF0'),
  486. ( ['test/ref/litecoin/98831F3A-LTC-S[1,31-33,500-501,1010-1011].addrs'],
  487. '63DF E42A 0827 21C3'),
  488. ( ['test/ref/litecoin/98831F3A-LTC-B[1,31-33,500-501,1010-1011].addrs'],
  489. 'FF1C 7939 5967 AB82'),
  490. ],
  491. 'ltc_testnet': [
  492. ( ['test/ref/litecoin/98831F3A-LTC[1,31-33,500-501,1010-1011].testnet.addrs'],
  493. '4EBE 2E85 E969 1B30'),
  494. ( ['test/ref/litecoin/98831F3A-LTC-S[1,31-33,500-501,1010-1011].testnet.addrs'],
  495. '5DD1 D186 DBE1 59F2'),
  496. ( ['test/ref/litecoin/98831F3A-LTC-B[1,31-33,500-501,1010-1011].testnet.addrs'],
  497. 'ED3D 8AA4 BED4 0B40'),
  498. ],
  499. 'zec_mainnet': [
  500. ( ['test/ref/zcash/98831F3A-ZEC-C[1,31-33,500-501,1010-1011].addrs'],'903E 7225 DD86 6E01'), ],
  501. 'zec_z_mainnet': [
  502. ( ['test/ref/zcash/98831F3A-ZEC-Z[1,31-33,500-501,1010-1011].addrs'],'9C7A 72DC 3D4A B3AF'), ],
  503. 'xmr_mainnet': [
  504. ( ['test/ref/monero/98831F3A-XMR-M[1,31-33,500-501,1010-1011].addrs'],'4369 0253 AC2C 0E38'), ],
  505. 'dash_mainnet': [
  506. ( ['test/ref/dash/98831F3A-DASH-C[1,31-33,500-501,1010-1011].addrs'],'FBC1 6B6A 0988 4403'), ],
  507. 'eth_mainnet': [
  508. ( ['test/ref/ethereum/98831F3A-ETH[1,31-33,500-501,1010-1011].addrs'],'E554 076E 7AF6 66A3'), ],
  509. 'etc_mainnet': [
  510. ( ['test/ref/ethereum_classic/98831F3A-ETC[1,31-33,500-501,1010-1011].addrs'],
  511. 'E97A D796 B495 E8BC'), ],
  512. },
  513. 'keyaddrfile_chksum': {
  514. 'btc_mainnet': [
  515. ( ['test/ref/98831F3A[1,31-33,500-501,1010-1011].akeys.mmenc'],
  516. '9F2D D781 1812 8BAD', kafile_opts, kafile_code ),
  517. ],
  518. 'btc_testnet': [
  519. ( ['test/ref/98831F3A[1,31-33,500-501,1010-1011].testnet.akeys.mmenc'],
  520. '88CC 5120 9A91 22C2', kafile_opts, kafile_code ),
  521. ],
  522. 'ltc_mainnet': [
  523. ( ['test/ref/litecoin/98831F3A-LTC[1,31-33,500-501,1010-1011].akeys.mmenc'],
  524. 'B804 978A 8796 3ED4', kafile_opts, kafile_code ),
  525. ],
  526. 'ltc_testnet': [
  527. ( ['test/ref/litecoin/98831F3A-LTC[1,31-33,500-501,1010-1011].testnet.akeys.mmenc'],
  528. '98B5 AC35 F334 0398', kafile_opts, kafile_code ),
  529. ],
  530. 'zec_mainnet': [
  531. ( ['test/ref/zcash/98831F3A-ZEC-C[1,31-33,500-501,1010-1011].akeys.mmenc'],
  532. 'F05A 5A5C 0C8E 2617', kafile_opts, kafile_code ), ],
  533. 'zec_z_mainnet': [
  534. ( ['test/ref/zcash/98831F3A-ZEC-Z[1,31-33,500-501,1010-1011].akeys.mmenc'],
  535. '6B87 9B2D 0D8D 8D1E', kafile_opts, kafile_code ), ],
  536. 'xmr_mainnet': [
  537. ( ['test/ref/monero/98831F3A-XMR-M[1,31-33,500-501,1010-1011].akeys.mmenc'],
  538. 'E0D7 9612 3D67 404A', kafile_opts, kafile_code ), ],
  539. 'dash_mainnet': [
  540. ( ['test/ref/dash/98831F3A-DASH-C[1,31-33,500-501,1010-1011].akeys.mmenc'],
  541. 'E83D 2C63 FEA2 4142', kafile_opts, kafile_code ), ],
  542. 'eth_mainnet': [
  543. ( ['test/ref/ethereum/98831F3A-ETH[1,31-33,500-501,1010-1011].akeys.mmenc'],
  544. 'E400 70D9 0AE3 C7C2', kafile_opts, kafile_code ), ],
  545. 'etc_mainnet': [
  546. ( ['test/ref/ethereum_classic/98831F3A-ETC[1,31-33,500-501,1010-1011].akeys.mmenc'],
  547. 'EF49 967D BD6C FE45', kafile_opts, kafile_code ), ],
  548. },
  549. 'passwdfile_chksum': {
  550. 'btc_mainnet': [
  551. ( ['test/ref/98831F3A-фубар@crypto.org-b58-20[1,4,9-11,1100].pws'],
  552. 'A983 DAB9 5514 27FB', kafile_opts, kafile_code ), ],
  553. },
  554. 'txview': {
  555. 'btc_mainnet': [ ( ['test/ref/0B8D5A[15.31789,14,tl=1320969600].rawtx'], None ), ],
  556. 'btc_testnet': [ ( ['test/ref/0C7115[15.86255,14,tl=1320969600].testnet.rawtx'], None ), ],
  557. 'bch_mainnet': [ ( ['test/ref/460D4D-BCH[10.19764,tl=1320969600].rawtx'], None ), ],
  558. 'bch_testnet': [ ( ['test/ref/359FD5-BCH[6.68868,tl=1320969600].testnet.rawtx'], None ), ],
  559. 'ltc_mainnet': [ ( ['test/ref/litecoin/AF3CDF-LTC[620.76194,1453,tl=1320969600].rawtx'], None ), ],
  560. 'ltc_testnet': [ ( ['test/ref/litecoin/A5A1E0-LTC[1454.64322,1453,tl=1320969600].testnet.rawtx'],
  561. None ), ],
  562. 'eth_mainnet': [ ( ['test/ref/ethereum/88FEFD-ETH[23.45495,40000].rawtx'], None ), ],
  563. 'eth_testnet': [ ( ['test/ref/ethereum/B472BD-ETH[23.45495,40000].testnet.rawtx'], None ), ],
  564. 'mm1_mainnet': [ ( ['test/ref/ethereum/5881D2-MM1[1.23456,50000].rawtx'], None ), ],
  565. 'mm1_testnet': [ ( ['test/ref/ethereum/6BDB25-MM1[1.23456,50000].testnet.rawtx'], None ), ],
  566. 'etc_mainnet': [ ( ['test/ref/ethereum_classic/ED3848-ETC[1.2345,40000].rawtx'], None ), ],
  567. },
  568. },
  569. }
  570. coin_dependent_groups = ('Coin','File') # TODO: do this as attr of each group in tool.py
  571. def run_test(gid,cmd_name):
  572. data = tests[gid][cmd_name]
  573. # behavior is like test.py: run coin-dependent tests only if g.testnet or g.coin != BTC
  574. if gid in coin_dependent_groups:
  575. k = '{}_{}net'.format((g.token.lower() if g.token else g.coin.lower()),('main','test')[g.testnet])
  576. if k in data:
  577. data = data[k]
  578. m2 = ' ({})'.format(k)
  579. else:
  580. msg("-- no data for {} ({}) - skipping".format(cmd_name,k))
  581. return
  582. else:
  583. if g.coin != 'BTC' or g.testnet: return
  584. m2 = ''
  585. m = '{} {}{}'.format(purple('Testing'), cmd_name if opt.names else
  586. extract_docstring(getattr(getattr(tool,'MMGenToolCmd'+gid),cmd_name)),m2)
  587. msg_r(green(m)+'\n' if opt.verbose else m)
  588. def fork_cmd(cmd_name,args,out,opts,exec_code):
  589. cmd = list(tool_cmd) + (opts or []) + [cmd_name] + args
  590. vmsg('{} {}'.format(green('Executing'),cyan(' '.join(cmd))))
  591. p = Popen(cmd,stdin=(PIPE if stdin_input else None),stdout=PIPE,stderr=PIPE)
  592. if stdin_input:
  593. p.stdin.write(stdin_input)
  594. p.stdin.close()
  595. cmd_out = p.stdout.read()
  596. try:
  597. cmd_out = cmd_out.decode().strip()
  598. except:
  599. pass
  600. cmd_err = p.stderr.read()
  601. if cmd_err: vmsg(cmd_err.strip().decode())
  602. if p.wait() != 0:
  603. import re
  604. m = re.match(b"tool command returned '(None|False)'"+NL.encode(),cmd_err)
  605. if m:
  606. return { b'None': None, b'False': False }[m.group(1)]
  607. else:
  608. ydie(1,'Spawned program exited with error: {}'.format(cmd_err))
  609. return cmd_out
  610. def run_func(cmd_name,args,out,opts,exec_code):
  611. vmsg('{}: {}{}'.format(purple('Running'),
  612. ' '.join([cmd_name]+[repr(e) for e in args]),
  613. ' '+exec_code if exec_code else '' ))
  614. if exec_code: exec(exec_code)
  615. aargs,kwargs = tool._process_args(cmd_name,args)
  616. oq_save = opt.quiet
  617. if not opt.verbose: opt.quiet = True
  618. if stdin_input:
  619. fd0,fd1 = os.pipe()
  620. if os.fork(): # parent
  621. os.close(fd1)
  622. stdin_save = os.dup(0)
  623. os.dup2(fd0,0)
  624. cmd_out = getattr(tc,cmd_name)(*aargs,**kwargs)
  625. os.dup2(stdin_save,0)
  626. os.wait()
  627. opt.quiet = oq_save
  628. return cmd_out
  629. else: # child
  630. os.close(fd0)
  631. os.write(fd1,stdin_input)
  632. vmsg('Input: {!r}'.format(stdin_input))
  633. sys.exit(0)
  634. else:
  635. ret = getattr(tc,cmd_name)(*aargs,**kwargs)
  636. opt.quiet = oq_save
  637. return ret
  638. for d in data:
  639. args,out,opts,exec_code = d + tuple([None] * (4-len(d)))
  640. stdin_input = None
  641. if args and type(args[0]) == bytes:
  642. stdin_input = args[0]
  643. args[0] = '-'
  644. if opt.fork:
  645. cmd_out = fork_cmd(cmd_name,args,out,opts,exec_code)
  646. else:
  647. if stdin_input and g.platform == 'win':
  648. msg('Skipping for MSWin - no os.fork()')
  649. continue
  650. cmd_out = run_func(cmd_name,args,out,opts,exec_code)
  651. vmsg('Output: {}\n'.format(cmd_out if issubclass(type(out),str) else repr(cmd_out)))
  652. def check_output(cmd_out,out):
  653. if issubclass(type(out),str): out = out.encode()
  654. if issubclass(type(cmd_out),int): cmd_out = str(cmd_out).encode()
  655. if issubclass(type(cmd_out),str): cmd_out = cmd_out.encode()
  656. if type(out).__name__ == 'function':
  657. assert out(cmd_out.decode()),"{}({}) failed!".format(out.__name__,cmd_out.decode())
  658. elif type(out) == dict:
  659. for k in out:
  660. if k == 'boolfunc':
  661. assert out[k](cmd_out.decode()),"{}({}) failed!".format(out[k].__name__,cmd_out.decod())
  662. else:
  663. if not getattr(__builtins__,k)(cmd_out) == out[k]:
  664. die(1,"{}({}) did not return {}!".format(k,cmd_out,out[k]))
  665. elif out is not None:
  666. assert cmd_out == out,"Output ({!r}) doesn't match expected output ({!r})".format(cmd_out,out)
  667. if type(out) == tuple and type(out[0]).__name__ == 'function':
  668. func_out = out[0](cmd_out)
  669. assert func_out == out[1],(
  670. "{}({}) == {} failed!\nOutput: {}".format(out[0].__name__,cmd_out,out[1],func_out))
  671. elif type(out) in (list,tuple):
  672. for co,o in zip(cmd_out.split(NL) if opt.fork else cmd_out,out):
  673. check_output(co,o)
  674. else:
  675. check_output(cmd_out,out)
  676. if not opt.verbose: msg_r('.')
  677. if not opt.verbose:
  678. msg('OK')
  679. def extract_docstring(obj):
  680. return obj.__doc__.strip().split('\n')[0]
  681. def do_group(gid):
  682. qmsg(blue("Testing {}".format(
  683. "command group '{}'".format(gid) if opt.names
  684. else extract_docstring(getattr(tool,'MMGenToolCmd'+gid)))))
  685. for cname in [e for e in dir(getattr(tool,'MMGenToolCmd'+gid)) if e[0] != '_']:
  686. if cname not in tests[gid]:
  687. m = 'No test for command {!r} in group {!r}!'.format(cname,gid)
  688. if opt.die_on_missing:
  689. die(1,m+' Aborting')
  690. else:
  691. msg(m)
  692. continue
  693. run_test(gid,cname)
  694. def do_cmd_in_group(cmd):
  695. for gid in tests:
  696. for cname in tests[gid]:
  697. if cname == cmd:
  698. run_test(gid,cname)
  699. return True
  700. return False
  701. def list_tested_cmds():
  702. for gid in tests:
  703. for cname in [e for e in dir(getattr(tool,'MMGenToolCmd'+gid)) if e[0] != '_']:
  704. Msg(cname)
  705. sys.argv = [sys.argv[0]] + ['--skip-cfg-file'] + sys.argv[1:]
  706. cmd_args = opts.init(opts_data)
  707. import mmgen.tool as tool
  708. if opt.list_tests:
  709. Msg('Available tests:')
  710. for gid in tests:
  711. Msg(' {:6} - {}'.format(gid,extract_docstring(getattr(tool,'MMGenToolCmd'+gid))))
  712. sys.exit(0)
  713. if opt.list_tested_cmds:
  714. list_tested_cmds()
  715. sys.exit(0)
  716. if opt.system:
  717. tool_exec = 'mmgen-tool'
  718. sys.path.pop(0)
  719. else:
  720. os.environ['PYTHONPATH'] = repo_root
  721. tool_exec = os.path.relpath(os.path.join('cmds','mmgen-tool'))
  722. if opt.fork:
  723. tool_cmd = (tool_exec,'--skip-cfg-file')
  724. passthru_args = ['coin','type','testnet','token']
  725. tool_cmd += tuple(['--{}{}'.format(k.replace('_','-'),
  726. '='+getattr(opt,k) if getattr(opt,k) != True else ''
  727. ) for k in passthru_args if getattr(opt,k)])
  728. if opt.traceback:
  729. tool_cmd = (os.path.join('scripts','traceback_run.py'),) + tool_cmd
  730. if opt.coverage:
  731. d,f = init_coverage()
  732. tool_cmd = ('python3','-m','trace','--count','--coverdir='+d,'--file='+f) + tool_cmd
  733. elif g.platform == 'win':
  734. tool_cmd = ('python3',) + tool_cmd
  735. else:
  736. opt.usr_randchars = 0
  737. tc = tool.MMGenToolCmd()
  738. start_time = int(time.time())
  739. try:
  740. if cmd_args:
  741. if len(cmd_args) != 1:
  742. die(1,'Only one command may be specified')
  743. cmd = cmd_args[0]
  744. if cmd in tests:
  745. do_group(cmd)
  746. else:
  747. if not do_cmd_in_group(cmd):
  748. die(1,"'{}': not a recognized test or test group".format(cmd))
  749. else:
  750. for garg in tests:
  751. do_group(garg)
  752. except KeyboardInterrupt:
  753. die(1,green('\nExiting at user request'))
  754. t = int(time.time()) - start_time
  755. gmsg('All requested tests finished OK, elapsed time: {:02}:{:02}'.format(t//60,t%60))