Browse Source

Minor changes, bugfixes

MMGen 7 years ago
parent
commit
3deb346133
5 changed files with 37 additions and 15 deletions
  1. 1 1
      mmgen/addr.py
  2. 3 3
      mmgen/obj.py
  3. 6 2
      mmgen/tx.py
  4. 1 1
      test/mmgen_pexpect.py
  5. 26 8
      test/test.py

+ 1 - 1
mmgen/addr.py

@@ -568,7 +568,7 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
 		dmsg_sc('lbl',lbl[9:])
 		dmsg_sc('lbl',lbl[9:])
 		out.append(u'{} {{'.format(lbl))
 		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:
 		for e in self.data:
 			c = ' '+e.label if enable_comments and e.label else ''
 			c = ' '+e.label if enable_comments and e.label else ''
 			if type(self) == KeyList:
 			if type(self) == KeyList:

+ 3 - 3
mmgen/obj.py

@@ -129,7 +129,7 @@ class Hilite(object):
 
 
 	@classmethod
 	@classmethod
 	def fmtc(cls,s,width=None,color=False,encl='',trunc_ok=None,
 	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 width == None: width = cls.width
 		if trunc_ok == None: trunc_ok = cls.trunc_ok
 		if trunc_ok == None: trunc_ok = cls.trunc_ok
 		assert width > 0,'Width must be > 0'
 		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)'
 		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 ('','')
 		a,b = list(encl) if encl else ('','')
 		if trunc_ok and len(s) > width: s = s[:width]
 		if trunc_ok and len(s) > width: s = s[:width]
-		if app:
+		if append_chars:
 			return cls.colorize(a+s+b,color=color) + \
 			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:
 		else:
 			return cls.colorize((a+s+b).ljust(width),color=color)
 			return cls.colorize((a+s+b).ljust(width),color=color)
 
 

+ 6 - 2
mmgen/tx.py

@@ -932,8 +932,12 @@ class MMGenTX(MMGenObject):
 					confs = e.confs + blockcount - self.blockcount
 					confs = e.confs + blockcount - self.blockcount
 					days = int(confs / confs_per_day)
 					days = int(confs / confs_per_day)
 				if e.mmid:
 				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:
 				else:
 					mmid_fmt = MMGenID.fmtc(nonmm_str,width=max_mmwid)
 					mmid_fmt = MMGenID.fmtc(nonmm_str,width=max_mmwid)
 				if terse:
 				if terse:

+ 1 - 1
test/mmgen_pexpect.py

@@ -239,7 +239,7 @@ class MMGenPexpect(object):
 	def tx_view(self,view=None):
 	def tx_view(self,view=None):
 		repl = { 'terse':'t', 'full':'v' }[view] if view else 'n'
 		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)
 		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')
 			my_expect(self.p,r'any key to continue: ','\n')
 
 
 	def expect_getend(self,s,regex=False):
 	def expect_getend(self,s,regex=False):

+ 26 - 8
test/test.py

@@ -140,6 +140,7 @@ opts_data = lambda: {
 -t, --traceback     Run the command inside the '{tbc}' script
 -t, --traceback     Run the command inside the '{tbc}' script
 -v, --verbose       Produce more verbose output
 -v, --verbose       Produce more verbose output
 -W, --no-dw-delete  Don't remove default wallet from data dir after dw tests are done
 -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),
 """.format(tbc=g.traceback_cmd,lf=log_file),
 	'notes': """
 	'notes': """
 
 
@@ -1135,7 +1136,16 @@ labels = [
 	"Job 2",
 	"Job 2",
 	"Carl's capital",
 	"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):
 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():
 	for d in tx_data.values():
 		al = adata.addrlist(d['al_id'])
 		al = adata.addrlist(d['al_id'])
 		for n,(idx,coinaddr) in enumerate(al.addrpairs()):
 		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']))
 			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
 			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']))
 				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]
 	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()
 	silence()
 	gmsg(u"Adding comments to address file '{}'".format(addrfile))
 	gmsg(u"Adding comments to address file '{}'".format(addrfile))
 	a = AddrList(addrfile)
 	a = AddrList(addrfile)
 	for n,idx in enumerate(a.idxs(),1):
 	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)
 	a.format(enable_comments=True)
 	write_data_to_file(outfile,a.fmt_data,silent=True)
 	write_data_to_file(outfile,a.fmt_data,silent=True)
 	end_silence()
 	end_silence()
@@ -1404,6 +1414,9 @@ class MMGenTestSuite(object):
 		global cmd_total
 		global cmd_total
 		cmd_total += 1
 		cmd_total += 1
 
 
+		if cmd == opt.exit_after:
+			sys.exit(0)
+
 	def generate_file_deps(self,cmd):
 	def generate_file_deps(self,cmd):
 		return [(str(n),e) for exts,n in cmd_data[cmd][2] for e in exts]
 		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='')
 		self.addrgen(name,wf,pf='')
 
 
 	def txcreate4(self,name,f1,f2,f3,f4,f5,f6):
 	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):
 	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)
 		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),
 			fn = os.path.join(self.regtest_user_dir(user),
 				u'{}{}{}[{}]{x}.addrs'.format(sid,altcoin_pfx,id_strs[desc],addr_range,
 				u'{}{}{}[{}]{x}.addrs'.format(sid,altcoin_pfx,id_strs[desc],addr_range,
 												x=u'-α' if g.debug_utf8 else ''))
 												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+')')
 			t = MMGenExpect(name,'mmgen-addrimport', ['--quiet','--'+user,'--batch',fn],extra_desc='('+desc+')')
 			if g.debug:
 			if g.debug:
 				t.expect("Type uppercase 'YES' to confirm: ",'YES\n')
 				t.expect("Type uppercase 'YES' to confirm: ",'YES\n')