Daemon: clean up handling of test_suite param

This commit is contained in:
The MMGen Project 2026-09-15 10:51:03 +00:00
commit a84a0613d2
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
20 changed files with 35 additions and 55 deletions

View file

@ -175,7 +175,7 @@ class Autosign:
await rpc_init(self.cfg, proto, ignore_wallet=True)
except SocketError as e:
from ..daemon import CoinDaemon
d = CoinDaemon(self.cfg, proto=proto, test_suite=self.cfg.test_suite)
d = CoinDaemon(self.cfg, proto=proto)
die(2,
f'\n{e}\nIs the {d.coind_name} daemon ({d.exec_fn}) running '
+ 'and listening on the correct port?')

View file

@ -50,7 +50,7 @@ class Daemon(Lockable):
_reset_ok = ('debug', 'wait', 'pids')
version_info_arg = '--version'
def __init__(self, cfg, *, opts=None, flags=None):
def __init__(self, cfg, *, opts=None, flags=None, test_suite=None):
self.cfg = cfg
if gc.platform == 'win32':
@ -60,6 +60,7 @@ class Daemon(Lockable):
self.opt = ClassOpts(self, opts)
self.flag = ClassFlags(self, flags)
self.debug = self.debug or cfg.debug_daemon
self.test_suite = cfg.test_suite if test_suite is None else test_suite
def exec_cmd_thread(self, cmd):
import threading
@ -259,8 +260,8 @@ class RPCDaemon(Daemon):
avail_opts = ('no_daemonize',)
def __init__(self, cfg, *, opts=None, flags=None):
super().__init__(cfg, opts=opts, flags=flags)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.desc = '{} {} {}RPC daemon'.format(
self.rpc_desc,
getattr(self.proto.network_names, self.proto.network),
@ -342,13 +343,11 @@ class CoinDaemon(Daemon):
*,
network_id = None,
proto = None,
opts = None,
flags = None,
test_suite = False,
port_shift = None,
p2p_port = None,
datadir = None,
daemon_id = None):
daemon_id = None,
**kwargs):
assert network_id or proto, 'CoinDaemon_chk1'
assert not (network_id and proto), 'CoinDaemon_chk2'
@ -392,17 +391,13 @@ class CoinDaemon(Daemon):
*,
network_id = None,
proto = None,
opts = None,
flags = None,
test_suite = False,
port_shift = None,
p2p_port = None,
datadir = None,
daemon_id = None):
daemon_id = None,
**kwargs):
self.test_suite = test_suite
super().__init__(cfg=cfg, opts=opts, flags=flags)
super().__init__(cfg, **kwargs)
self._set_ok += ('shared_args', 'usr_coind_args')
self.shared_args = []
@ -414,23 +409,23 @@ class CoinDaemon(Daemon):
self.desc = '{} {} {}daemon'.format(
self.coind_name,
getattr(self.proto.network_names, self.network),
'test suite ' if test_suite else '')
'test suite ' if self.test_suite else '')
# user-set values take precedence
self.datadir = os.path.abspath(datadir or cfg.daemon_data_dir or self.init_datadir())
self.non_dfl_datadir = bool(datadir or cfg.daemon_data_dir or test_suite or self.network == 'regtest')
self.non_dfl_datadir = bool(datadir or cfg.daemon_data_dir or self.test_suite or self.network == 'regtest')
# init_datadir() may have already initialized logdir
self.logdir = os.path.abspath(getattr(self, 'logdir', self.datadir))
ps_adj = (port_shift or 0) + (self.test_suite_port_shift if test_suite else 0)
ps_adj = (port_shift or 0) + (self.test_suite_port_shift if self.test_suite else 0)
# user-set values take precedence
usr_rpc_port = self.proto.rpc_port or cfg.rpc_port
self.rpc_port = usr_rpc_port + (port_shift or 0) if usr_rpc_port else ps_adj + self.get_rpc_port()
self.p2p_port = (
p2p_port or (
self.get_p2p_port() + ps_adj if self.get_p2p_port() and (test_suite or ps_adj) else None
self.get_p2p_port() + ps_adj if self.get_p2p_port() and (self.test_suite or ps_adj) else None
) if self.network != 'regtest' else None)
if hasattr(self, 'private_ports'):

View file

@ -87,7 +87,6 @@ class MMGenRegtest(MMGenObject):
self.d = CoinDaemon(
cfg,
network_id = self.coin + '_rt',
test_suite = cfg.test_suite,
opts = ['bdb_wallet'] if self.bdb_wallet else None)
# Caching creates problems (broken pipe) when recreating + loading wallets,

View file

@ -26,7 +26,7 @@ class ethereum_daemon(CoinDaemon):
daemon_port_offset = 100
network_port_offsets = _nw(0, 10, 20)
def __init__(self, *args, test_suite=False, **kwargs):
def __init__(self, *args, test_suite=None, **kwargs):
if not hasattr(self, 'all_daemons'):
ethereum_daemon.all_daemons = get_subclasses(ethereum_daemon, names=True)
@ -168,7 +168,6 @@ class erigon_daemon(geth_daemon):
proto = self.proto,
rpc_port = self.rpc_port,
private_port = self.private_port,
test_suite = self.test_suite,
datadir = self.datadir)
def start(self, *, quiet=False, silent=False):
@ -193,13 +192,11 @@ class erigon_rpcdaemon(RPCDaemon):
use_pidfile = False
use_threads = True
def __init__(self, cfg, proto, *, rpc_port, private_port, test_suite, datadir):
self.proto = proto
self.test_suite = test_suite
def __init__(self, cfg, *, proto, rpc_port, private_port, datadir):
super().__init__(cfg)
self.proto = proto
self.network = proto.network
self.rpc_port = rpc_port
self.datadir = datadir

View file

@ -103,7 +103,6 @@ class MoneroWalletDaemon(RPCDaemon):
proto,
*,
wallet_dir = None,
test_suite = False,
user = None,
passwd = None,
monerod_addr = None,
@ -112,24 +111,23 @@ class MoneroWalletDaemon(RPCDaemon):
datadir = None,
trust_monerod = False,
test_monerod = False,
opts = None,
flags = None):
**kwargs):
self.proto = proto
self.test_suite = test_suite
super().__init__(cfg, opts=opts, flags=flags)
super().__init__(cfg, **kwargs)
self.network = proto.network
self.wallet_dir = wallet_dir or (self.test_suite_datadir if test_suite else None)
self.wallet_dir = wallet_dir or (self.test_suite_datadir if self.test_suite else None)
self.rpc_port = (
self.cfg.wallet_rpc_port or
getattr(self.rpc_ports, self.network) + (11 if test_suite else 0))
getattr(self.rpc_ports, self.network) + (11 if self.test_suite else 0))
if port_shift:
self.rpc_port += port_shift
id_str = f'{self.exec_fn}-{self.bind_port}'
self.datadir = datadir or (self.test_suite_datadir if test_suite else self.exec_fn + '.d')
self.datadir = datadir or (self.test_suite_datadir if self.test_suite else self.exec_fn + '.d')
self.pidfile = os.path.join(self.datadir, id_str+'.pid')
self.logfile = os.path.join(self.datadir, id_str+'.log')
@ -140,9 +138,8 @@ class MoneroWalletDaemon(RPCDaemon):
self.monerod_port = (
None if monerod_addr else
CoinDaemon(
cfg = self.cfg,
proto = proto,
test_suite = test_suite).rpc_port)
cfg = self.cfg,
proto = proto).rpc_port)
if test_monerod and self.monerod_port:
import socket
@ -175,7 +172,7 @@ class MoneroWalletDaemon(RPCDaemon):
[f'--pidfile={self.pidfile}', gc.platform == 'linux'],
['--detach', not (self.opt.no_daemonize or gc.platform=='win32')],
['--stagenet', self.network == 'testnet'],
['--allow-mismatched-daemon-version', test_suite])
['--allow-mismatched-daemon-version', self.test_suite])
from .rpc import MoneroWalletRPCClient
self.rpc = MoneroWalletRPCClient(

View file

@ -43,7 +43,7 @@ async def rpc_init(
proto.base_proto + 'RPCClient')(
cfg = cfg,
proto = proto,
daemon = daemon or CoinDaemon(cfg, proto=proto, test_suite=cfg.test_suite),
daemon = daemon or CoinDaemon(cfg, proto=proto),
backend = backend or cfg.rpc_backend,
ignore_wallet = ignore_wallet)

View file

@ -33,7 +33,7 @@ class tool_cmd(tool_cmd_base):
async def daemon_version(self):
"print coin daemon version"
from ..daemon import CoinDaemon
d = CoinDaemon(cfg=self.cfg, proto=self.proto, test_suite=self.cfg.test_suite)
d = CoinDaemon(cfg=self.cfg, proto=self.proto)
if self.proto.base_proto == 'Monero':
from ..proto.xmr.rpc import MoneroRPCClient
r = MoneroRPCClient(

View file

@ -39,7 +39,7 @@ class OpDaemon(OpBase):
md = None
else:
from ...daemon import CoinDaemon
md = CoinDaemon(self.cfg, network_id='xmr', test_suite=self.cfg.test_suite)
md = CoinDaemon(self.cfg, network_id='xmr')
host, port = (
self.cfg.daemon.split(':') if self.cfg.daemon else
('localhost', md.rpc_port))

View file

@ -54,7 +54,6 @@ class OpSubmit(OpWallet):
cfg = self.cfg,
proto = self.proto,
wallet_dir = self.cfg.wallet_dir or '.',
test_suite = self.cfg.test_suite,
monerod_addr = relay_opt[1])
u = wd.usr_daemon_args = []

View file

@ -52,7 +52,6 @@ class OpSweep(OpMixinSpec, OpWallet):
cfg = self.cfg,
proto = self.proto,
wallet_dir = self.cfg.wallet_dir or '.',
test_suite = self.cfg.test_suite,
monerod_addr = m[1],
proxy = m[2])

View file

@ -66,7 +66,6 @@ class OpWallet(OpBase):
cfg = self.cfg,
proto = self.proto,
wallet_dir = self.cfg.wallet_dir or '.',
test_suite = self.cfg.test_suite,
monerod_addr = self.cfg.daemon or None,
trust_monerod = self.trust_monerod,
test_monerod = not self.wallet_offline)

View file

@ -122,7 +122,6 @@ class CmdTestAutosignBase(CmdTestBase):
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,

View file

@ -734,7 +734,7 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
self.proto = init_proto(cfg, network_id=self.proto.coin+'_rt', need_amt=True)
from mmgen.daemon import CoinDaemon
self.daemon = CoinDaemon(cfg, network_id=self.proto.coin+'_rt', test_suite=True)
self.daemon = CoinDaemon(cfg, network_id=self.proto.coin+'_rt')
if self.daemon.id == 'reth':
global reth_devkey, reth_devaddr

View file

@ -117,7 +117,6 @@ class CmdTestXMRAutosign(CmdTestXMRWallet, CmdTestAutosignThreaded):
'coin': 'XMR',
'outdir': self.users['alice'].udir,
'wallet_rpc_password': 'passwOrd',
'test_suite': True,
} | ({
'alice': True,
'compat': True

View file

@ -196,7 +196,6 @@ class CmdTestXMRWallet(CmdTestBase):
md = CoinDaemon(
cfg = self.cfg,
proto = self.proto,
test_suite = True,
port_shift = shift,
opts = ['online'],
datadir = daemon_datadir)
@ -214,7 +213,6 @@ class CmdTestXMRWallet(CmdTestBase):
wd = MoneroWalletDaemon(
cfg = self.cfg,
proto = self.proto,
test_suite = True,
wallet_dir = wallet_dir,
user = 'foo',
passwd = 'bar',

View file

@ -162,7 +162,7 @@ def run_test(network_ids, test_cf_auth=False, daemon_ids=None, cfg_override=None
all_ids = CoinDaemon.get_daemon_ids(my_cfg, proto.coin)
ids = set(daemon_ids) & set(all_ids) if daemon_ids else all_ids
for daemon_id in ids:
do_test(CoinDaemon(my_cfg, proto=proto, test_suite=True, daemon_id=daemon_id), my_cfg)
do_test(CoinDaemon(my_cfg, proto=proto, daemon_id=daemon_id), my_cfg)
return True
@ -240,11 +240,10 @@ class unit_tests:
async def run():
networks = init_proto(cfg, 'xmr').networks
daemons = [(
CoinDaemon(cfg, proto=proto, test_suite=True),
CoinDaemon(cfg, proto=proto),
MoneroWalletDaemon(
cfg = cfg,
proto = proto,
test_suite = True,
wallet_dir = trash_dir2,
datadir = os.path.join(trash_dir2, 'wallet_rpc'),
passwd = 'ut_rpc_passw0rd')

View file

@ -110,7 +110,7 @@ class unit_tests:
async def newtx(self, name, ut):
qmsg(' Testing NewTX initializer')
d = CoinDaemon(cfg, network_id='btc', test_suite=True)
d = CoinDaemon(cfg, network_id='btc')
d.start()
proto = init_proto(cfg, 'btc', need_amt=True)

View file

@ -79,7 +79,6 @@ def run(network_id=None, proto=None, daemon_id=None, missing_exec_ok=False):
proto = init_proto(cfg, coin='XMR', network=xmr_wallet_network_ids[network_id]),
user = 'test',
passwd = 'test passwd',
test_suite = True,
monerod_addr = None,
trust_monerod = True,
test_monerod = False,

View file

@ -313,7 +313,7 @@ def test_daemons_ops(*network_ids, op, remove_datadir=False, verbose=False):
silent = not (verbose or cfg.verbose or cfg.exact_output)
ret = False
for network_id in network_ids:
d = CoinDaemon(cfg, network_id=network_id, test_suite=True)
d = CoinDaemon(cfg, network_id=network_id)
if remove_datadir:
d.wait = True
d.stop(silent=True)

View file

@ -29,6 +29,7 @@ for k, v in {
### everything below is missing in Config:
# these are referenced in production code:
'test_suite': True,
'test_suite_cfgtest': False, # cfgfile - using getattr() with dfl val - OK
'test_suite_popen_spawn': False, # line_input() - using getattr() with dfl val - OK
'test_suite_hold_protect_disable': False, # init_term() - using getattr() with dfl val - OK