From 6b4841e760faf4e0cdce13a89a178f646e590aba Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 11 Sep 2026 14:10:56 +0000 Subject: [PATCH] test suite: data_dir, trash_dir fixups --- mmgen/cfg.py | 2 +- test/clean.py | 7 +++---- test/cmdtest.py | 29 +++++++++++++++-------------- test/cmdtest_d/include/common.py | 2 +- test/cmdtest_d/input.py | 13 +++++++------ test/cmdtest_d/main.py | 3 ++- test/cmdtest_d/ref_3seed.py | 4 ++-- test/cmdtest_d/ref_altcoin.py | 5 +++-- test/daemontest_d/msg.py | 5 +++-- test/daemontest_d/rpc.py | 10 +++++----- test/include/common.py | 3 +++ test/include/unit_test.py | 3 --- 12 files changed, 45 insertions(+), 41 deletions(-) diff --git a/mmgen/cfg.py b/mmgen/cfg.py index 10c8b06e..ad632713 100755 --- a/mmgen/cfg.py +++ b/mmgen/cfg.py @@ -285,7 +285,7 @@ class Config(Lockable): exit_after = '' resuming = False skipping_deps = False - test_datadir = os.path.join('test', 'data_dir' + ('', '-α')[bool(os.getenv('MMGEN_DEBUG_UTF8'))]) + test_datadir = os.path.join('test', 'tmp', 'data_dir') mnemonic_entry_modes = {} diff --git a/test/clean.py b/test/clean.py index 3b8508ed..7b60de9e 100755 --- a/test/clean.py +++ b/test/clean.py @@ -43,15 +43,14 @@ if os.path.exists(overlay_tree_dir): rmtree(overlay_tree_dir, ignore_errors=True) print(f'Removed {os.path.relpath(overlay_tree_dir)!r}') -from test.include.common import clean, set_globals +from test.include.common import clean, set_globals, trash_dir, trash_dir2 set_globals(cfg) extra_dirs = [ Config.test_datadir, - os.path.join('test', 'trash'), - os.path.join('test', 'trash2') -] + trash_dir, + trash_dir2] from test.cmdtest_d.include.cfg import cfgs clean(cfgs, extra_dirs=extra_dirs) diff --git a/test/cmdtest.py b/test/cmdtest.py index daad2a8f..f394906c 100755 --- a/test/cmdtest.py +++ b/test/cmdtest.py @@ -25,13 +25,13 @@ def check_segwit_opts(proto): if getattr(cfg, k) and m not in proto.mmtypes: die(1, f'--{k.replace("_", "-")} option incompatible with {proto.cls_name}') -def create_shm_dir(data_dir, trash_dir): +def create_shm_dir(data_dir, trash_dir, trash_dir2): # Laggy flash media can cause pexpect to fail, so create a temporary directory # under '/dev/shm' and put datadir and tmpdirs here. import shutil from subprocess import run if gc.platform in ('win32', 'darwin'): - for tdir in (data_dir, trash_dir): + for tdir in (data_dir, trash_dir, trash_dir2): try: os.listdir(tdir) except: @@ -61,11 +61,12 @@ def create_shm_dir(data_dir, trash_dir): except Exception as e: die(2, f'Unable to create temporary directory in {tdir} ({e.args[0]})') - dest = os.path.join(shm_dir, os.path.basename(trash_dir)) - os.mkdir(dest, 0o755) + for tdir in (trash_dir, trash_dir2): + dest = os.path.join(shm_dir, os.path.basename(tdir)) + os.mkdir(dest, 0o755) - run(f'rm -rf {trash_dir}', shell=True, check=True) - os.symlink(dest, trash_dir) + run(f'rm -rf {tdir}', shell=True, check=True) + os.symlink(dest, tdir) dest = os.path.join(shm_dir, os.path.basename(data_dir)) shutil.move(data_dir, dest) # data_dir was created by Config() @@ -90,6 +91,8 @@ from test.include.common import ( cmdtest_py_log_fn, cmdtest_py_error_fn, mk_tmpdir, + trash_dir, + trash_dir2, stop_test_daemons) try: @@ -179,10 +182,11 @@ data_dir = Config.test_datadir # step 1: delete data_dir symlink in ./test; if not po.user_opts.get('skip_deps'): - try: - os.unlink(data_dir) - except: - pass + for fn in (data_dir,): + try: + os.unlink(fn) + except: + pass # step 2: opts.init will create new data_dir in ./test (if not po.user_opts['skip_deps']) cfg = Config(opts_data=opts_data) @@ -212,11 +216,8 @@ if cfg.daemon_id and cfg.daemon_id in cfg.blacklisted_daemons.split(): die(1, f'cmdtest.py: daemon {cfg.daemon_id!r} blacklisted, exiting') # step 3: move data_dir to /dev/shm and symlink it back to ./test: -trash_dir = os.path.join('test', 'trash') -trash_dir2 = os.path.join('test', 'trash2') - if not cfg.skipping_deps: - shm_dir = create_shm_dir(data_dir, trash_dir) + shm_dir = create_shm_dir(data_dir, trash_dir, trash_dir2) check_segwit_opts(cfg._proto) diff --git a/test/cmdtest_d/include/common.py b/test/cmdtest_d/include/common.py index a93b3b10..9030b15c 100755 --- a/test/cmdtest_d/include/common.py +++ b/test/cmdtest_d/include/common.py @@ -74,7 +74,7 @@ Ctrl_U = '\x15' eth_inbound_addr = (28 * '0') + 'feedbeefcafe' -thorchain_router_addr_file = 'test/data_dir/thorchain_router_addr' +thorchain_router_addr_file = os.path.join(cfg.test_datadir, 'thorchain_router_addr') def ok_msg(): if cfg.profile: diff --git a/test/cmdtest_d/input.py b/test/cmdtest_d/input.py index 36ec12ca..3da38cee 100755 --- a/test/cmdtest_d/input.py +++ b/test/cmdtest_d/input.py @@ -22,8 +22,9 @@ from ..include.common import ( sample_mn, get_data_from_file, read_from_file, - strip_ansi_escapes -) + strip_ansi_escapes, + trash_dir) + from .include.common import Ctrl_U, ref_dir from .base import CmdTestBase from .include.input import stealth_mnemonic_entry, user_dieroll_entry @@ -124,7 +125,7 @@ class CmdTestInput(CmdTestBase): '--skip-cfg-file', '--in-fmt=words', '--out-fmt=words', - '--outdir=test/trash'] + f'--outdir={trash_dir}'] mn = sample_mn['mmgen']['mn'] run_env = dict(os.environ) run_env['MMGEN_TEST_SUITE'] = '' @@ -134,7 +135,7 @@ class CmdTestInput(CmdTestBase): imsg(cp.stderr.decode().strip()) res = get_data_from_file( self.cfg, - 'test/trash/A773B05C[128].mmwords', + os.path.join(trash_dir, 'A773B05C[128].mmwords'), silent = True).strip() assert res == mn, f'{res} != {mn}' return 'ok' if b'written to file' in cp.stderr else 'error' @@ -209,12 +210,12 @@ class CmdTestInput(CmdTestBase): return t def get_passphrase_cmdline(self): - with open('test/trash/pwfile', 'w') as fp: + with open(os.path.join(trash_dir, 'pwfile'), 'w') as fp: fp.write('reference password\n') t = self.spawn('test/misc/get_passphrase.py', [ '--usr-randchars=0', '--label=MyLabel', - '--passwd-file=test/trash/pwfile', + '--passwd-file={}'.format(os.path.join(trash_dir, 'pwfile')), '--hash-preset=1', 'seed'], cmd_dir = '.') diff --git a/test/cmdtest_d/main.py b/test/cmdtest_d/main.py index 01ee42a8..4582922f 100755 --- a/test/cmdtest_d/main.py +++ b/test/cmdtest_d/main.py @@ -39,6 +39,7 @@ from ..include.common import ( getrandnum, getrandnum_range, getrandhex, + trash_dir, strip_ansi_escapes) from .include.common import ( @@ -382,7 +383,7 @@ class CmdTestMain(CmdTestBase, CmdTestShared): self.tx_fee = {'btc':'90s', 'bch':'0.001', 'ltc':'0.01'}[self.coin] self.txbump_fee = {'btc':'123s', 'bch':'567s', 'ltc':'12345s'}[self.coin] - self.unspent_data_file = joinpath('test', 'trash', 'unspent.json') + self.unspent_data_file = joinpath(trash_dir, 'unspent.json') self.spawn_env['MMGEN_TEST_SUITE_BOGUS_UNSPENT_DATA'] = self.unspent_data_file @property diff --git a/test/cmdtest_d/ref_3seed.py b/test/cmdtest_d/ref_3seed.py index 291339e0..36f0b562 100755 --- a/test/cmdtest_d/ref_3seed.py +++ b/test/cmdtest_d/ref_3seed.py @@ -26,7 +26,7 @@ import os from mmgen.util import msg, capfirst from mmgen.wallet import get_wallet_cls -from ..include.common import cmp_or_die, joinpath +from ..include.common import cmp_or_die, joinpath, trash_dir from .include.common import ( pwfile, ref_wallet_hash_preset, @@ -172,7 +172,7 @@ class CmdTestRef3Seed(CmdTestBase, CmdTestShared): def ref_walletconv(self, ofmt, extra_args=[], re_pat=None): wf = self.get_file_with_ext('mmdat') pf = joinpath(self.tmpdir, pwfile) - t = self.spawn('mmgen-walletconv', extra_args+['-d', 'test/trash', '-o', ofmt, '-P'+pf, wf]) + t = self.spawn('mmgen-walletconv', extra_args+['-d', trash_dir, '-o', ofmt, '-P'+pf, wf]) wcls = get_wallet_cls(fmt_code=ofmt) fn = os.path.split(t.written_to_file(capfirst(wcls.desc)))[-1] idx = int(self.test_name[-1]) - 1 diff --git a/test/cmdtest_d/ref_altcoin.py b/test/cmdtest_d/ref_altcoin.py index 3316ef39..c8d25d7d 100755 --- a/test/cmdtest_d/ref_altcoin.py +++ b/test/cmdtest_d/ref_altcoin.py @@ -25,7 +25,8 @@ from ..include.common import ( joinpath, start_test_daemons, stop_test_daemons, - cmp_or_die) + cmp_or_die, + trash_dir) from .ref import CmdTestRef, CmdTestRefTX from .base import CmdTestBase @@ -111,7 +112,7 @@ class CmdTestRefAltcoin(CmdTestRef, CmdTestBase): start_test_daemons(proto.network_id) t = self.spawn( 'mmgen-txsign', - ['--outdir=test/trash', '--yes', f'--passwd-file={passfile}', dfl_words_file, txfile], + [f'--outdir={trash_dir}', '--yes', f'--passwd-file={passfile}', dfl_words_file, txfile], no_passthru_opts = ['coin'], extra_desc = f'{proto.coin}{token_desc} {proto.network}') t.read() diff --git a/test/daemontest_d/msg.py b/test/daemontest_d/msg.py index 31b80da5..1ef231ef 100755 --- a/test/daemontest_d/msg.py +++ b/test/daemontest_d/msg.py @@ -16,7 +16,8 @@ from ..include.common import ( silence, end_silence, restart_test_daemons, - stop_test_daemons) + stop_test_daemons, + trash_dir2) def get_obj(coin, network, msghash_type): @@ -54,7 +55,7 @@ async def do_test(network_id, chksum, msghash_type='raw'): pumsg('\nTesting data creation:\n') - tmpdir = os.path.join('test', 'trash2') + tmpdir = trash_dir2 os.makedirs(tmpdir, exist_ok=True) diff --git a/test/daemontest_d/rpc.py b/test/daemontest_d/rpc.py index 9b3125ab..4377d3d3 100755 --- a/test/daemontest_d/rpc.py +++ b/test/daemontest_d/rpc.py @@ -15,7 +15,7 @@ from mmgen.daemon import CoinDaemon from mmgen.proto.xmr.rpc import MoneroRPCClient, MoneroWalletRPCClient from mmgen.proto.xmr.daemon import MoneroWalletDaemon -from ..include.common import cfg, qmsg, vmsg, in_nix_environment, test_exec +from ..include.common import cfg, qmsg, vmsg, in_nix_environment, test_exec, trash_dir2 async def cfg_file_auth_test(cfg, d, bad_auth=False): m = 'missing credentials' if bad_auth else f'credentials from {d.cfg_file}' @@ -246,8 +246,8 @@ class unit_tests: cfg = cfg, proto = proto, test_suite = True, - wallet_dir = os.path.join('test', 'trash2'), - datadir = os.path.join('test', 'trash2', 'wallet_rpc'), + wallet_dir = trash_dir2, + datadir = os.path.join(trash_dir2, 'wallet_rpc'), passwd = 'ut_rpc_passw0rd') ) for proto in (init_proto(cfg, 'xmr', network=network) for network in networks)] @@ -282,7 +282,7 @@ class unit_tests: gmsg('OK') import shutil - shutil.rmtree('test/trash2', ignore_errors=True) - os.makedirs('test/trash2/wallet_rpc') + shutil.rmtree(trash_dir2, ignore_errors=True) + os.makedirs(os.path.join(trash_dir2, 'wallet_rpc')) await run() return True diff --git a/test/include/common.py b/test/include/common.py index ba2df7bd..26c657c9 100755 --- a/test/include/common.py +++ b/test/include/common.py @@ -60,6 +60,9 @@ def set_globals(cfg): def strip_ansi_escapes(s): return re.sub('\x1b' + r'\[[;0-9]+?m', '', s) +trash_dir = os.path.join('test', 'tmp', 'trash') +trash_dir2 = os.path.join('test', 'tmp', 'trash2') + cmdtest_py_log_fn = 'cmdtest.py.log' cmdtest_py_error_fn = 'cmdtest.py.err' parity_dev_amt = 1606938044258990275541962092341162602522202993782792835301376 diff --git a/test/include/unit_test.py b/test/include/unit_test.py index 5a7ba794..73f08d4b 100755 --- a/test/include/unit_test.py +++ b/test/include/unit_test.py @@ -63,9 +63,6 @@ If no test is specified, all available tests are run } } -if os.path.islink(Config.test_datadir): - os.unlink(Config.test_datadir) - sys.argv.insert(1, '--skip-cfg-file') cfg = Config(opts_data=opts_data)