tooltest.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2017 Philemon <mmgen-py@yandex.com>
  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/tooltest.py: Tests for the 'mmgen-tool' utility
  20. """
  21. import sys,os,subprocess
  22. repo_root = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),os.pardir)))
  23. os.chdir(repo_root)
  24. sys.path.__setitem__(0,repo_root)
  25. # Import this _after_ local path's been added to sys.path
  26. from mmgen.common import *
  27. opts_data = lambda: {
  28. 'desc': "Test suite for the 'mmgen-tool' utility",
  29. 'usage':'[options] [command]',
  30. 'options': """
  31. -h, --help Print this help message
  32. --, --longhelp Print help message for long options (common options)
  33. -l, --list-cmds List and describe the tests and commands in this test suite
  34. -L, --list-names List the names of all tested 'mmgen-tool' commands
  35. -s, --system Test scripts and modules installed on system rather than
  36. those in the repo root
  37. -t, --type=t Specify address type (valid options: 'zcash_z')
  38. -v, --verbose Produce more verbose output
  39. """,
  40. 'notes': """
  41. If no command is given, the whole suite of tests is run.
  42. """
  43. }
  44. sys.argv = [sys.argv[0]] + ['--skip-cfg-file'] + sys.argv[1:]
  45. cmd_args = opts.init(opts_data,add_opts=['exact_output','profile'])
  46. from collections import OrderedDict
  47. cmd_data = OrderedDict([
  48. ('util', {
  49. 'desc': 'base conversion, hashing and file utilities',
  50. 'cmd_data': OrderedDict([
  51. ('Strtob58', ()),
  52. ('B58tostr', ('Strtob58','io')),
  53. ('Hextob58', ()),
  54. ('B58tohex', ('Hextob58','io')),
  55. ('B58randenc', ()),
  56. ('Hextob32', ()),
  57. ('B32tohex', ('Hextob32','io')),
  58. ('Randhex', ()),
  59. ('Id6', ()),
  60. ('Id8', ()),
  61. ('Str2id6', ()),
  62. ('Hash160', ()),
  63. ('Hash256', ()),
  64. ('Hexreverse', ()),
  65. ('Hexlify', ()),
  66. ('Hexdump', ()),
  67. ('Unhexdump', ('Hexdump','io')),
  68. ('Rand2file', ()),
  69. ])
  70. }
  71. ),
  72. ('cryptocoin', {
  73. 'desc': 'Cryptocoin address/key commands',
  74. 'cmd_data': OrderedDict([
  75. ('Randwif', ()),
  76. ('Randpair', ()), # create 3 pairs: uncomp,comp,segwit
  77. ('Wif2addr', ('Randpair','o3')),
  78. ('Wif2hex', ('Randpair','o3')),
  79. ('Privhex2pubhex', ('Wif2hex','o3')),
  80. ('Pubhex2addr', ('Privhex2pubhex','o3')),
  81. ('Hex2wif', ('Wif2hex','io2')),
  82. ('Addr2hexaddr', ('Randpair','o2'))] + # TODO: Hexaddr2addr
  83. ([],[
  84. ('Pubhash2addr', ('Addr2hexaddr','io2'))
  85. ])[opt.type != 'zcash_z'] +
  86. ([],[
  87. ('Pubhex2redeem_script', ('Privhex2pubhex','o3')),
  88. ('Wif2redeem_script', ('Randpair','o3')),
  89. ('Wif2segwit_pair', ('Randpair','o2')),
  90. ('Privhex2addr', ('Wif2hex','o3')), # compare with output of Randpair
  91. ('Pipetest', ('Randpair','o3'))
  92. ])[g.coin in ('BTC','LTC')]
  93. )
  94. }
  95. ),
  96. ('mnemonic', {
  97. 'desc': 'mnemonic commands',
  98. 'cmd_data': OrderedDict([
  99. ('Hex2mn', ()),
  100. ('Mn2hex', ('Hex2mn','io3')),
  101. ('Mn_rand128', ()),
  102. ('Mn_rand192', ()),
  103. ('Mn_rand256', ()),
  104. ('Mn_stats', ()),
  105. ('Mn_printlist', ()),
  106. ])
  107. }
  108. ),
  109. ('rpc', {
  110. 'desc': 'Coin daemon RPC commands',
  111. 'cmd_data': OrderedDict([
  112. # ('Keyaddrfile_chksum', ()), # interactive
  113. ('Addrfile_chksum', ()),
  114. ('Getbalance', ()),
  115. ('Listaddresses', ()),
  116. ('Twview', ()),
  117. ('Txview', ()),
  118. ])
  119. }
  120. ),
  121. ])
  122. cfg = {
  123. 'name': 'the tool utility',
  124. 'enc_passwd': 'Ten Satoshis',
  125. 'tmpdir': 'test/tmp10',
  126. 'tmpdir_num': 10,
  127. 'refdir': 'test/ref',
  128. 'txfile': {
  129. 'btc': 'FFB367[1.234]{}.rawtx',
  130. 'bch': '99BE60-BCH[106.6789]{}.rawtx',
  131. 'ltc': '75F455-LTC[106.6789]{}.rawtx',
  132. },
  133. 'addrfile': '98831F3A{}[1,31-33,500-501,1010-1011]{}.addrs',
  134. 'addrfile_chk': {
  135. 'btc': ('6FEF 6FB9 7B13 5D91','3C2C 8558 BB54 079E'),
  136. 'ltc': ('AD52 C3FE 8924 AAF0','5738 5C4F 167C F9AE'),
  137. }
  138. }
  139. ref_subdir = '' if g.proto.base_coin == 'BTC' else g.proto.name
  140. altcoin_pfx = '' if g.proto.base_coin == 'BTC' else '-'+g.proto.base_coin
  141. tn_ext = ('','.testnet')[g.testnet]
  142. mmgen_cmd = 'mmgen-tool'
  143. if not opt.system:
  144. os.environ['PYTHONPATH'] = repo_root
  145. mmgen_cmd = os.path.relpath(os.path.join(repo_root,'cmds',mmgen_cmd))
  146. spawn_cmd = ([],['python'])[g.platform == 'win'] + [mmgen_cmd]
  147. add_spawn_args = ['--data-dir='+cfg['tmpdir']] + ['--{}{}'.format(
  148. k.replace('_','-'),'='+getattr(opt,k) if getattr(opt,k) != True else '')
  149. for k in ('testnet','rpc_host','regtest','coin','type') if getattr(opt,k)]
  150. if opt.list_cmds:
  151. fs = ' {:<{w}} - {}'
  152. Msg('Available commands:')
  153. w = max([len(i) for i in cmd_data])
  154. for cmd in cmd_data:
  155. Msg(fs.format(cmd,cmd_data[cmd]['desc'],w=w))
  156. Msg('\nAvailable utilities:')
  157. Msg(fs.format('clean','Clean the tmp directory',w=w))
  158. sys.exit(0)
  159. if opt.list_names:
  160. acc = []
  161. for v in cmd_data.values():
  162. acc += v['cmd_data'].keys()
  163. tc = sorted(c.lower() for c in acc)
  164. msg('{}\n{}'.format(green('Tested commands:'),'\n'.join(tc)))
  165. import mmgen.tool
  166. tested_in_tool = ('Encrypt','Decrypt','Find_incog_data','Keyaddrfile_chksum','Passwdfile_chksum')
  167. ignore = ('Help','Usage')
  168. uc = sorted(c.lower() for c in set(mmgen.tool.cmd_data.keys()) - set(acc) - set(ignore) - set(tested_in_tool))
  169. msg('\n{}\n{}'.format(yellow('Untested commands:'),'\n'.join(uc)))
  170. die()
  171. import binascii
  172. from mmgen.test import *
  173. from mmgen.tx import is_wif,is_coin_addr
  174. msg_w = 35
  175. def test_msg(m):
  176. m2 = 'Testing {}'.format(m)
  177. msg_r(green(m2+'\n') if opt.verbose else '{:{w}}'.format(m2,w=msg_w+8))
  178. maybe_compressed = ('','compressed')['C' in g.proto.mmtypes]
  179. maybe_segwit = ('','segwit')['S' in g.proto.mmtypes]
  180. maybe_type_compressed = ([],['--type=compressed'])['C' in g.proto.mmtypes]
  181. maybe_type_segwit = ([],['--type=segwit'])['S' in g.proto.mmtypes]
  182. class MMGenToolTestSuite(object):
  183. def __init__(self):
  184. pass
  185. def gen_deps_for_cmd(self,cmd,cdata):
  186. fns = []
  187. if cdata:
  188. name,code = cdata
  189. io,count = (code[:-1],int(code[-1])) if code[-1] in '0123456789' else (code,1)
  190. for c in range(count):
  191. fns += ['{}{}{}'.format(name,('',c+1)[count > 1],('.out','.in')[ch=='i']) for ch in io]
  192. return fns
  193. def get_num_exts_for_cmd(self,cmd,dpy): # dpy required here
  194. num = str(tool_cfgs['tmpdir_num'])
  195. # return only first file - a hack
  196. exts = gen_deps_for_cmd(dpy)
  197. return num,exts
  198. def do_cmds(self,cmd_group):
  199. cdata = cmd_data[cmd_group]['cmd_data']
  200. for cmd in cdata: self.do_cmd(cmd,cdata[cmd])
  201. def do_cmd(self,cmd,cdata):
  202. fns = self.gen_deps_for_cmd(cmd,cdata)
  203. file_list = [os.path.join(cfg['tmpdir'],fn) for fn in fns]
  204. self.__class__.__dict__[cmd](*([self,cmd] + file_list))
  205. def run_cmd(self,name,tool_args,kwargs='',extra_msg='',silent=False,strip=True,add_opts=[]):
  206. sys_cmd = (
  207. spawn_cmd +
  208. add_spawn_args +
  209. ['-r0','-d',cfg['tmpdir']] +
  210. add_opts +
  211. [name.lower()] +
  212. tool_args +
  213. kwargs.split()
  214. )
  215. if extra_msg: extra_msg = '({})'.format(extra_msg)
  216. full_name = ' '.join([name.lower()]+add_opts+kwargs.split()+extra_msg.split())
  217. if not silent:
  218. if opt.verbose:
  219. sys.stderr.write(green('Testing {}\nExecuting '.format(full_name)))
  220. sys.stderr.write(cyan(' '.join(sys_cmd)+'\n'))
  221. else:
  222. msg_r('Testing {:{w}}'.format(full_name+':',w=msg_w))
  223. p = subprocess.Popen(sys_cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
  224. a,b = p.communicate()
  225. retcode = p.wait()
  226. if retcode != 0:
  227. msg('%s\n%s\n%s'%(red('FAILED'),yellow('Command stderr output:'),b))
  228. die(1,red('Called process returned with an error (retcode %s)' % retcode))
  229. return (a,a.rstrip())[bool(strip)]
  230. def run_cmd_chk(self,name,f1,f2,kwargs='',extra_msg='',strip_hex=False,add_opts=[]):
  231. idata = read_from_file(f1).rstrip()
  232. odata = read_from_file(f2).rstrip()
  233. ret = self.run_cmd(name,[odata],kwargs=kwargs,extra_msg=extra_msg,add_opts=add_opts)
  234. vmsg('In: ' + repr(odata))
  235. vmsg('Out: ' + repr(ret))
  236. def cmp_equal(a,b):
  237. return (a.lstrip('0') == b.lstrip('0')) if strip_hex else (a == b)
  238. if cmp_equal(ret,idata): ok()
  239. else:
  240. die(3,red(
  241. "Error: values don't match:\nIn: %s\nOut: %s" % (repr(idata),repr(ret))))
  242. return ret
  243. def run_cmd_nochk(self,name,f1,kwargs='',add_opts=[]):
  244. odata = read_from_file(f1).rstrip()
  245. ret = self.run_cmd(name,[odata],kwargs=kwargs,add_opts=add_opts)
  246. vmsg('In: ' + repr(odata))
  247. vmsg('Out: ' + repr(ret))
  248. return ret
  249. def run_cmd_out(self,name,carg=None,Return=False,kwargs='',fn_idx='',extra_msg='',literal=False,chkdata='',hush=False,add_opts=[]):
  250. if carg: write_to_tmpfile(cfg,'%s%s.in' % (name,fn_idx),carg+'\n')
  251. ret = self.run_cmd(name,([],[carg])[bool(carg)],kwargs=kwargs,extra_msg=extra_msg,add_opts=add_opts)
  252. if carg: vmsg('In: ' + repr(carg))
  253. vmsg('Out: ' + (repr(ret),ret.decode('utf8'))[literal])
  254. if ret or ret == '':
  255. write_to_tmpfile(cfg,'%s%s.out' % (name,fn_idx),ret+'\n')
  256. if chkdata:
  257. cmp_or_die(ret,chkdata)
  258. return
  259. if Return: return ret
  260. else:
  261. if not hush: ok()
  262. else:
  263. die(3,red("Error for command '%s'" % name))
  264. def run_cmd_randinput(self,name,strip=True,add_opts=[]):
  265. s = os.urandom(128)
  266. fn = name+'.in'
  267. write_to_tmpfile(cfg,fn,s,binary=True)
  268. ret = self.run_cmd(name,[get_tmpfile_fn(cfg,fn)],strip=strip,add_opts=add_opts)
  269. fn = name+'.out'
  270. write_to_tmpfile(cfg,fn,ret+'\n')
  271. ok()
  272. vmsg('Returned: %s' % ret)
  273. # Util
  274. def Strtob58(self,name): self.run_cmd_out(name,getrandstr(16))
  275. def B58tostr(self,name,f1,f2): self.run_cmd_chk(name,f1,f2)
  276. def Hextob58(self,name): self.run_cmd_out(name,getrandhex(32))
  277. def B58tohex(self,name,f1,f2): self.run_cmd_chk(name,f1,f2,strip_hex=True)
  278. def B58randenc(self,name):
  279. ret = self.run_cmd_out(name,Return=True)
  280. ok_or_die(ret,is_b58_str,'base 58 string')
  281. def Hextob32(self,name): self.run_cmd_out(name,getrandhex(24))
  282. def B32tohex(self,name,f1,f2): self.run_cmd_chk(name,f1,f2,strip_hex=True)
  283. def Randhex(self,name):
  284. ret = self.run_cmd_out(name,Return=True)
  285. ok_or_die(ret,binascii.unhexlify,'hex string')
  286. def Id6(self,name): self.run_cmd_randinput(name)
  287. def Id8(self,name): self.run_cmd_randinput(name)
  288. def Str2id6(self,name):
  289. s = getrandstr(120,no_space=True)
  290. s2 = ' %s %s %s %s %s ' % (s[:3],s[3:9],s[9:29],s[29:50],s[50:120])
  291. ret1 = self.run_cmd(name,[s],extra_msg='unspaced input'); ok()
  292. ret2 = self.run_cmd(name,[s2],extra_msg='spaced input')
  293. cmp_or_die(ret1,ret2)
  294. vmsg('Returned: %s' % ret1)
  295. def Hash160(self,name): self.run_cmd_out(name,getrandhex(16))
  296. def Hash256(self,name): self.run_cmd_out(name,getrandstr(16))
  297. def Hexreverse(self,name): self.run_cmd_out(name,getrandhex(24))
  298. def Hexlify(self,name): self.run_cmd_out(name,getrandstr(24))
  299. def Hexdump(self,name): self.run_cmd_randinput(name,strip=False)
  300. def Unhexdump(self,name,fn1,fn2):
  301. ret = self.run_cmd(name,[fn2],strip=False)
  302. orig = read_from_file(fn1,binary=True)
  303. cmp_or_die(orig,ret)
  304. def Rand2file(self,name):
  305. of = name + '.out'
  306. dlen = 1024
  307. self.run_cmd(name,[of,str(1024),'threads=4','silent=1'],strip=False)
  308. d = read_from_tmpfile(cfg,of,binary=True)
  309. cmp_or_die(dlen,len(d))
  310. # Cryptocoin
  311. def Randwif(self,name):
  312. for n,k in enumerate(['',maybe_compressed]):
  313. ao = ['--type='+k] if k else []
  314. ret = self.run_cmd_out(name,add_opts=ao,Return=True,fn_idx=n+1)
  315. ok_or_die(ret,is_wif,'WIF key')
  316. def Randpair(self,name):
  317. for n,k in enumerate(['',maybe_compressed,maybe_segwit]):
  318. ao = ['--type='+k] if k else []
  319. wif,addr = self.run_cmd_out(name,add_opts=ao,Return=True,fn_idx=n+1).split()
  320. ok_or_die(wif,is_wif,'WIF key',skip_ok=True)
  321. ok_or_die(addr,is_coin_addr,'Coin address')
  322. def Wif2addr(self,name,f1,f2,f3):
  323. for n,f,k,m in ((1,f1,'',''),(2,f2,'',maybe_compressed),(3,f3,maybe_segwit,maybe_compressed)):
  324. ao = ['--type='+k] if k else []
  325. wif = read_from_file(f).split()[0]
  326. self.run_cmd_out(name,wif,add_opts=ao,fn_idx=n,extra_msg=m)
  327. def Wif2hex(self,name,f1,f2,f3):
  328. for n,f,m in ((1,f1,''),(2,f2,maybe_compressed),(3,f3,'{} for {}'.format(maybe_compressed,maybe_segwit))):
  329. wif = read_from_file(f).split()[0]
  330. self.run_cmd_out(name,wif,fn_idx=n,extra_msg=m)
  331. def Privhex2addr(self,name,f1,f2,f3):
  332. keys = [read_from_file(f).rstrip() for f in (f1,f2,f3)]
  333. for n,k in enumerate(('',maybe_compressed,maybe_segwit)):
  334. ao = ['--type='+k] if k else []
  335. ret = self.run_cmd(name,[keys[n]],add_opts=ao).rstrip()
  336. iaddr = read_from_tmpfile(cfg,'Randpair{}.out'.format(n+1)).split()[-1]
  337. cmp_or_die(iaddr,ret)
  338. def Hex2wif(self,name,f1,f2,f3,f4):
  339. for n,fi,fo,k in ((1,f1,f2,''),(2,f3,f4,maybe_compressed)):
  340. ao = ['--type='+k] if k else []
  341. ret = self.run_cmd_chk(name,fi,fo,add_opts=ao)
  342. def Addr2hexaddr(self,name,f1,f2):
  343. for n,f,m in ((1,f1,''),(2,f2,'from {}'.format(maybe_compressed))):
  344. addr = read_from_file(f).split()[-1]
  345. self.run_cmd_out(name,addr,fn_idx=n,extra_msg=m)
  346. def Pubhash2addr(self,name,f1,f2,f3,f4):
  347. for n,fi,fo,m in ((1,f1,f2,''),(2,f3,f4,'from {}'.format(maybe_compressed))):
  348. self.run_cmd_chk(name,fi,fo,extra_msg=m)
  349. def Privhex2pubhex(self,name,f1,f2,f3): # from Hex2wif
  350. addr = read_from_file(f3).strip()
  351. self.run_cmd_out(name,addr,add_opts=maybe_type_compressed,fn_idx=3) # what about uncompressed?
  352. def Pubhex2redeem_script(self,name,f1,f2,f3): # from above
  353. addr = read_from_file(f3).strip()
  354. self.run_cmd_out(name,addr,fn_idx=3)
  355. rs = read_from_tmpfile(cfg,name+'3.out').strip()
  356. self.run_cmd_out('pubhex2addr',rs,add_opts=maybe_type_segwit,fn_idx=3,hush=True)
  357. addr1 = read_from_tmpfile(cfg,'pubhex2addr3.out').strip()
  358. addr2 = read_from_tmpfile(cfg,'Randpair3.out').split()[1]
  359. cmp_or_die(addr1,addr2)
  360. def Wif2redeem_script(self,name,f1,f2,f3): # compare output with above
  361. wif = read_from_file(f3).split()[0]
  362. ret1 = self.run_cmd_out(name,wif,add_opts=maybe_type_segwit,fn_idx=3,Return=True)
  363. ret2 = read_from_tmpfile(cfg,'Pubhex2redeem_script3.out').strip()
  364. cmp_or_die(ret1,ret2)
  365. def Wif2segwit_pair(self,name,f1,f2): # does its own checking, so just run
  366. wif = read_from_file(f2).split()[0]
  367. self.run_cmd_out(name,wif,add_opts=maybe_type_segwit,fn_idx=2)
  368. def Pubhex2addr(self,name,f1,f2,f3):
  369. addr = read_from_file(f3).strip()
  370. self.run_cmd_out(name,addr,add_opts=maybe_type_segwit,fn_idx=3)
  371. def Pipetest(self,name,f1,f2,f3):
  372. wif = read_from_file(f3).split()[0]
  373. cmd = ( '{c} {a} wif2hex {wif} | ' +
  374. '{c} {a} --type=compressed privhex2pubhex - | ' +
  375. '{c} {a} pubhex2redeem_script - | ' +
  376. '{c} {a} --type=segwit pubhex2addr -').format(
  377. c=' '.join(spawn_cmd),
  378. a=' '.join(add_spawn_args),
  379. wif=wif)
  380. test_msg('command piping')
  381. if opt.verbose:
  382. sys.stderr.write(green('Executing ') + cyan(cmd) + '\n')
  383. p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
  384. res = p.stdout.read().strip()
  385. addr = read_from_tmpfile(cfg,'Wif2addr3.out').strip()
  386. cmp_or_die(res,addr)
  387. # Mnemonic
  388. def Hex2mn(self,name):
  389. for n,size,m in ((1,16,'128-bit'),(2,24,'192-bit'),(3,32,'256-bit')):
  390. hexnum = getrandhex(size)
  391. self.run_cmd_out(name,hexnum,fn_idx=n,extra_msg=m)
  392. def Mn2hex(self,name,f1,f2,f3,f4,f5,f6):
  393. for f_i,f_o,m in ((f1,f2,'128-bit'),(f3,f4,'192-bit'),(f5,f6,'256-bit')):
  394. self.run_cmd_chk(name,f_i,f_o,extra_msg=m,strip_hex=True)
  395. def Mn_rand128(self,name): self.run_cmd_out(name)
  396. def Mn_rand192(self,name): self.run_cmd_out(name)
  397. def Mn_rand256(self,name): self.run_cmd_out(name)
  398. def Mn_stats(self,name): self.run_cmd_out(name)
  399. def Mn_printlist(self,name):
  400. self.run_cmd(name,[])
  401. ok()
  402. # RPC
  403. def Addrfile_chksum(self,name):
  404. fn = os.path.join(cfg['refdir'],ref_subdir,cfg['addrfile'].format(altcoin_pfx,tn_ext))
  405. self.run_cmd_out(name,fn,literal=True,chkdata=cfg['addrfile_chk'][g.coin.lower()][g.testnet])
  406. def Getbalance(self,name):
  407. self.run_cmd_out(name,literal=True)
  408. def Listaddresses(self,name):
  409. self.run_cmd_out(name,literal=True)
  410. def Twview(self,name):
  411. self.run_cmd_out(name,literal=True)
  412. def Txview(self,name):
  413. fn = os.path.join(cfg['refdir'],ref_subdir,cfg['txfile'][g.coin.lower()].format(tn_ext))
  414. self.run_cmd_out(name,fn,literal=True)
  415. # main()
  416. import time
  417. start_time = int(time.time())
  418. ts = MMGenToolTestSuite()
  419. mk_tmpdir(cfg['tmpdir'])
  420. if cmd_args:
  421. if len(cmd_args) != 1:
  422. die(1,'Only one command may be specified')
  423. cmd = cmd_args[0]
  424. if cmd in cmd_data:
  425. msg('Running tests for %s:' % cmd_data[cmd]['desc'])
  426. ts.do_cmds(cmd)
  427. elif cmd == 'clean':
  428. cleandir(cfg['tmpdir'])
  429. sys.exit(0)
  430. else:
  431. die(1,"'%s': unrecognized command" % cmd)
  432. else:
  433. cleandir(cfg['tmpdir'])
  434. for cmd in cmd_data:
  435. msg('Running tests for %s:' % cmd_data[cmd]['desc'])
  436. ts.do_cmds(cmd)
  437. if cmd is not cmd_data.keys()[-1]: msg('')
  438. t = int(time.time()) - start_time
  439. msg(green(
  440. 'All requested tests finished OK, elapsed time: %02i:%02i' % (t/60,t%60)))