From fb9c5ac22c54c7d987c8da47bede886b8a8c8f0e Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 21 Nov 2023 15:43:52 +0000 Subject: [PATCH] init_proto(): add `return_cls` param; cmdtest.py: minor cleanups --- mmgen/cfg.py | 3 ++- mmgen/daemon.py | 8 +++++--- mmgen/protocol.py | 6 +++++- test/cmdtest.py | 8 ++++---- test/cmdtest_py_d/cfg.py | 3 +-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/mmgen/cfg.py b/mmgen/cfg.py index 8c14a4bc..6fd7bd6c 100755 --- a/mmgen/cfg.py +++ b/mmgen/cfg.py @@ -572,7 +572,8 @@ class Config(Lockable): (ns[2:],ns[1]=='testnet') if len(ns) > 2 and ns[1] in ('mainnet','testnet') else (ns[1:],False) ) - cls = type(init_proto( self, ns[0], tn, need_amt=True )) # no instance yet, so override _class_ attr + # no instance yet, so override _class_ attr: + cls = init_proto(self, ns[0], tn, need_amt=True, return_cls=True) attr = '_'.join(nse) else: cls = self diff --git a/mmgen/daemon.py b/mmgen/daemon.py index e18f85f8..cfb5360d 100755 --- a/mmgen/daemon.py +++ b/mmgen/daemon.py @@ -319,11 +319,13 @@ class CoinDaemon(Daemon): @classmethod def get_daemon(cls,cfg,coin,daemon_id,proto=None): - if not proto: + if proto: + proto_cls = type(proto) + else: from .protocol import init_proto - proto = init_proto( cfg, coin ) + proto_cls = init_proto(cfg, coin, return_cls=True) return getattr( - importlib.import_module(f'mmgen.proto.{proto.base_proto_coin.lower()}.daemon'), + importlib.import_module(f'mmgen.proto.{proto_cls.base_proto_coin.lower()}.daemon'), daemon_id+'_daemon' ) @classmethod diff --git a/mmgen/protocol.py b/mmgen/protocol.py index ca5f58c5..b8705f09 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -238,7 +238,8 @@ def init_proto( network = None, network_id = None, tokensym = None, - need_amt = False ): + need_amt = False, + return_cls = False): assert type(testnet) is bool, 'init_proto_chk1' assert type(regtest) is bool, 'init_proto_chk2' @@ -271,6 +272,9 @@ def init_proto( getattr(importlib.import_module(f'mmgen.proto.{coin}.params'),network) ) + if return_cls: + return getattr(CoinProtocol,proto_name) + return getattr(CoinProtocol,proto_name)( cfg = cfg, coin = coin, diff --git a/test/cmdtest.py b/test/cmdtest.py index a0160f01..103a0072 100755 --- a/test/cmdtest.py +++ b/test/cmdtest.py @@ -94,7 +94,7 @@ else: from test.include.test_init import repo_root from mmgen.cfg import Config,gc -from mmgen.color import red,yellow,green,blue,cyan,nocolor,init_color +from mmgen.color import red,yellow,green,blue,cyan,gray,nocolor,init_color from mmgen.util import Msg,bmsg,die,suf,make_timestr,async_run from test.include.common import ( @@ -699,7 +699,7 @@ class CmdTestRunner: ct_cls = CmdGroupMgr().load_mod(gname) if sys.platform == 'win32' and ct_cls.win_skip: - omsg(f'Skipping test {gname!r} for Windows platform') + omsg(gray(f'INFO → skipping test {gname!r} (platform=win32)')) return False for k in ('segwit','segwit_random','bech32'): @@ -719,7 +719,7 @@ class CmdTestRunner: m = ''.join(gen_msg()) if segwit_opt and not ct_cls.segwit_opts_ok: - iqmsg('INFO → skipping ' + m) + iqmsg(gray(f'INFO → skipping {m}')) return False # 'networks = ()' means all networks allowed @@ -731,7 +731,7 @@ class CmdTestRunner: if a == coin and b == nw: break else: - iqmsg('INFO → skipping ' + m) + iqmsg(gray(f'INFO → skipping {m} (network={nw})')) return False if do_clean: diff --git a/test/cmdtest_py_d/cfg.py b/test/cmdtest_py_d/cfg.py index 95dfd517..63d32bd4 100755 --- a/test/cmdtest_py_d/cfg.py +++ b/test/cmdtest_py_d/cfg.py @@ -12,8 +12,6 @@ test.cmdtest_py_d.cfg: configuration data for cmdtest.py """ -import os - from .common import pwfile,hincog_fn,incog_id_fn,randbool from ..include.common import cfg @@ -222,6 +220,7 @@ cfgs = { # addr_idx_lists (except 31,32,33,34) must contain exactly 8 addresses } def fixup_cfgs(): + import os for src,target in ( ('6','11'), ('7','12'),