2015-05-01 22:04:07 +03:00
|
|
|
#!/usr/bin/env python
|
2016-02-28 16:41:43 +03:00
|
|
|
#
|
|
|
|
|
# mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
|
2017-05-31 18:16:08 +03:00
|
|
|
# Copyright (C)2013-2017 Philemon <mmgen-py@yandex.com>
|
2016-02-28 16:41:43 +03:00
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
test/tooltest.py: Tests for the 'mmgen-tool' utility
|
|
|
|
|
"""
|
2015-01-09 21:02:16 +03:00
|
|
|
|
|
|
|
|
import sys,os
|
|
|
|
|
pn = os.path.dirname(sys.argv[0])
|
|
|
|
|
os.chdir(os.path.join(pn,os.pardir))
|
|
|
|
|
sys.path.__setitem__(0,os.path.abspath(os.curdir))
|
|
|
|
|
|
2016-02-28 16:41:43 +03:00
|
|
|
# Import this _after_ local path's been added to sys.path
|
|
|
|
|
from mmgen.common import *
|
2015-01-09 21:02:16 +03:00
|
|
|
|
2016-02-28 16:41:43 +03:00
|
|
|
from collections import OrderedDict
|
2015-01-09 21:02:16 +03:00
|
|
|
cmd_data = OrderedDict([
|
|
|
|
|
('util', {
|
2016-02-28 16:41:43 +03:00
|
|
|
'desc': 'base conversion, hashing and file utilities',
|
2015-01-09 21:02:16 +03:00
|
|
|
'cmd_data': OrderedDict([
|
|
|
|
|
('strtob58', ()),
|
2016-02-28 16:41:43 +03:00
|
|
|
('b58tostr', ('strtob58','io')),
|
2015-01-09 21:02:16 +03:00
|
|
|
('hextob58', ()),
|
2016-02-28 16:41:43 +03:00
|
|
|
('b58tohex', ('hextob58','io')),
|
2015-01-09 21:02:16 +03:00
|
|
|
('b58randenc', ()),
|
|
|
|
|
('hextob32', ()),
|
2016-02-28 16:41:43 +03:00
|
|
|
('b32tohex', ('hextob32','io')),
|
2015-01-09 21:02:16 +03:00
|
|
|
('randhex', ()),
|
|
|
|
|
('id8', ()),
|
|
|
|
|
('id6', ()),
|
|
|
|
|
('str2id6', ()),
|
2016-02-28 16:41:43 +03:00
|
|
|
('sha256x2', ()),
|
|
|
|
|
('hexreverse', ()),
|
|
|
|
|
('hexlify', ()),
|
2015-01-09 21:02:16 +03:00
|
|
|
('hexdump', ()),
|
2016-02-28 16:41:43 +03:00
|
|
|
('unhexdump', ('hexdump','io')),
|
2015-01-09 21:02:16 +03:00
|
|
|
('rand2file', ()),
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
('bitcoin', {
|
2016-02-28 16:41:43 +03:00
|
|
|
'desc': 'Bitcoin address/key commands',
|
2015-01-09 21:02:16 +03:00
|
|
|
'cmd_data': OrderedDict([
|
|
|
|
|
('randwif', ()),
|
|
|
|
|
('randpair', ()),
|
2016-02-28 16:41:43 +03:00
|
|
|
('wif2addr', ('randpair','o2')),
|
|
|
|
|
('wif2hex', ('randpair','o2')),
|
|
|
|
|
('privhex2addr', ('wif2hex','o2')), # wif from randpair o2
|
|
|
|
|
('hex2wif', ('wif2hex','io2')),
|
|
|
|
|
('addr2hexaddr', ('randpair','o2')),
|
|
|
|
|
('hexaddr2addr', ('addr2hexaddr','io2')),
|
|
|
|
|
# ('pubkey2addr', ['<public key in hex format> [str]']),
|
|
|
|
|
# ('pubkey2hexaddr', ['<public key in hex format> [str]']),
|
2015-01-09 21:02:16 +03:00
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
('mnemonic', {
|
2016-02-28 16:41:43 +03:00
|
|
|
'desc': 'mnemonic commands',
|
2015-01-09 21:02:16 +03:00
|
|
|
'cmd_data': OrderedDict([
|
|
|
|
|
('hex2mn', ()),
|
2016-02-28 16:41:43 +03:00
|
|
|
('mn2hex', ('hex2mn','io3')),
|
2015-01-09 21:02:16 +03:00
|
|
|
('mn_rand128', ()),
|
|
|
|
|
('mn_rand192', ()),
|
|
|
|
|
('mn_rand256', ()),
|
|
|
|
|
('mn_stats', ()),
|
|
|
|
|
('mn_printlist', ()),
|
|
|
|
|
])
|
|
|
|
|
}
|
2016-02-28 16:41:43 +03:00
|
|
|
),
|
|
|
|
|
('rpc', {
|
|
|
|
|
'desc': 'Bitcoind RPC commands',
|
|
|
|
|
'cmd_data': OrderedDict([
|
|
|
|
|
# ('keyaddrfile_chksum', ()), # interactive
|
|
|
|
|
('addrfile_chksum', ()),
|
|
|
|
|
('getbalance', ()),
|
|
|
|
|
('listaddresses', ()),
|
2016-11-21 19:59:03 +03:00
|
|
|
('twview', ()),
|
2016-02-28 16:41:43 +03:00
|
|
|
('txview', ()),
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
),
|
2015-01-09 21:02:16 +03:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
cfg = {
|
2016-02-28 16:41:43 +03:00
|
|
|
'name': 'the tool utility',
|
|
|
|
|
'enc_passwd': 'Ten Satoshis',
|
|
|
|
|
'tmpdir': 'test/tmp10',
|
2015-01-09 21:02:16 +03:00
|
|
|
'tmpdir_num': 10,
|
2016-02-28 16:41:43 +03:00
|
|
|
'refdir': 'test/ref',
|
2016-07-04 21:47:32 +03:00
|
|
|
'txfile': 'FFB367[1.234].rawtx',
|
2016-02-28 16:41:43 +03:00
|
|
|
'addrfile': '98831F3A[1,31-33,500-501,1010-1011].addrs',
|
2016-07-26 22:16:25 +03:00
|
|
|
'addrfile_chk': '6FEF 6FB9 7B13 5D91',
|
2015-01-09 21:02:16 +03:00
|
|
|
}
|
|
|
|
|
|
2015-01-10 18:52:30 +03:00
|
|
|
opts_data = {
|
2015-01-09 21:02:16 +03:00
|
|
|
'desc': "Test suite for the 'mmgen-tool' utility",
|
2016-02-28 16:41:43 +03:00
|
|
|
'usage':'[options] [command]',
|
2015-01-09 21:02:16 +03:00
|
|
|
'options': """
|
2015-01-12 14:41:17 +03:00
|
|
|
-h, --help Print this help message
|
2016-11-17 18:10:27 +03:00
|
|
|
--, --longhelp Print help message for long options (common options)
|
2015-01-12 14:41:17 +03:00
|
|
|
-l, --list-cmds List and describe the tests and commands in the test suite
|
|
|
|
|
-s, --system Test scripts and modules installed on system rather than
|
|
|
|
|
those in the repo root
|
|
|
|
|
-v, --verbose Produce more verbose output
|
2015-01-09 21:02:16 +03:00
|
|
|
""",
|
|
|
|
|
'notes': """
|
|
|
|
|
|
|
|
|
|
If no command is given, the whole suite of tests is run.
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 19:59:03 +03:00
|
|
|
sys.argv = [sys.argv[0]] + ['--skip-cfg-file'] + sys.argv[1:]
|
|
|
|
|
|
2016-11-11 16:05:27 +03:00
|
|
|
cmd_args = opts.init(opts_data,add_opts=['exact_output','profile'])
|
2016-11-17 18:10:27 +03:00
|
|
|
add_spawn_args = ' '.join(['{} {}'.format(
|
|
|
|
|
'--'+k.replace('_','-'),
|
|
|
|
|
getattr(opt,k) if getattr(opt,k) != True else ''
|
|
|
|
|
) for k in 'testnet','rpc_host' if getattr(opt,k)]).split()
|
2016-12-08 18:02:28 +03:00
|
|
|
add_spawn_args += [ '--data-dir', cfg['tmpdir']] # ignore ~/.mmgen
|
2015-01-09 21:02:16 +03:00
|
|
|
|
2015-01-10 18:52:30 +03:00
|
|
|
if opt.system: sys.path.pop(0)
|
2015-01-09 21:02:16 +03:00
|
|
|
|
2015-01-10 18:52:30 +03:00
|
|
|
if opt.list_cmds:
|
2016-02-28 16:41:43 +03:00
|
|
|
fs = ' {:<{w}} - {}'
|
|
|
|
|
Msg('Available commands:')
|
2015-01-09 21:02:16 +03:00
|
|
|
w = max([len(i) for i in cmd_data])
|
|
|
|
|
for cmd in cmd_data:
|
|
|
|
|
Msg(fs.format(cmd,cmd_data[cmd]['desc'],w=w))
|
2016-02-28 16:41:43 +03:00
|
|
|
Msg('\nAvailable utilities:')
|
|
|
|
|
Msg(fs.format('clean','Clean the tmp directory',w=w))
|
2015-01-09 21:02:16 +03:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
import binascii
|
|
|
|
|
from mmgen.test import *
|
2017-07-07 16:09:28 +03:00
|
|
|
from mmgen.tx import is_wif,is_btc_addr
|
2015-01-09 21:02:16 +03:00
|
|
|
|
|
|
|
|
class MMGenToolTestSuite(object):
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def gen_deps_for_cmd(self,cmd,cdata):
|
|
|
|
|
fns = []
|
|
|
|
|
if cdata:
|
|
|
|
|
name,code = cdata
|
2016-02-28 16:41:43 +03:00
|
|
|
io,count = (code[:-1],int(code[-1])) if code[-1] in '0123456789' else (code,1)
|
2015-01-09 21:02:16 +03:00
|
|
|
|
|
|
|
|
for c in range(count):
|
2016-02-28 16:41:43 +03:00
|
|
|
fns += ['%s%s%s' % (
|
2015-01-09 21:02:16 +03:00
|
|
|
name,
|
2016-02-28 16:41:43 +03:00
|
|
|
('',c+1)[count > 1],
|
|
|
|
|
('.out','.in')[ch=='i']
|
2015-01-09 21:02:16 +03:00
|
|
|
) for ch in io]
|
|
|
|
|
return fns
|
|
|
|
|
|
|
|
|
|
def get_num_exts_for_cmd(self,cmd,dpy): # dpy required here
|
|
|
|
|
num = str(tool_cfgs['tmpdir_num'])
|
|
|
|
|
# return only first file - a hack
|
|
|
|
|
exts = gen_deps_for_cmd(dpy)
|
|
|
|
|
return num,exts
|
|
|
|
|
|
|
|
|
|
def do_cmds(self,cmd_group):
|
|
|
|
|
cdata = cmd_data[cmd_group]['cmd_data']
|
|
|
|
|
for cmd in cdata: self.do_cmd(cmd,cdata[cmd])
|
|
|
|
|
|
|
|
|
|
def do_cmd(self,cmd,cdata):
|
|
|
|
|
|
|
|
|
|
fns = self.gen_deps_for_cmd(cmd,cdata)
|
|
|
|
|
|
|
|
|
|
file_list = [os.path.join(cfg['tmpdir'],fn) for fn in fns]
|
|
|
|
|
|
|
|
|
|
self.__class__.__dict__[cmd](*([self,cmd] + file_list))
|
|
|
|
|
|
|
|
|
|
|
2016-02-28 16:41:43 +03:00
|
|
|
def run_cmd(self,name,tool_args,kwargs='',extra_msg='',silent=False,strip=True):
|
|
|
|
|
mmgen_tool = 'mmgen-tool'
|
2015-01-10 18:52:30 +03:00
|
|
|
if not opt.system:
|
2015-01-09 21:02:16 +03:00
|
|
|
mmgen_tool = os.path.join(os.curdir,mmgen_tool)
|
|
|
|
|
|
2016-11-17 18:10:27 +03:00
|
|
|
sys_cmd = ['python',mmgen_tool] + add_spawn_args + ['-r0','-d',cfg['tmpdir'],name] + tool_args + kwargs.split()
|
2016-02-28 16:41:43 +03:00
|
|
|
if extra_msg: extra_msg = '(%s)' % extra_msg
|
|
|
|
|
full_name = ' '.join([name]+kwargs.split()+extra_msg.split())
|
2015-01-09 21:02:16 +03:00
|
|
|
if not silent:
|
2015-01-10 18:52:30 +03:00
|
|
|
if opt.verbose:
|
2016-02-28 16:41:43 +03:00
|
|
|
sys.stderr.write(green('Testing %s\nExecuting ' % full_name))
|
|
|
|
|
sys.stderr.write('%s\n' % cyan(repr(sys_cmd)))
|
2015-01-09 21:02:16 +03:00
|
|
|
else:
|
2016-02-28 16:41:43 +03:00
|
|
|
msg_r('Testing %-31s%s' % (full_name+':',''))
|
2015-01-09 21:02:16 +03:00
|
|
|
|
|
|
|
|
import subprocess
|
2016-02-28 16:41:43 +03:00
|
|
|
p = subprocess.Popen(
|
|
|
|
|
sys_cmd,
|
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
|
)
|
|
|
|
|
a,b = p.communicate()
|
|
|
|
|
retcode = p.wait()
|
|
|
|
|
if retcode != 0:
|
|
|
|
|
msg('%s\n%s\n%s'%(red('FAILED'),yellow('Command stderr output:'),b))
|
|
|
|
|
die(1,red('Called process returned with an error (retcode %s)' % retcode))
|
|
|
|
|
return (a,a.rstrip())[bool(strip)]
|
|
|
|
|
|
|
|
|
|
def run_cmd_chk(self,name,f1,f2,kwargs='',extra_msg=''):
|
2015-05-02 14:51:04 +03:00
|
|
|
idata = read_from_file(f1).rstrip()
|
|
|
|
|
odata = read_from_file(f2).rstrip()
|
|
|
|
|
ret = self.run_cmd(name,[odata],kwargs=kwargs,extra_msg=extra_msg)
|
2016-02-28 16:41:43 +03:00
|
|
|
vmsg('In: ' + repr(odata))
|
|
|
|
|
vmsg('Out: ' + repr(ret))
|
2015-01-09 21:02:16 +03:00
|
|
|
if ret == idata: ok()
|
|
|
|
|
else:
|
2016-02-28 16:41:43 +03:00
|
|
|
die(3,red(
|
2015-01-09 21:02:16 +03:00
|
|
|
"Error: values don't match:\nIn: %s\nOut: %s" % (repr(idata),repr(ret))))
|
|
|
|
|
return ret
|
|
|
|
|
|
2016-02-28 16:41:43 +03:00
|
|
|
def run_cmd_nochk(self,name,f1,kwargs=''):
|
2015-05-02 14:51:04 +03:00
|
|
|
odata = read_from_file(f1).rstrip()
|
|
|
|
|
ret = self.run_cmd(name,[odata],kwargs=kwargs)
|
2016-02-28 16:41:43 +03:00
|
|
|
vmsg('In: ' + repr(odata))
|
|
|
|
|
vmsg('Out: ' + repr(ret))
|
2015-01-09 21:02:16 +03:00
|
|
|
return ret
|
|
|
|
|
|
2016-02-28 16:41:43 +03:00
|
|
|
def run_cmd_out(self,name,carg=None,Return=False,kwargs='',fn_idx='',extra_msg='',literal=False,chkdata=''):
|
|
|
|
|
if carg: write_to_tmpfile(cfg,'%s%s.in' % (name,fn_idx),carg+'\n')
|
|
|
|
|
ret = self.run_cmd(name,([],[carg])[bool(carg)],kwargs=kwargs,extra_msg=extra_msg)
|
|
|
|
|
if carg: vmsg('In: ' + repr(carg))
|
|
|
|
|
vmsg('Out: ' + (repr(ret),ret)[literal])
|
2016-06-25 18:27:45 +03:00
|
|
|
if ret or ret == '':
|
2016-02-28 16:41:43 +03:00
|
|
|
write_to_tmpfile(cfg,'%s%s.out' % (name,fn_idx),ret+'\n')
|
|
|
|
|
if chkdata:
|
|
|
|
|
cmp_or_die(ret,chkdata)
|
|
|
|
|
return
|
2015-01-09 21:02:16 +03:00
|
|
|
if Return: return ret
|
|
|
|
|
else: ok()
|
|
|
|
|
else:
|
2016-02-28 16:41:43 +03:00
|
|
|
die(3,red("Error for command '%s'" % name))
|
2015-01-09 21:02:16 +03:00
|
|
|
|
2015-05-02 14:51:04 +03:00
|
|
|
def run_cmd_randinput(self,name,strip=True):
|
2015-01-09 21:02:16 +03:00
|
|
|
s = os.urandom(128)
|
2016-02-28 16:41:43 +03:00
|
|
|
fn = name+'.in'
|
2015-10-25 13:04:30 +03:00
|
|
|
write_to_tmpfile(cfg,fn,s,binary=True)
|
2015-05-02 14:51:04 +03:00
|
|
|
ret = self.run_cmd(name,[get_tmpfile_fn(cfg,fn)],strip=strip)
|
2016-02-28 16:41:43 +03:00
|
|
|
fn = name+'.out'
|
|
|
|
|
write_to_tmpfile(cfg,fn,ret+'\n')
|
2015-01-09 21:02:16 +03:00
|
|
|
ok()
|
2016-02-28 16:41:43 +03:00
|
|
|
vmsg('Returned: %s' % ret)
|
2015-01-09 21:02:16 +03:00
|
|
|
|
|
|
|
|
def str2id6(self,name):
|
|
|
|
|
s = getrandstr(120,no_space=True)
|
2016-02-28 16:41:43 +03:00
|
|
|
s2 = ' %s %s %s %s %s ' % (s[:3],s[3:9],s[9:29],s[29:50],s[50:120])
|
|
|
|
|
ret1 = self.run_cmd(name,[s],extra_msg='unspaced input'); ok()
|
|
|
|
|
ret2 = self.run_cmd(name,[s2],extra_msg='spaced input')
|
2015-01-09 21:02:16 +03:00
|
|
|
cmp_or_die(ret1,ret2)
|
2016-02-28 16:41:43 +03:00
|
|
|
vmsg('Returned: %s' % ret1)
|
2015-01-09 21:02:16 +03:00
|
|
|
|
|
|
|
|
def mn_rand128(self,name):
|
|
|
|
|
self.run_cmd_out(name)
|
|
|
|
|
|
|
|
|
|
def mn_rand192(self,name):
|
|
|
|
|
self.run_cmd_out(name)
|
|
|
|
|
|
|
|
|
|
def mn_rand256(self,name):
|
|
|
|
|
self.run_cmd_out(name)
|
|
|
|
|
|
|
|
|
|
def mn_stats(self,name):
|
|
|
|
|
self.run_cmd_out(name)
|
|
|
|
|
|
|
|
|
|
def mn_printlist(self,name):
|
|
|
|
|
self.run_cmd(name,[])
|
|
|
|
|
ok()
|
|
|
|
|
|
2015-05-02 14:51:04 +03:00
|
|
|
def id6(self,name): self.run_cmd_randinput(name)
|
|
|
|
|
def id8(self,name): self.run_cmd_randinput(name)
|
|
|
|
|
def hexdump(self,name): self.run_cmd_randinput(name,strip=False)
|
2015-01-09 21:02:16 +03:00
|
|
|
|
|
|
|
|
def unhexdump(self,name,fn1,fn2):
|
2015-05-02 14:51:04 +03:00
|
|
|
ret = self.run_cmd(name,[fn2],strip=False)
|
2015-10-25 13:04:30 +03:00
|
|
|
orig = read_from_file(fn1,binary=True)
|
2015-01-09 21:02:16 +03:00
|
|
|
cmp_or_die(orig,ret)
|
|
|
|
|
|
|
|
|
|
def rand2file(self,name):
|
2016-02-28 16:41:43 +03:00
|
|
|
of = name + '.out'
|
2015-01-09 21:02:16 +03:00
|
|
|
dlen = 1024
|
2016-02-28 16:41:43 +03:00
|
|
|
self.run_cmd(name,[of,str(1024),'threads=4','silent=1'],strip=False)
|
2015-10-25 13:04:30 +03:00
|
|
|
d = read_from_tmpfile(cfg,of,binary=True)
|
2015-01-09 21:02:16 +03:00
|
|
|
cmp_or_die(dlen,len(d))
|
|
|
|
|
|
|
|
|
|
def strtob58(self,name): self.run_cmd_out(name,getrandstr(16))
|
|
|
|
|
def sha256x2(self,name): self.run_cmd_out(name,getrandstr(16))
|
|
|
|
|
def hexreverse(self,name): self.run_cmd_out(name,getrandhex(24))
|
|
|
|
|
def hexlify(self,name): self.run_cmd_out(name,getrandstr(24))
|
|
|
|
|
def b58tostr(self,name,f1,f2): self.run_cmd_chk(name,f1,f2)
|
|
|
|
|
def hextob58(self,name): self.run_cmd_out(name,getrandhex(32))
|
|
|
|
|
def b58tohex(self,name,f1,f2): self.run_cmd_chk(name,f1,f2)
|
|
|
|
|
def hextob32(self,name): self.run_cmd_out(name,getrandhex(24))
|
|
|
|
|
def b32tohex(self,name,f1,f2): self.run_cmd_chk(name,f1,f2)
|
|
|
|
|
def b58randenc(self,name):
|
|
|
|
|
ret = self.run_cmd_out(name,Return=True)
|
2016-02-28 16:41:43 +03:00
|
|
|
ok_or_die(ret,is_b58_str,'base 58 string')
|
2015-01-09 21:02:16 +03:00
|
|
|
def randhex(self,name):
|
|
|
|
|
ret = self.run_cmd_out(name,Return=True)
|
2016-02-28 16:41:43 +03:00
|
|
|
ok_or_die(ret,binascii.unhexlify,'hex string')
|
2015-01-09 21:02:16 +03:00
|
|
|
def randwif(self,name):
|
2016-02-28 16:41:43 +03:00
|
|
|
for n,k in enumerate(['','compressed=1']):
|
2015-01-09 21:02:16 +03:00
|
|
|
ret = self.run_cmd_out(name,kwargs=k,Return=True,fn_idx=n+1)
|
2016-02-28 16:41:43 +03:00
|
|
|
ok_or_die(ret,is_wif,'WIF key')
|
2015-01-09 21:02:16 +03:00
|
|
|
def randpair(self,name):
|
2016-02-28 16:41:43 +03:00
|
|
|
for n,k in enumerate(['','compressed=1']):
|
2015-01-09 21:02:16 +03:00
|
|
|
wif,addr = self.run_cmd_out(name,kwargs=k,Return=True,fn_idx=n+1).split()
|
2016-02-28 16:41:43 +03:00
|
|
|
ok_or_die(wif,is_wif,'WIF key',skip_ok=True)
|
|
|
|
|
ok_or_die(addr,is_btc_addr,'Bitcoin address')
|
2015-01-09 21:02:16 +03:00
|
|
|
def hex2wif(self,name,f1,f2,f3,f4):
|
2016-02-28 16:41:43 +03:00
|
|
|
for n,fi,fo,k in (1,f1,f2,''),(2,f3,f4,'compressed=1'):
|
2015-01-09 21:02:16 +03:00
|
|
|
ret = self.run_cmd_chk(name,fi,fo,kwargs=k)
|
|
|
|
|
def wif2hex(self,name,f1,f2):
|
2016-02-28 16:41:43 +03:00
|
|
|
for n,f,k in (1,f1,''),(2,f2,'compressed=1'):
|
2015-01-09 21:02:16 +03:00
|
|
|
wif = read_from_file(f).split()[0]
|
|
|
|
|
self.run_cmd_out(name,wif,kwargs=k,fn_idx=n)
|
|
|
|
|
def wif2addr(self,name,f1,f2):
|
2016-02-28 16:41:43 +03:00
|
|
|
for n,f,k in (1,f1,''),(2,f2,'compressed=1'):
|
2015-01-09 21:02:16 +03:00
|
|
|
wif = read_from_file(f).split()[0]
|
|
|
|
|
self.run_cmd_out(name,wif,kwargs=k,fn_idx=n)
|
|
|
|
|
def addr2hexaddr(self,name,f1,f2):
|
2016-02-28 16:41:43 +03:00
|
|
|
for n,f,m in (1,f1,''),(2,f2,'from compressed'):
|
2015-01-09 21:02:16 +03:00
|
|
|
addr = read_from_file(f).split()[-1]
|
|
|
|
|
self.run_cmd_out(name,addr,fn_idx=n,extra_msg=m)
|
|
|
|
|
def hexaddr2addr(self,name,f1,f2,f3,f4):
|
2016-02-28 16:41:43 +03:00
|
|
|
for n,fi,fo,m in (1,f1,f2,''),(2,f3,f4,'from compressed'):
|
2015-01-09 21:02:16 +03:00
|
|
|
self.run_cmd_chk(name,fi,fo,extra_msg=m)
|
|
|
|
|
def privhex2addr(self,name,f1,f2):
|
2015-10-25 13:04:30 +03:00
|
|
|
key1 = read_from_file(f1).rstrip()
|
|
|
|
|
key2 = read_from_file(f2).rstrip()
|
2016-02-28 16:41:43 +03:00
|
|
|
for n,args in enumerate([[key1],[key2,'compressed=1']]):
|
2015-01-09 21:02:16 +03:00
|
|
|
ret = self.run_cmd(name,args).rstrip()
|
2016-02-28 16:41:43 +03:00
|
|
|
iaddr = read_from_tmpfile(cfg,'randpair%s.out' % (n+1)).split()[-1]
|
2015-01-09 21:02:16 +03:00
|
|
|
cmp_or_die(iaddr,ret)
|
|
|
|
|
def hex2mn(self,name):
|
2016-02-28 16:41:43 +03:00
|
|
|
for n,size,m in(1,16,'128-bit'),(2,24,'192-bit'),(3,32,'256-bit'):
|
2015-01-09 21:02:16 +03:00
|
|
|
hexnum = getrandhex(size)
|
|
|
|
|
self.run_cmd_out(name,hexnum,fn_idx=n,extra_msg=m)
|
|
|
|
|
def mn2hex(self,name,f1,f2,f3,f4,f5,f6):
|
2016-02-28 16:41:43 +03:00
|
|
|
for f_i,f_o,m in (f1,f2,'128-bit'),(f3,f4,'192-bit'),(f5,f6,'256-bit'):
|
2015-01-09 21:02:16 +03:00
|
|
|
self.run_cmd_chk(name,f_i,f_o,extra_msg=m)
|
|
|
|
|
|
2016-02-28 16:41:43 +03:00
|
|
|
def getbalance(self,name):
|
|
|
|
|
self.run_cmd_out(name,literal=True)
|
|
|
|
|
def listaddresses(self,name):
|
|
|
|
|
self.run_cmd_out(name,literal=True)
|
2016-11-21 19:59:03 +03:00
|
|
|
def twview(self,name):
|
|
|
|
|
self.run_cmd_out(name,literal=True)
|
2016-02-28 16:41:43 +03:00
|
|
|
def txview(self,name):
|
|
|
|
|
fn = os.path.join(cfg['refdir'],cfg['txfile'])
|
|
|
|
|
self.run_cmd_out(name,fn,literal=True)
|
|
|
|
|
def addrfile_chksum(self,name):
|
|
|
|
|
fn = os.path.join(cfg['refdir'],cfg['addrfile'])
|
|
|
|
|
self.run_cmd_out(name,fn,literal=True,chkdata=cfg['addrfile_chk'])
|
|
|
|
|
|
2015-01-09 21:02:16 +03:00
|
|
|
# main()
|
|
|
|
|
import time
|
|
|
|
|
start_time = int(time.time())
|
|
|
|
|
ts = MMGenToolTestSuite()
|
2016-11-21 19:59:03 +03:00
|
|
|
mk_tmpdir(cfg['tmpdir'])
|
2015-01-09 21:02:16 +03:00
|
|
|
|
|
|
|
|
if cmd_args:
|
|
|
|
|
if len(cmd_args) != 1:
|
2016-02-28 16:41:43 +03:00
|
|
|
die(1,'Only one command may be specified')
|
2015-01-09 21:02:16 +03:00
|
|
|
|
|
|
|
|
cmd = cmd_args[0]
|
|
|
|
|
if cmd in cmd_data:
|
2016-02-28 16:41:43 +03:00
|
|
|
msg('Running tests for %s:' % cmd_data[cmd]['desc'])
|
2015-01-09 21:02:16 +03:00
|
|
|
ts.do_cmds(cmd)
|
2016-02-28 16:41:43 +03:00
|
|
|
elif cmd == 'clean':
|
2015-01-09 21:02:16 +03:00
|
|
|
cleandir(cfg['tmpdir'])
|
2016-02-28 16:41:43 +03:00
|
|
|
sys.exit()
|
2015-01-09 21:02:16 +03:00
|
|
|
else:
|
2016-02-28 16:41:43 +03:00
|
|
|
die(1,"'%s': unrecognized command" % cmd)
|
2015-01-09 21:02:16 +03:00
|
|
|
else:
|
|
|
|
|
cleandir(cfg['tmpdir'])
|
|
|
|
|
for cmd in cmd_data:
|
2016-02-28 16:41:43 +03:00
|
|
|
msg('Running tests for %s:' % cmd_data[cmd]['desc'])
|
2015-01-09 21:02:16 +03:00
|
|
|
ts.do_cmds(cmd)
|
2016-02-28 16:41:43 +03:00
|
|
|
if cmd is not cmd_data.keys()[-1]: msg('')
|
2015-01-09 21:02:16 +03:00
|
|
|
|
|
|
|
|
t = int(time.time()) - start_time
|
|
|
|
|
msg(green(
|
2016-02-28 16:41:43 +03:00
|
|
|
'All requested tests finished OK, elapsed time: %02i:%02i' % (t/60,t%60)))
|