From b9a6e725d119c466b3d111d191c6fc6193f0396e Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 26 Aug 2024 13:47:02 +0000 Subject: [PATCH] minor fixes and cleanups --- mmgen/autosign.py | 2 +- mmgen/cfg.py | 2 +- mmgen/filename.py | 2 +- mmgen/fileutil.py | 2 +- mmgen/main_xmrwallet.py | 2 +- mmgen/tx/util.py | 2 +- mmgen/xmrwallet.py | 13 +------------ test/cmdtest.py | 3 +++ test/cmdtest_py_d/ct_automount.py | 2 +- test/cmdtest_py_d/ct_autosign.py | 26 +++++++++++++++----------- test/cmdtest_py_d/ct_input.py | 2 +- test/cmdtest_py_d/ct_misc.py | 4 ++-- 12 files changed, 29 insertions(+), 33 deletions(-) diff --git a/mmgen/autosign.py b/mmgen/autosign.py index 0eeb48e9..19f74555 100755 --- a/mmgen/autosign.py +++ b/mmgen/autosign.py @@ -340,7 +340,7 @@ class Autosign: to your fstab as described in this script’s help text. """ - mn_fmts = { + mn_fmts = { 'mmgen': 'words', 'bip39': 'bip39', } diff --git a/mmgen/cfg.py b/mmgen/cfg.py index e5968887..88020255 100755 --- a/mmgen/cfg.py +++ b/mmgen/cfg.py @@ -58,7 +58,7 @@ class GlobalConstants(Lockable): if sys.platform not in ('linux', 'win32', 'darwin'): die2(1,f'{sys.platform!r}: platform not supported by {proj_name}') - if os.getenv('HOME'): # Linux or MSYS2 + if os.getenv('HOME'): # Linux, MSYS2, or macOS home_dir = os.getenv('HOME') elif sys.platform == 'win32': # Windows without MSYS2 - not supported die2(1,f'$HOME not set! {proj_name} for Windows must be run in MSYS2 environment') diff --git a/mmgen/filename.py b/mmgen/filename.py index 6c3e0e15..d07913e8 100755 --- a/mmgen/filename.py +++ b/mmgen/filename.py @@ -42,7 +42,7 @@ class File: import stat if stat.S_ISBLK(st.st_mode): - if sys.platform in ('win32',): + if sys.platform in ('win32', 'darwin'): die(2, 'Access to raw block devices not supported on platform {sys.platform!r}') mode = (os.O_RDONLY,os.O_RDWR)[bool(write)] try: diff --git a/mmgen/fileutil.py b/mmgen/fileutil.py index be8beaa7..92eb8a46 100755 --- a/mmgen/fileutil.py +++ b/mmgen/fileutil.py @@ -86,7 +86,7 @@ def _check_file_type_and_access(fname,ftype,blkdev_ok=False): (stat.S_ISLNK,'symbolic link') ] if blkdev_ok: - if not sys.platform in ('win32',): + if not sys.platform in ('win32', 'darwin'): ok_types.append((stat.S_ISBLK, 'block device')) try: diff --git a/mmgen/main_xmrwallet.py b/mmgen/main_xmrwallet.py index daa9b38e..c4360acc 100755 --- a/mmgen/main_xmrwallet.py +++ b/mmgen/main_xmrwallet.py @@ -115,7 +115,7 @@ opts_data = { } } -cfg = Config(opts_data=opts_data) +cfg = Config(opts_data=opts_data, init_opts={'coin':'xmr'}) cmd_args = cfg._args diff --git a/mmgen/tx/util.py b/mmgen/tx/util.py index 4ec5ddc4..96c5616a 100755 --- a/mmgen/tx/util.py +++ b/mmgen/tx/util.py @@ -21,7 +21,7 @@ def get_autosign_obj(cfg): 'test_suite': cfg.test_suite, 'test_suite_root_pfx': cfg.test_suite_root_pfx, 'coins': cfg.coin, - 'online': True, # used only in online environment (txcreate, txsend) + 'online': not cfg.offline, # used only in online environment (xmrwallet, txcreate, txsend, txbump) }) ) diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index 4dba132c..6e6ee276 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -57,6 +57,7 @@ from .proto.xmr.rpc import MoneroRPCClient,MoneroWalletRPCClient from .proto.xmr.daemon import MoneroWalletDaemon from .ui import keypress_confirm from .autosign import Autosign +from .tx.util import get_autosign_obj xmrwallet_uargs = namedtuple('xmrwallet_uargs',[ 'infile', @@ -77,18 +78,6 @@ xmrwallet_uarg_info = ( r'(?:[^:]+):(?:\d+)' ) -def get_autosign_obj(cfg): - from .cfg import Config - return Autosign( - Config({ - 'mountpoint': cfg.autosign_mountpoint, - 'test_suite': cfg.test_suite, - 'test_suite_root_pfx': cfg.test_suite_root_pfx, - 'coins': 'xmr', - 'online': not cfg.offline, - }) - ) - # required to squelch pylint: def fmt_amt(amt): return str(amt) diff --git a/test/cmdtest.py b/test/cmdtest.py index cdc8bbf8..875e872b 100755 --- a/test/cmdtest.py +++ b/test/cmdtest.py @@ -997,6 +997,9 @@ if __name__ == '__main__': tr.warn_skipped() if tr.daemon_started: stop_test_daemons(network_id) + if hasattr(tr, 'tg'): + del tr.tg + del tr except KeyboardInterrupt: if tr.daemon_started: stop_test_daemons(network_id) diff --git a/test/cmdtest_py_d/ct_automount.py b/test/cmdtest_py_d/ct_automount.py index 292c7a69..6d9e6093 100755 --- a/test/cmdtest_py_d/ct_automount.py +++ b/test/cmdtest_py_d/ct_automount.py @@ -249,7 +249,7 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet) t.expect('Only sent transactions') t.expect(bad_tx_desc) else: - t.expect(f'to deduct the fee from .* change output\): ', '\n', regex=True) + t.expect(r'to deduct the fee from .* change output\): ', '\n', regex=True) t.expect(r'(Y/n): ', 'y') # output OK? t.expect('transaction fee: ', '200s\n') t.expect(r'(Y/n): ', 'y') # fee OK? diff --git a/test/cmdtest_py_d/ct_autosign.py b/test/cmdtest_py_d/ct_autosign.py index 7c27887f..cd734dd9 100755 --- a/test/cmdtest_py_d/ct_autosign.py +++ b/test/cmdtest_py_d/ct_autosign.py @@ -82,24 +82,28 @@ class CmdTestAutosignBase(CmdTestBase): def _create_autosign_instances(self,create_dirs): d = {'offline': {'name':'asi'}} + if self.have_online: d['online'] = {'name':'asi_online'} + for subdir,data in d.items(): + asi = Autosign( + Config({ + 'coins': ','.join(self.coins), + 'test_suite': True, + 'test_suite_xmr_autosign': self.name == 'CmdTestXMRAutosign', + 'test_suite_autosign_threaded': self.threaded, + 'test_suite_root_pfx': None if self.live else self.tmpdir, + 'online': subdir == 'online', + })) + if create_dirs and not self.live: - for k in ('mountpoint','wallet_dir','dev_label_dir'): + for k in ('mountpoint', 'wallet_dir', 'dev_label_dir'): if k == 'wallet_dir' and subdir == 'online': continue (Path(self.tmpdir) / (subdir + getattr(Autosign,'dfl_'+k))).mkdir(parents=True,exist_ok=True) - setattr(self,data['name'], - Autosign( - Config({ - 'coins': ','.join(self.coins), - 'test_suite': True, - 'test_suite_xmr_autosign': self.name == 'CmdTestXMRAutosign', - 'test_suite_autosign_threaded': self.threaded, - 'test_suite_root_pfx': None if self.live else self.tmpdir, - 'online': subdir == 'online', - }))) + + setattr(self, data['name'], asi) def _create_removable_device(self): redir = DEVNULL diff --git a/test/cmdtest_py_d/ct_input.py b/test/cmdtest_py_d/ct_input.py index 87f1f889..fb225534 100755 --- a/test/cmdtest_py_d/ct_input.py +++ b/test/cmdtest_py_d/ct_input.py @@ -471,7 +471,7 @@ class CmdTestInput(CmdTestBase): from mmgen.mn_entry import mn_entry mne = mn_entry( cfg, fmt, entry_mode ) t.expect('Type a number.*: ',str(mne.entry_modes.index(entry_mode)+1),regex=True) - t.expect('Using entry mode (\S+)',regex=True) + t.expect(r'Using entry mode (\S+)',regex=True) mode = strip_ansi_escapes(t.p.match.group(1)).lower() assert mode == mne.em.name.lower(), f'{mode} != {mne.em.name.lower()}' stealth_mnemonic_entry(t,mne,mn,entry_mode=entry_mode) diff --git a/test/cmdtest_py_d/ct_misc.py b/test/cmdtest_py_d/ct_misc.py index e7d87c00..b24e0409 100755 --- a/test/cmdtest_py_d/ct_misc.py +++ b/test/cmdtest_py_d/ct_misc.py @@ -217,10 +217,10 @@ class CmdTestHelp(CmdTestBase): if 'tx' not in self.proto.mmcaps: scripts = [s for s in scripts if not (s == 'regtest' or s.startswith('tx'))] - if self.proto.coin not in ('BTC','XMR') and 'xmrwallet' in scripts: + if 'xmrwallet' in scripts and (cfg.no_altcoin or not self.proto.coin in ('BTC','XMR')): scripts.remove('xmrwallet') - if sys.platform == 'win32' and 'autosign' in scripts: + if 'autosign' in scripts and sys.platform == 'win32': scripts.remove('autosign') for s in sorted(scripts):