From 68d1d2e812d31c145e94e94c3506755b17036cf2 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 2 Oct 2026 10:02:32 +0000 Subject: [PATCH] cmdtest_d.swap: new `start_thornode_servers()` method --- test/cmdtest_d/ethbump.py | 7 +++--- test/cmdtest_d/ethswap.py | 7 +++--- test/cmdtest_d/rune.py | 20 +++++++++------- test/cmdtest_d/runeswap.py | 11 +++++---- test/cmdtest_d/swap.py | 49 ++++++++++++++++++++++---------------- 5 files changed, 53 insertions(+), 41 deletions(-) diff --git a/test/cmdtest_d/ethbump.py b/test/cmdtest_d/ethbump.py index 5c68cfaa..389293f3 100755 --- a/test/cmdtest_d/ethbump.py +++ b/test/cmdtest_d/ethbump.py @@ -19,7 +19,6 @@ from mmgen.util import ymsg, suf from ..include.common import imsg, omsg_r from .include.common import cleanup_env, dfl_words_file, dfl_sid -from .httpd.thornode.swap import ThornodeSwapServer from .ethdev import CmdTestEthdev from .regtest import CmdTestRegtest @@ -120,6 +119,7 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe networks = ('eth',) tmpdir_nums = [42] + thornode_servers = ('swap',) dfl_devnet_block_period = {'geth': 7, 'reth': 9} fund_amt = 100000 token_fund_amt = 1000 @@ -141,7 +141,7 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe # ('subgroup.token_feebump_swap', ['token_init_swap']), # TBD ('subgroup.token_new_outputs_swap', ['token_init_swap']), ('ltc_stop', ''), - ('swap_server_stop', 'stopping the Thornode server'), + ('stop_thornode_servers', 'stopping the Thornode swap server'), ('stop', 'stopping daemon')) cmd_subgroups = { @@ -283,8 +283,7 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe globals()[self.cross_group] = self.create_cross_runner(trunner) - self.swap_server = ThornodeSwapServer(cfg) - self.swap_server.start() + self.start_thornode_servers() def txcreate1(self): return self._txcreate(args=[f'{burn_addr},987'], acct='1') diff --git a/test/cmdtest_d/ethswap.py b/test/cmdtest_d/ethswap.py index b766a6da..ba2851cd 100755 --- a/test/cmdtest_d/ethswap.py +++ b/test/cmdtest_d/ethswap.py @@ -21,7 +21,6 @@ from ..include.common import imsg, chk_equal from .include.common import dfl_sid, eth_inbound_addr, thorchain_router_addr_file from .include.proxy import TestProxy -from .httpd.thornode.swap import ThornodeSwapServer from .regtest import CmdTestRegtest from .swap import CmdTestSwapMethods, create_cross_methods @@ -124,6 +123,7 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): bdb_wallet = True tmpdir_nums = [47] networks = ('btc',) + thornode_servers = ('swap',) passthru_opts = ('coin', 'rpc_backend', 'eth_daemon_id') cross_group = 'ethswap_eth' cross_coin = 'eth' @@ -140,7 +140,7 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): ('subgroup.token_init', ['eth_fund']), ('subgroup.token_swap', ['fund', 'token_init']), ('subgroup.eth_token_swap', ['fund', 'token_init']), - ('swap_server_stop', 'stopping the Thornode server'), + ('stop_thornode_servers', 'stopping the Thornode swap server'), ('eth_stop', 'stopping the Ethereum daemon'), ('stop', 'stopping the regtest daemon')) @@ -259,8 +259,7 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): trunner, add_cfg = {'eth_daemon_id': trunner.cfg.eth_daemon_id}) - self.swap_server = ThornodeSwapServer(cfg) - self.swap_server.start() + self.start_thornode_servers() TestProxy(self, cfg) diff --git a/test/cmdtest_d/rune.py b/test/cmdtest_d/rune.py index 7d50fa43..ff5c3431 100755 --- a/test/cmdtest_d/rune.py +++ b/test/cmdtest_d/rune.py @@ -16,9 +16,9 @@ from hashlib import md5 from mmgen.fileutil import get_data_from_file +from ..include.common import imsg from .include.common import dfl_words_file from .include.proxy import TestProxy -from .httpd.thornode.rpc import ThornodeRPCServer from .ethdev import CmdTestEthdevMethods from .base import CmdTestBase from .shared import CmdTestShared @@ -83,6 +83,7 @@ class CmdTestRune(CmdTestRuneMethods, CmdTestEthdevMethods, CmdTestBase, CmdTest networks = ('rune',) passthru_opts = ('coin', 'http_timeout') tmpdir_nums = [50] + thornode_servers = ('rpc',) color = True menu_prompt = 'efresh balance:\b' txhex_chksum = '83f85785' @@ -90,7 +91,7 @@ class CmdTestRune(CmdTestRuneMethods, CmdTestEthdevMethods, CmdTestBase, CmdTest cmd_group_in = ( ('subgroup.init', []), ('subgroup.main', ['init']), - ('rpc_server_stop', 'stopping the Thornode RPC server')) + ('stop_thornode_servers', 'stopping the Thornode RPC server')) cmd_subgroups = { 'init': ( @@ -123,13 +124,20 @@ class CmdTestRune(CmdTestRuneMethods, CmdTestEthdevMethods, CmdTestBase, CmdTest self.proto = init_proto(cfg, network_id=self.proto.coin + '_rt', need_amt=True) self.spawn_env['MMGEN_TEST_SUITE_BOGUS_SEND'] = '' - self.rpc_server = ThornodeRPCServer(cfg) - self.rpc_server.start() + self.start_thornode_servers() TestProxy(self, cfg) self.txhex_file = f'{self.tmpdir}/tx_dump.hex' + def start_thornode_servers(self): + from .swap import CmdTestSwapMethods + return CmdTestSwapMethods.start_thornode_servers(self) + + def stop_thornode_servers(self): + from .swap import CmdTestSwapMethods + return CmdTestSwapMethods.stop_thornode_servers(self) + def addrgen(self): return self._addrgen() @@ -159,7 +167,3 @@ class CmdTestRune(CmdTestRuneMethods, CmdTestEthdevMethods, CmdTestBase, CmdTest if md5(txhex.encode()).hexdigest()[:8] != self.txhex_chksum: self.tr.warn('txid mismatch') return t - - def rpc_server_stop(self): - from .swap import CmdTestSwapMethods - return CmdTestSwapMethods.rpc_server_stop(self) diff --git a/test/cmdtest_d/runeswap.py b/test/cmdtest_d/runeswap.py index b79d232b..efdc9bbc 100755 --- a/test/cmdtest_d/runeswap.py +++ b/test/cmdtest_d/runeswap.py @@ -29,6 +29,7 @@ class CmdTestRuneSwap(CmdTestSwapMethods, CmdTestRegtest): bdb_wallet = True tmpdir_nums = [57] networks = ('ltc',) + thornode_servers = ('swap',) passthru_opts = ('coin', 'rpc_backend') cross_group = 'runeswap_rune' cross_coin = 'rune' @@ -38,8 +39,8 @@ class CmdTestRuneSwap(CmdTestSwapMethods, CmdTestRegtest): ('subgroup.init', []), ('subgroup.rune_init', ['init']), ('subgroup.rune_swap', ['rune_init']), - ('rune_rpc_server_stop', 'stopping the Thornode RPC server'), - ('swap_server_stop', 'stopping the Thornode swap server'), + ('rune_stop_thornode_servers', 'stopping the Thornode swap server'), + ('stop_thornode_servers','stopping the Thornode RPC server'), ('stop', 'stopping the regtest daemon')) cmd_subgroups = { @@ -77,8 +78,7 @@ class CmdTestRuneSwap(CmdTestSwapMethods, CmdTestRegtest): globals()[self.cross_group] = self.create_cross_runner(trunner) - self.swap_server = ThornodeSwapServer(cfg) - self.swap_server.start() + self.start_thornode_servers() TestProxy(self, cfg) @@ -87,6 +87,7 @@ class CmdTestRuneSwapRune(CmdTestSwapMethods, CmdTestRune): networks = ('rune',) tmpdir_nums = [58] + thornode_servers = ('rpc',) input_sels_prompt = 'to spend from: ' is_helper = True txhex_chksum = '0b84cb00' @@ -100,7 +101,7 @@ class CmdTestRuneSwapRune(CmdTestSwapMethods, CmdTestRune): ('swaptxstatus1', 'getting the transaction status'), ('swaptxreceipt1', 'getting the transaction receipt'), ('swaptxhex1', 'dumping the transaction hex'), - ('thornode_server_stop', 'stopping Thornode server')) + ('stop_thornode_servers', 'stopping the Thornode RPC server')) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/test/cmdtest_d/swap.py b/test/cmdtest_d/swap.py index b0286401..95f0fdf9 100755 --- a/test/cmdtest_d/swap.py +++ b/test/cmdtest_d/swap.py @@ -20,26 +20,18 @@ from mmgen.protocol import init_proto from mmgen.wallet.mmgen import wallet as MMGenWallet from mmgen.tx.file import txfile_json_dumps # pylint: disable=no-name-in-module -from ..include.common import imsg, make_burn_addr, gr_uc +from ..include.common import make_burn_addr, gr_uc from .include.runner import CmdTestRunner from .include.common import dfl_words_file -from .httpd.thornode.swap import ThornodeSwapServer from .autosign import CmdTestAutosign, CmdTestAutosignThreaded from .regtest import CmdTestRegtest, dfl_wcls, rt_pw, strip_ansi_escapes +from .rune import CmdTestRuneMethods sample1 = gr_uc[:24] sample2 = '00010203040506' -def thornode_server_stop(self, attrname='swap_server', name='thornode swap server'): - self.spawn(msg_only=True) - if self.cfg.no_daemon_stop: - imsg(f'(leaving {name} running by user request)') - else: - getattr(self, attrname).stop() - return 'ok' - def create_cross_methods(cross_coin, cross_group, cmd_group_in, cmd_subgroups): method_template = """ @@ -249,12 +241,6 @@ class CmdTestSwapMethods: assert data return 'ok' - def swap_server_stop(self): - return thornode_server_stop(self) - - def rpc_server_stop(self): - return thornode_server_stop(self, attrname='rpc_server', name='Thornode RPC server') - def create_cross_runner(self, trunner, *, add_cfg={}): cfg = Config({ '_clone': trunner.cfg, @@ -270,8 +256,31 @@ class CmdTestSwapMethods: ret.parent_group = self return ret + def start_thornode_servers(self): + import importlib + pkg = 'test.cmdtest_d.httpd.thornode' + d = { + 'rpc': 'ThornodeRPCServer', + 'swap': 'ThornodeSwapServer', + 'midgard': 'ThornodeMidgardServer'} + for name in self.thornode_servers: + cls = getattr(importlib.import_module(f'{pkg}.{name}'), d[name]) + attr = f'{name}_server' + setattr(self, attr, cls(self.cfg)) + getattr(self, attr).start() + + def stop_thornode_servers(self): + self.spawn(msg_only=True) + for name in self.thornode_servers: + if self.cfg.no_daemon_stop: + imsg(f'(leaving Thornode {name} server running by user request)') + else: + getattr(self, f'{name}_server').stop() + return 'ok' + class CmdTestSwap( CmdTestSwapMethods, + CmdTestRuneMethods, CmdTestRegtest, CmdTestAutosignThreaded): 'swap operations (LTC <=> BCH)' @@ -279,6 +288,7 @@ class CmdTestSwap( bdb_wallet = True networks = ('btc',) tmpdir_nums = [37] + thornode_servers = ('rpc', 'swap') passthru_opts = ('rpc_backend',) coins = ['bch', 'ltc'] daemon_coins = ['bch', 'ltc'] @@ -292,7 +302,7 @@ class CmdTestSwap( ('subgroup.signsend', ['init_swap']), ('subgroup.signsend_bad', ['init_swap']), ('subgroup.autosign', ['signsend']), - ('swap_server_stop', 'stopping the Thornode swap server'), + ('stop_thornode_servers', 'stopping the Thornode RPC and swap servers'), ('stop', 'stopping regtest daemons')) cmd_subgroups = { @@ -393,11 +403,10 @@ class CmdTestSwap( self.protos = [init_proto(cfg, k, network='regtest', need_amt=True) for k in ('ltc', 'bch')] - self.swap_server = ThornodeSwapServer(cfg) - self.swap_server.start() - self.opts.append('--bob') + self.start_thornode_servers() + @property def sid(self): return self._user_sid('bob')