tooltest.py 17 KB

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