From 365e31adb28928c1844d502af0db8ae69e1e78c9 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 29 Jul 2022 16:45:30 +0000 Subject: [PATCH] minor changes and fixes --- mmgen/msg.py | 15 ++++----- test/test.py | 62 ++++++++++++++++++++++-------------- test/test_py_d/ts_regtest.py | 1 + test/test_py_d/ts_shared.py | 1 + 4 files changed, 47 insertions(+), 32 deletions(-) diff --git a/mmgen/msg.py b/mmgen/msg.py index 546c32e7..30cc7415 100755 --- a/mmgen/msg.py +++ b/mmgen/msg.py @@ -146,11 +146,11 @@ class coin_msg: def gen_entry(e): for k in labels: if e.get(k): - yield fs2.format( labels[k], e[k] ) + yield fs_sig.format( labels[k], e[k] ) def gen_all(): for k,v in hdr_data.items(): - yield fs1.format( v[0], v[1](self.data[k]) ) + yield fs_hdr.format( v[0], v[1](self.data[k]) ) if self.sigs: yield '' yield 'Signatures:' @@ -162,7 +162,7 @@ class coin_msg: def gen_single(): for k,v in hdr_data.items(): - yield fs1.format( v[0], v[1](self.data[k]) ) + yield fs_hdr.format( v[0], v[1](self.data[k]) ) if self.sigs: yield 'Signature data:' k = ( @@ -190,17 +190,16 @@ class coin_msg: if req_addr or not self.data.get('failed_sids'): del hdr_data['failed_sids'] - fs1 = '{:%s} {}' % max(len(v[0]) for v in hdr_data.values()) - fs2 = '{:%s} %s{}' % ( + fs_hdr = '{:%s} {}' % max(len(v[0]) for v in hdr_data.values()) + fs_sig = '%s{:%s} %s{}' % ( + ' ' * (2 if req_addr else 5), max(len(labels[k]) for v in self.sigs.values() for k in v.keys()), self.msg_cls.sigdata_pfx or '' - ) + ) if self.sigs else None if req_addr: - fs2 = ' ' * 2 + fs2 return '\n'.join(gen_single()) else: - fs2 = ' ' * 5 + fs2 return ( '{}SIGNED MESSAGE DATA:\n\n '.format('' if self.sigs else 'UN') + '\n '.join(gen_all()) ) diff --git a/test/test.py b/test/test.py index d1d316b5..1f84a24d 100755 --- a/test/test.py +++ b/test/test.py @@ -113,7 +113,7 @@ opts_data = { debugging only) -e, --exact-output Show the exact output of the MMGen script(s) being run -G, --exclude-groups=G Exclude the specified command groups (comma-separated) --l, --list-cmds List and describe the commands in the test suite +-l, --list-cmds List the test script’s available commands -L, --list-cmd-groups Output a list of command groups with descriptions -g, --list-current-cmd-groups List command groups for current configuration -n, --names Display command names instead of descriptions @@ -133,14 +133,16 @@ opts_data = { -u, --usr-random Get random data interactively from user -T, --pexpect-timeout=T Set the timeout for pexpect -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' -y, --segwit Generate and use Segwit addresses -Y, --segwit-random Generate and use a random mix of Segwit and Legacy addrs """, 'notes': """ -If no command is given, the whole test suite is run. +If no command is given, the whole test suite is run for the currently +specified coin (default BTC). """ }, 'code': { @@ -217,28 +219,37 @@ utils = { } def list_cmds(): - gm = CmdGroupMgr() - cw,d = 0,[] - Msg(green('AVAILABLE COMMANDS:')) - for gname in gm.cmd_groups: - ts = gm.gm_init_group(None,gname,None) - desc = ts.__doc__.strip() if ts.__doc__ else type(ts).__name__ - d.append( (gname,desc,gm.cmd_list,gm.dpy_data) ) - cw = max(max(len(k) for k in gm.dpy_data),cw) - for gname,gdesc,clist,dpdata in d: - Msg('\n'+green(f'{gname!r} - {gdesc}:')) - for cmd in clist: - data = dpdata[cmd] - Msg(' {:{w}} - {}'.format( - cmd, - (data if type(data) == str else data[1]), - w = cw )) + def gen_output(): - w = max(map(len,utils)) - Msg('\n'+green('AVAILABLE UTILITIES:')) - for cmd in sorted(utils): - Msg(' {:{w}} - {}'.format( cmd, utils[cmd], w=w )) + gm = CmdGroupMgr() + cw,d = 0,[] + + yield green('AVAILABLE COMMANDS:') + + for gname in gm.cmd_groups: + ts = gm.gm_init_group(None,gname,None,None) + desc = ts.__doc__.strip() if ts.__doc__ else type(ts).__name__ + d.append( (gname,desc,gm.cmd_list,gm.dpy_data) ) + cw = max(max(len(k) for k in gm.dpy_data),cw) + + for gname,gdesc,clist,dpdata in d: + yield '\n'+green(f'{gname!r} - {gdesc}:') + for cmd in clist: + data = dpdata[cmd] + yield ' {:{w}} - {}'.format( + cmd, + (data if type(data) == str else data[1]), + w = cw ) + + w = max(map(len,utils)) + + yield '\n'+green('AVAILABLE UTILITIES:') + + for cmd in sorted(utils): + yield ' {:{w}} - {}'.format( cmd, utils[cmd], w=w ) + + do_pager('\n'.join(gen_output())) sys.exit(0) @@ -426,10 +437,13 @@ class CmdGroupMgr(object): for gname in groups: clsname,kwargs = self.cmd_groups[gname] cls = self.load_mod(gname,kwargs['modname'] if 'modname' in kwargs else None) + if cmd in cls.cmd_group: # first search the class return gname + if cmd in dir(cls(None,None,None)): # then a throwaway instance return gname # cmd might exist in more than one group - we'll go with the first + return None class TestSuiteRunner(object): @@ -527,10 +541,10 @@ class TestSuiteRunner(object): os.environ['MMGEN_FORCE_COLOR'] = '1' if self.ts.color else '' env = { 'EXEC_WRAPPER_SPAWN':'1' } + env.update(os.environ) if 'exec_wrapper_init' in globals(): # test.py itself is running under exec_wrapper, so disable traceback file writing for spawned script env.update({ 'EXEC_WRAPPER_NO_TRACEBACK':'1' }) # Python 3.9: OR the dicts - env.update(os.environ) from test.include.pexpect import MMGenPexpect return MMGenPexpect( args, no_output=no_output, env=env ) diff --git a/test/test_py_d/ts_regtest.py b/test/test_py_d/ts_regtest.py index b3a1b69d..08e1e3e3 100755 --- a/test/test_py_d/ts_regtest.py +++ b/test/test_py_d/ts_regtest.py @@ -1284,6 +1284,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared): def bob_msgverify_raw(self): t = self.bob_msgverify(ext='rawmsg.json') + t.expect('No signatures') t.req_exit_val = 1 return t diff --git a/test/test_py_d/ts_shared.py b/test/test_py_d/ts_shared.py index 6da24cbc..b65a19f2 100755 --- a/test/test_py_d/ts_shared.py +++ b/test/test_py_d/ts_shared.py @@ -176,6 +176,7 @@ class TestSuiteShared(object): else: t.do_comment(False,has_label=has_label) t.expect('Save signed transaction? (Y/n): ','n') + t.expect('not saved') t.req_exit_val = 1 return t