Minor changes, bugfixes

This commit is contained in:
The MMGen Project 2018-04-27 07:37:36 +00:00
commit 3deb346133
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 37 additions and 15 deletions

View file

@ -568,7 +568,7 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
dmsg_sc('lbl',lbl[9:])
out.append(u'{} {{'.format(lbl))
fs = ' {:<%s} {:<34}{}' % len(str(self.data[-1].idx))
fs = u' {:<%s} {:<34}{}' % len(str(self.data[-1].idx))
for e in self.data:
c = ' '+e.label if enable_comments and e.label else ''
if type(self) == KeyList:

View file

@ -129,7 +129,7 @@ class Hilite(object):
@classmethod
def fmtc(cls,s,width=None,color=False,encl='',trunc_ok=None,
center=False,nullrepl='',app='',appcolor=False):
center=False,nullrepl='',append_chars='',append_color=False):
if width == None: width = cls.width
if trunc_ok == None: trunc_ok = cls.trunc_ok
assert width > 0,'Width must be > 0'
@ -139,9 +139,9 @@ class Hilite(object):
assert type(encl) is str and len(encl) in (0,2),'type(encl) must be str and len(encl) be in (0,2)'
a,b = list(encl) if encl else ('','')
if trunc_ok and len(s) > width: s = s[:width]
if app:
if append_chars:
return cls.colorize(a+s+b,color=color) + \
cls.colorize(app.ljust(width-len(a+s+b)),color=appcolor)
cls.colorize(append_chars.ljust(width-len(a+s+b)),color=append_color)
else:
return cls.colorize((a+s+b).ljust(width),color=color)

View file

@ -932,8 +932,12 @@ class MMGenTX(MMGenObject):
confs = e.confs + blockcount - self.blockcount
days = int(confs / confs_per_day)
if e.mmid:
app=('',' (chg)')[bool(not ip and e.is_chg and terse)]
mmid_fmt = e.mmid.fmt(width=max_mmwid,encl='()',color=True,app=app,appcolor='green')
mmid_fmt = e.mmid.fmt(
width=max_mmwid,
encl='()',
color=True,
append_chars=('',' (chg)')[bool(not ip and e.is_chg and terse)],
append_color='green')
else:
mmid_fmt = MMGenID.fmtc(nonmm_str,width=max_mmwid)
if terse:

View file

@ -239,7 +239,7 @@ class MMGenPexpect(object):
def tx_view(self,view=None):
repl = { 'terse':'t', 'full':'v' }[view] if view else 'n'
my_expect(self.p,r'View .*?transaction.*? \(y\)es, \(N\)o, pager \(v\)iew.*?: ',repl,regex=True)
if repl in ('t','v'):
if repl == 't':
my_expect(self.p,r'any key to continue: ','\n')
def expect_getend(self,s,regex=False):

View file

@ -140,6 +140,7 @@ opts_data = lambda: {
-t, --traceback Run the command inside the '{tbc}' script
-v, --verbose Produce more verbose output
-W, --no-dw-delete Don't remove default wallet from data dir after dw tests are done
-X, --exit-after=C Exit after command 'C'
""".format(tbc=g.traceback_cmd,lf=log_file),
'notes': """
@ -1135,7 +1136,16 @@ labels = [
"Job 2",
"Carl's capital",
]
label_iter = None
def get_label(do_shuffle=False):
from random import shuffle
global label_iter
try:
return next(label_iter)
except:
if do_shuffle: shuffle(labels)
label_iter = iter(labels)
return next(label_iter)
def create_fake_unspent_data(adata,tx_data,non_mmgen_input='',non_mmgen_input_compressed=True):
@ -1143,10 +1153,7 @@ def create_fake_unspent_data(adata,tx_data,non_mmgen_input='',non_mmgen_input_co
for d in tx_data.values():
al = adata.addrlist(d['al_id'])
for n,(idx,coinaddr) in enumerate(al.addrpairs()):
while True:
try: lbl = next(label_iter)
except: label_iter = iter(labels)
else: break
lbl = get_label(do_shuffle=True)
out.append(create_fake_unspent_entry(coinaddr,d['al_id'],idx,lbl,segwit=d['segwit']))
if n == 0: # create a duplicate address. This means addrs_per_wallet += 1
out.append(create_fake_unspent_entry(coinaddr,d['al_id'],idx,lbl,segwit=d['segwit']))
@ -1215,12 +1222,15 @@ def make_txcreate_cmdline(tx_data):
return cmd_args + [tx_data[num]['addrfile'] for num in tx_data]
def add_comments_to_addr_file(addrfile,outfile):
def add_comments_to_addr_file(addrfile,outfile,use_labels=False):
silence()
gmsg(u"Adding comments to address file '{}'".format(addrfile))
a = AddrList(addrfile)
for n,idx in enumerate(a.idxs(),1):
if n % 2: a.set_comment(idx,'Test address {}'.format(n))
if use_labels:
a.set_comment(idx,get_label())
else:
if n % 2: a.set_comment(idx,'Test address {}'.format(n))
a.format(enable_comments=True)
write_data_to_file(outfile,a.fmt_data,silent=True)
end_silence()
@ -1404,6 +1414,9 @@ class MMGenTestSuite(object):
global cmd_total
cmd_total += 1
if cmd == opt.exit_after:
sys.exit(0)
def generate_file_deps(self,cmd):
return [(str(n),e) for exts,n in cmd_data[cmd][2] for e in exts]
@ -1944,7 +1957,7 @@ class MMGenTestSuite(object):
self.addrgen(name,wf,pf='')
def txcreate4(self,name,f1,f2,f3,f4,f5,f6):
self.txcreate_common(name,sources=['1','2','3','4','14'],non_mmgen_input='4',do_label=1)
self.txcreate_common(name,sources=['1','2','3','4','14'],non_mmgen_input='4',do_label=1,view='full')
def txdo4(self,name,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12):
non_mm_fn = os.path.join(cfg['tmpdir'],non_mmgen_fn)
@ -2418,6 +2431,11 @@ class MMGenTestSuite(object):
fn = os.path.join(self.regtest_user_dir(user),
u'{}{}{}[{}]{x}.addrs'.format(sid,altcoin_pfx,id_strs[desc],addr_range,
x=u'' if g.debug_utf8 else ''))
if mmtype == g.proto.mmtypes[0] and user == 'bob':
psave = g.proto
g.proto = CoinProtocol(g.coin,True)
add_comments_to_addr_file(fn,fn,use_labels=True)
g.proto = psave
t = MMGenExpect(name,'mmgen-addrimport', ['--quiet','--'+user,'--batch',fn],extra_desc='('+desc+')')
if g.debug:
t.expect("Type uppercase 'YES' to confirm: ",'YES\n')