From 1f3c0481721939c2b9352ce2b113b613e84b6cc8 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 15 Nov 2019 10:46:16 +0000 Subject: [PATCH] test suite: minor fixes & cleanups --- mmgen/opts.py | 2 +- mmgen/tool.py | 2 +- test/colortest.py | 7 +++++-- test/hashfunc.py | 2 +- test/objtest.py | 7 +++++-- test/pexpect.py | 8 ++++---- test/test-release.sh | 3 +-- test/tooltest2.py | 19 ++++++++++--------- 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/mmgen/opts.py b/mmgen/opts.py index 1fa63fb3..59b9af40 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -179,7 +179,7 @@ This coin's {pn} testing status: {} Are you sure you want to continue? """.strip().format(g.coin,tl[trust_level],pn=g.proj_name) if g.test_suite: - msg(m); return + qmsg(m); return if not keypress_confirm(m,default_yes=True): sys.exit(0) diff --git a/mmgen/tool.py b/mmgen/tool.py index 21f9a299..f702d6fb 100755 --- a/mmgen/tool.py +++ b/mmgen/tool.py @@ -419,7 +419,7 @@ class MMGenToolCmdCoin(MMGenToolCmdBase): return (rs,addr) def privhex2addr(self,privhex:'sstr',output_pubhex=False): - "generate coin address from private key in hex format" + "generate coin address from raw private key data in hexadecimal format" init_generators() pk = PrivKey(bytes.fromhex(privhex),compressed=at.compressed,pubkey_type=at.pubkey_type) ph = kg.to_pubhex(pk) diff --git a/test/colortest.py b/test/colortest.py index 4d0fb214..dbc66e56 100755 --- a/test/colortest.py +++ b/test/colortest.py @@ -16,7 +16,7 @@ init_color() def test_color(): try: import colorama - colorama.init(strip=True,convert=True) + start_mscolor() except: pass @@ -24,7 +24,10 @@ def test_color(): for t,c in (('rxvt',8),('xterm',8),('rxvt-unicode',88),('screen-256color',256),('xterm-256color',256)): ret = get_terminfo_colors(t) - print('{}: {}'.format(t,ret)) + if ret == None: + ymsg('Warning: unable to get info for terminal {!r}'.format(t)) + continue + msg('{}: {}'.format(t,ret)) assert c == ret, "'colors' value for terminal {} ({}) does not match expected value of {}".format(t,ret,c) ret = get_terminfo_colors() diff --git a/test/hashfunc.py b/test/hashfunc.py index 88fd1d90..4e095b44 100755 --- a/test/hashfunc.py +++ b/test/hashfunc.py @@ -136,7 +136,7 @@ class TestSha512(TestSha2): 0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 ) t = globals()['Test'+test]() -msg(green('Testing internal implementation of {}\n'.format(t.desc))) +msg('Testing internal implementation of {}\n'.format(t.desc)) t.test_constants() t.test_ref() t.test_random(random_rounds) diff --git a/test/objtest.py b/test/objtest.py index bc7300fa..7f655168 100755 --- a/test/objtest.py +++ b/test/objtest.py @@ -81,7 +81,8 @@ def run_test(test,arg,input_data): args = [arg] try: if not opt.super_silent: - msg_r((orange,green)[input_data=='good']('{:<22}'.format(repr(arg_copy)+':'))) + arg_disp = repr(arg_copy[0] if type(arg_copy) == tuple else arg_copy) + msg_r((orange,green)[input_data=='good']('{:<22}'.format(arg_disp+':'))) cls = globals()[test] ret = cls(*args,**kwargs) bad_ret = list() if issubclass(cls,list) else None @@ -96,7 +97,9 @@ def run_test(test,arg,input_data): if input_data=='good' and ret != ret_chk and repr(ret) != repr(ret_chk): raise UserWarning("Return value ({!r}) doesn't match expected value ({!r})".format(ret,ret_chk)) if not opt.super_silent: - msg('==> {}'.format(ret)) + try: ret_disp = ret.decode() + except: ret_disp = ret + msg('==> {!r}'.format(ret_disp)) if opt.verbose and issubclass(cls,MMGenObject): ret.pmsg() if hasattr(ret,'pmsg') else pmsg(ret) except Exception as e: diff --git a/test/pexpect.py b/test/pexpect.py index 9be697d7..80d54775 100755 --- a/test/pexpect.py +++ b/test/pexpect.py @@ -48,18 +48,18 @@ class MMGenPexpect(object): from subprocess import run,DEVNULL run([args[0]] + args[1:],check=True,stdout=DEVNULL if no_output else None) else: + timeout = int(opt.pexpect_timeout or 0) or (60,5)[bool(opt.debug_pexpect)] if opt.pexpect_spawn: - self.p = pexpect.spawn(args[0],args[1:],encoding='utf8') + self.p = pexpect.spawn(args[0],args[1:],encoding='utf8',timeout=timeout) self.p.delaybeforesend = 0 else: - self.p = PopenSpawn(args,encoding='utf8') + self.p = PopenSpawn(args,encoding='utf8',timeout=timeout) # self.p.delaybeforesend = 0 # TODO: try this here too if opt.exact_output: self.p.logfile = sys.stdout self.req_exit_val = 0 self.skip_ok = False - self.timeout = int(opt.pexpect_timeout or 0) or (60,5)[bool(opt.debug_pexpect)] self.sent_value = None def do_decrypt_ka_data(self,hp,pw,desc='key-address data',check=True,have_yes_opt=False): @@ -177,7 +177,7 @@ class MMGenPexpect(object): ret = 0 else: f = (self.p.expect_exact,self.p.expect)[bool(regex)] - ret = f(s,self.timeout) + ret = f(s) except pexpect.TIMEOUT: if opt.debug_pexpect: raise m1 = red('\nERROR. Expect {!r} timed out. Exiting\n'.format(s)) diff --git a/test/test-release.sh b/test/test-release.sh index 635a87b4..855ca6ff 100755 --- a/test/test-release.sh +++ b/test/test-release.sh @@ -320,7 +320,7 @@ t_monero=" f_monero='Monero tests completed' [ "$MSYS2" ] || { # password file descriptor issues, cannot use popen_spawn() - t_monero="$t_monero + t_monero+=" $mmgen_tool -q --accept-defaults --outdir $TMPDIR keyaddrlist2monerowallets $TMPDIR/*-XMR*.akeys addrs=23 $mmgen_tool -q --accept-defaults --outdir $TMPDIR keyaddrlist2monerowallets $TMPDIR/*-XMR*.akeys addrs=103-200 rm $TMPDIR/*-MoneroWallet* @@ -430,7 +430,6 @@ t_tool2=" $tooltest2_py --coin=bch $tooltest2_py --coin=bch --testnet=1 $tooltest2_py --coin=zec - $tooltest2_py --coin=zec --type=zcash_z $tooltest2_py --coin=xmr $tooltest2_py --coin=dash $tooltest2_py --coin=eth diff --git a/test/tooltest2.py b/test/tooltest2.py index edc255dd..d48b851b 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -588,9 +588,10 @@ tests = { 'ED3D 8AA4 BED4 0B40'), ], 'zec_mainnet': [ - ( ['test/ref/zcash/98831F3A-ZEC-C[1,31-33,500-501,1010-1011].addrs'],'903E 7225 DD86 6E01'), ], - 'zec_z_mainnet': [ - ( ['test/ref/zcash/98831F3A-ZEC-Z[1,31-33,500-501,1010-1011].addrs'],'9C7A 72DC 3D4A B3AF'), ], + ( ['test/ref/zcash/98831F3A-ZEC-C[1,31-33,500-501,1010-1011].addrs'],'903E 7225 DD86 6E01'), + ( ['test/ref/zcash/98831F3A-ZEC-Z[1,31-33,500-501,1010-1011].addrs'], '9C7A 72DC 3D4A B3AF', + ['--type=zcash_z'], 'opt.type = "zcash_z"' ), + ], 'xmr_mainnet': [ ( ['test/ref/monero/98831F3A-XMR-M[1,31-33,500-501,1010-1011].addrs'],'4369 0253 AC2C 0E38'), ], 'dash_mainnet': [ @@ -620,10 +621,10 @@ tests = { ], 'zec_mainnet': [ ( ['test/ref/zcash/98831F3A-ZEC-C[1,31-33,500-501,1010-1011].akeys.mmenc'], - 'F05A 5A5C 0C8E 2617', kafile_opts, kafile_code ), ], - 'zec_z_mainnet': [ - ( ['test/ref/zcash/98831F3A-ZEC-Z[1,31-33,500-501,1010-1011].akeys.mmenc'], - '6B87 9B2D 0D8D 8D1E', kafile_opts, kafile_code ), ], + 'F05A 5A5C 0C8E 2617', kafile_opts, kafile_code ), + ( ['test/ref/zcash/98831F3A-ZEC-Z[1,31-33,500-501,1010-1011].akeys.mmenc'], '6B87 9B2D 0D8D 8D1E', + kafile_opts + ['--type=zcash_z'], kafile_code + '\nopt.type = "zcash_z"' ), + ], 'xmr_mainnet': [ ( ['test/ref/monero/98831F3A-XMR-M[1,31-33,500-501,1010-1011].akeys.mmenc'], 'E0D7 9612 3D67 404A', kafile_opts, kafile_code ), ], @@ -670,7 +671,7 @@ def run_test(gid,cmd_name): data = data[k] m2 = ' ({})'.format(k) else: - msg("-- no data for {} ({}) - skipping".format(cmd_name,k)) + qmsg("-- no data for {} ({}) - skipping".format(cmd_name,k)) return else: if g.coin != 'BTC' or g.testnet: return @@ -814,7 +815,7 @@ def list_tested_cmds(): sys.argv = [sys.argv[0]] + ['--skip-cfg-file'] + sys.argv[1:] -cmd_args = opts.init(opts_data) +cmd_args = opts.init(opts_data,add_opts=['use_old_ed25519']) import mmgen.tool as tool