From 771463f286b761d791a3b9b79d21830466839a9a Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 15 Jun 2025 09:17:02 +0000 Subject: [PATCH] cmdtest swap: new `cross_coin`, `cross_group` attributes --- test/cmdtest_d/ethbump.py | 22 +++++----------------- test/cmdtest_d/ethswap.py | 34 +++++++--------------------------- test/cmdtest_d/swap.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/test/cmdtest_d/ethbump.py b/test/cmdtest_d/ethbump.py index ee89e131..48a49822 100755 --- a/test/cmdtest_d/ethbump.py +++ b/test/cmdtest_d/ethbump.py @@ -26,7 +26,7 @@ from .httpd.thornode.swap import ThornodeSwapServer from .ethdev import CmdTestEthdev, CmdTestEthdevMethods from .regtest import CmdTestRegtest -from .swap import CmdTestSwapMethods +from .swap import CmdTestSwapMethods, create_cross_methods from .ethswap import CmdTestEthSwapMethods burn_addr = 'beefcafe22' * 4 @@ -123,6 +123,8 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe dfl_devnet_block_period = {'geth': 7, 'reth': 9} fund_amt = 100000 token_fund_amt = 1000 + cross_group = 'ethbump_ltc' + cross_coin = 'ltc' cmd_group_in = ( ('subgroup.ltc_init', []), @@ -262,10 +264,7 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe ), } - ltc_tests = [c[0] for v in tuple(cmd_subgroups.values()) + (cmd_group_in,) - for c in v if isinstance(c, tuple) and c[0].startswith('ltc_')] - - exec(''.join(method_template.format(name=k, ltc_name=k.removeprefix('ltc_')) for k in ltc_tests)) + exec(create_cross_methods(cross_coin, cross_group, cmd_group_in, cmd_subgroups)) def __init__(self, cfg, trunner, cfgs, spawn): @@ -279,18 +278,7 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe 'geth': [f'--dev.period={self.devnet_block_period}'] }[self.daemon.id] - global ethbump_ltc - cfg = Config({ - '_clone': trunner.cfg, - 'coin': 'ltc', - 'resume': None, - 'resuming': None, - 'resume_after': None, - 'exit_after': None, - 'log': None}) - t = trunner - ethbump_ltc = CmdTestRunner(cfg, t.repo_root, t.data_dir, t.trash_dir, t.trash_dir2) - ethbump_ltc.init_group('ethbump_ltc') + globals()[self.cross_group] = self.create_cross_runner(trunner) self.swap_server = ThornodeSwapServer() self.swap_server.start() diff --git a/test/cmdtest_d/ethswap.py b/test/cmdtest_d/ethswap.py index 3c20079c..34556511 100755 --- a/test/cmdtest_d/ethswap.py +++ b/test/cmdtest_d/ethswap.py @@ -14,27 +14,19 @@ test.cmdtest_d.ethswap: Ethereum swap tests for the cmdtest.py test suite from subprocess import run, PIPE, DEVNULL -from mmgen.cfg import Config from mmgen.util import msg_r, rmsg, die from mmgen.protocol import init_proto from mmgen.fileutil import get_data_from_file from ..include.common import imsg, chk_equal -from .include.runner import CmdTestRunner from .include.common import dfl_sid, eth_inbound_addr, thorchain_router_addr_file from .httpd.thornode.swap import ThornodeSwapServer from .regtest import CmdTestRegtest -from .swap import CmdTestSwapMethods +from .swap import CmdTestSwapMethods, create_cross_methods from .ethdev import CmdTestEthdev -method_template = """ -def {name}(self): - self.spawn(log_only=True) - return ethswap_eth.run_test("{eth_name}", sub=True) -""" - class CmdTestEthSwapMethods: async def token_deploy_a(self): @@ -132,7 +124,8 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): tmpdir_nums = [47] networks = ('btc',) passthru_opts = ('coin', 'rpc_backend', 'eth_daemon_id') - eth_group = 'ethswap_eth' + cross_group = 'ethswap_eth' + cross_coin = 'eth' cmd_group_in = ( ('setup', 'regtest (Bob and Alice) mode setup'), @@ -253,10 +246,7 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): ), } - eth_tests = [c[0] for v in tuple(cmd_subgroups.values()) + (cmd_group_in,) - for c in v if isinstance(c, tuple) and c[0].startswith('eth_')] - - exec(''.join(method_template.format(name=k, eth_name=k.removeprefix('eth_')) for k in eth_tests)) + exec(create_cross_methods(cross_coin, cross_group, cmd_group_in, cmd_subgroups)) def __init__(self, cfg, trunner, cfgs, spawn): @@ -265,19 +255,9 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): if not trunner: return - global ethswap_eth - cfg = Config({ - '_clone': trunner.cfg, - 'coin': 'eth', - 'eth_daemon_id': trunner.cfg.eth_daemon_id, - 'resume': None, - 'resuming': None, - 'resume_after': None, - 'exit_after': None, - 'log': None}) - t = trunner - ethswap_eth = CmdTestRunner(cfg, t.repo_root, t.data_dir, t.trash_dir, t.trash_dir2) - ethswap_eth.init_group(self.eth_group) + globals()[self.cross_group] = self.create_cross_runner( + trunner, + add_cfg = {'eth_daemon_id': trunner.cfg.eth_daemon_id}) self.swap_server = ThornodeSwapServer() self.swap_server.start() diff --git a/test/cmdtest_d/swap.py b/test/cmdtest_d/swap.py index 06d0b10a..966d982d 100755 --- a/test/cmdtest_d/swap.py +++ b/test/cmdtest_d/swap.py @@ -14,10 +14,13 @@ test.cmdtest_d.swap: asset swap tests for the cmdtest.py test suite from pathlib import Path +from mmgen.cfg import Config from mmgen.protocol import init_proto from mmgen.wallet.mmgen import wallet as MMGenWallet from ..include.common import imsg, make_burn_addr, gr_uc + +from .include.runner import CmdTestRunner from .include.common import dfl_bip39_file, dfl_words_file from .httpd.thornode.swap import ThornodeSwapServer @@ -27,6 +30,23 @@ from .regtest import CmdTestRegtest, rt_data, dfl_wcls, rt_pw, strip_ansi_escape sample1 = gr_uc[:24] sample2 = '00010203040506' +def create_cross_methods(cross_coin, cross_group, cmd_group_in, cmd_subgroups): + + method_template = """ +def {name}(self): + self.spawn(log_only=True) + return {group}.run_test("{method_name}", sub=True) +""" + + tests = [c[0] for v in tuple(cmd_subgroups.values()) + (cmd_group_in,) + for c in v if isinstance(c, tuple) and c[0].startswith(f'{cross_coin}_')] + + return ''.join(method_template.format( + name = k, + method_name = k.removeprefix(f'{cross_coin}_'), + group = cross_group) + for k in tests) + class CmdTestSwapMethods: @property @@ -268,6 +288,20 @@ class CmdTestSwapMethods: getattr(self, attrname).stop() return 'ok' + def create_cross_runner(self, trunner, *, add_cfg={}): + cfg = Config({ + '_clone': trunner.cfg, + 'coin': self.cross_coin, + 'resume': None, + 'resuming': None, + 'resume_after': None, + 'exit_after': None, + 'log': None} | add_cfg) + t = trunner + ret = CmdTestRunner(cfg, t.repo_root, t.data_dir, t.trash_dir, t.trash_dir2) + ret.init_group(self.cross_group) + return ret + class CmdTestSwap(CmdTestSwapMethods, CmdTestRegtest, CmdTestAutosignThreaded): bdb_wallet = True networks = ('btc',)