From f97869702d3b5559db84cac6273e7b97ea61ec98 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 19 May 2023 16:16:53 +0000 Subject: [PATCH] MSWin/MSYS2 testing fixes --- mmgen/data/version | 2 +- mmgen/term.py | 7 ++++++- mmgen/tw/json.py | 4 +++- mmgen/xmrwallet.py | 2 +- test/test.py | 4 ++++ test/test_py_d/common.py | 3 ++- test/test_py_d/ts_autosign.py | 4 +--- test/test_py_d/ts_base.py | 1 + test/test_py_d/ts_misc.py | 3 +++ test/test_py_d/ts_xmr_autosign.py | 1 + test/test_py_d/ts_xmrwallet.py | 9 ++++++--- test/unit_tests_d/ut_rpc.py | 11 +++++++---- 12 files changed, 36 insertions(+), 15 deletions(-) diff --git a/mmgen/data/version b/mmgen/data/version index 96713812..e4948247 100644 --- a/mmgen/data/version +++ b/mmgen/data/version @@ -1 +1 @@ -13.3.dev55 +13.3.dev56 diff --git a/mmgen/term.py b/mmgen/term.py index 53836824..7761997e 100755 --- a/mmgen/term.py +++ b/mmgen/term.py @@ -272,7 +272,12 @@ class MMGenTermMSWinStub(MMGenTermMSWin): Use stdin to allow UTF-8 and emulate the one-character behavior of MMGenTermMSWin """ msg_r(prompt) - return sys.stdin.read(1) + while True: + try: + return sys.stdin.read(1) + except: + msg('[read error, trying again]') + time.sleep(0.5) get_char_raw = get_char diff --git a/mmgen/tw/json.py b/mmgen/tw/json.py index 0dffb6bd..2b55a2db 100755 --- a/mmgen/tw/json.py +++ b/mmgen/tw/json.py @@ -54,7 +54,9 @@ class TwJSON: from ..addrlist import AddrIdxList prune_id = AddrIdxList(idx_list=self.pruned).id_str fn = get_fn(prune_id) - if len(fn) > os.statvfs(self.cfg.outdir or os.curdir).f_namemax: + from ..cfg import gc + mf = 255 if gc.platform == 'win' else os.statvfs(self.cfg.outdir or os.curdir).f_namemax + if len(fn) > mf: fn = get_fn(f'idhash={make_chksum_8(prune_id.encode()).lower()}') else: fn = get_fn(None) diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index 68501f54..fec213f6 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -22,7 +22,7 @@ xmrwallet.py - MoneroWalletOps class import re,time,json,atexit from collections import namedtuple -from pathlib import PosixPath as Path +from pathlib import Path from .objmethods import MMGenObject,Hilite,InitErrors from .obj import CoinTxID,Int diff --git a/test/test.py b/test/test.py index 1b6338d8..09bab7e7 100755 --- a/test/test.py +++ b/test/test.py @@ -672,6 +672,10 @@ class TestSuiteRunner(object): ts_cls = CmdGroupMgr().load_mod(gname) + if gc.platform == 'win' and ts_cls.win_skip: + omsg(f'Skipping test {gname!r} for Windows platform') + return False + for k in ('segwit','segwit_random','bech32'): if getattr(cfg,k): segwit_opt = k diff --git a/test/test_py_d/common.py b/test/test_py_d/common.py index 52399ead..258e553c 100755 --- a/test/test_py_d/common.py +++ b/test/test_py_d/common.py @@ -116,7 +116,8 @@ def get_file_with_ext(tdir,ext,delete=True,no_dot=False,return_list=False,delete or fn.endswith( dot + ext ) or (substr and ext in fn) ) - flist = [f.path for f in os.scandir(tdir) if have_match(f.name)] + # Don’t use os.scandir here - it returns broken paths under Windows/MSYS2 + flist = [os.path.join(tdir,name) for name in os.listdir(tdir) if have_match(name)] if not flist: return False diff --git a/test/test_py_d/ts_autosign.py b/test/test_py_d/ts_autosign.py index acfa46fd..4ca1dc67 100755 --- a/test/test_py_d/ts_autosign.py +++ b/test/test_py_d/ts_autosign.py @@ -81,6 +81,7 @@ class TestSuiteAutosignBase(TestSuiteBase): color = True mountpoint_basename = 'mmgen_autosign' no_insert_check = True + win_skip = True def __init__(self,trunner,cfgs,spawn): @@ -89,9 +90,6 @@ class TestSuiteAutosignBase(TestSuiteBase): if trunner == None: return - if gc.platform == 'win': - die(1,f'Test {self.name} not supported for Windows platform') - self.network_ids = [c+'_tn' for c in self.daemon_coins] + self.daemon_coins if not self.live: diff --git a/test/test_py_d/ts_base.py b/test/test_py_d/ts_base.py index 22d5e950..d3e5bfbc 100755 --- a/test/test_py_d/ts_base.py +++ b/test/test_py_d/ts_base.py @@ -34,6 +34,7 @@ class TestSuiteBase: segwit_opts_ok = False color = False need_daemon = False + win_skip = False def __init__(self,trunner,cfgs,spawn): if hasattr(self,'tr'): # init will be called multiple times for classes with multiple inheritance diff --git a/test/test_py_d/ts_misc.py b/test/test_py_d/ts_misc.py index 71656a03..3b96dd22 100755 --- a/test/test_py_d/ts_misc.py +++ b/test/test_py_d/ts_misc.py @@ -182,6 +182,9 @@ class TestSuiteHelp(TestSuiteBase): if self.proto.coin not in ('BTC','XMR') and 'xmrwallet' in scripts: scripts.remove('xmrwallet') + if gc.platform == 'win' and 'autosign' in scripts: + scripts.remove('autosign') + for s in sorted(scripts): t = self.spawn(f'mmgen-{s}',[arg],extra_desc=f'(mmgen-{s})') t.expect(expect,regex=True) diff --git a/test/test_py_d/ts_xmr_autosign.py b/test/test_py_d/ts_xmr_autosign.py index 0996b89f..5d5f5d7d 100755 --- a/test/test_py_d/ts_xmr_autosign.py +++ b/test/test_py_d/ts_xmr_autosign.py @@ -47,6 +47,7 @@ class TestSuiteXMRAutosign(TestSuiteXMRWallet,TestSuiteAutosignBase): bad_tx_count = 0 tx_relay_user = 'miner' no_insert_check = False + win_skip = True cmd_group = ( ('daemon_version', 'checking daemon version'), diff --git a/test/test_py_d/ts_xmrwallet.py b/test/test_py_d/ts_xmrwallet.py index 015f0ae3..b08df7af 100755 --- a/test/test_py_d/ts_xmrwallet.py +++ b/test/test_py_d/ts_xmrwallet.py @@ -60,10 +60,11 @@ class TestSuiteXMRWallet(TestSuiteBase): dfl_random_txs = 3 color = True socks_port = 49237 + # Bob’s daemon is stopped via process kill, not RPC, so put Bob last in list: user_data = ( ('miner', '98831F3A', False, 130, '1-2', []), - ('bob', '1378FC64', False, 140, None, ['--restricted-rpc']), ('alice', 'FE3C6545', False, 150, '1-4', []), + ('bob', '1378FC64', False, 140, None, ['--restricted-rpc']), ) tx_relay_user = 'bob' datadir_base = os.path.join('test','daemons','xmrtest') @@ -814,9 +815,11 @@ class TestSuiteXMRWallet(TestSuiteBase): h = await self._get_height() imsg_r(f'Chain height: {h} ') - for count in range(50): + max_iterations,height_threshold = (300,80) if gc.platform == 'win' else (50,300) + + for count in range(max_iterations): bal_info = await get_balance(dest,count) - if h > 300 and (dest.test(bal_info) is True or ( chk_bal_chg and bal_info.ub != bal_info_start.ub )): + if h > height_threshold and (dest.test(bal_info) is True or ( chk_bal_chg and bal_info.ub != bal_info_start.ub )): imsg('') oqmsg_r('+') print_balance(dest,bal_info) diff --git a/test/unit_tests_d/ut_rpc.py b/test/unit_tests_d/ut_rpc.py index 1edbf701..c504fa66 100755 --- a/test/unit_tests_d/ut_rpc.py +++ b/test/unit_tests_d/ut_rpc.py @@ -211,14 +211,17 @@ class unit_tests: filename = fn, password = 'foo', seed = xmrseed().fromhex('beadface'*8,tostr=True) ) + + if gc.platform == 'win': + wd.stop() + wd.start() + qmsg(f'Opening {wd.network} wallet') c.call( 'open_wallet', filename=fn, password='foo' ) - for md,wd in daemons: - wd.wait = False - await wd.rpc.stop_daemon() + await c.stop_daemon() + if not cfg.no_daemon_stop: - md.wait = False await md.rpc.stop_daemon() gmsg('OK')