From a93173f43cf5f0e1a9c9dac776db3b820438b1dc Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 28 May 2025 11:40:40 +0000 Subject: [PATCH] test suite: clean up `swap_server_stop()` --- test/cmdtest_d/ethbump.py | 8 ++++++-- test/cmdtest_d/ethswap.py | 13 +++---------- test/cmdtest_d/swap.py | 19 ++++++++++++------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/test/cmdtest_d/ethbump.py b/test/cmdtest_d/ethbump.py index cfbde706..eb18540b 100755 --- a/test/cmdtest_d/ethbump.py +++ b/test/cmdtest_d/ethbump.py @@ -29,7 +29,6 @@ from .regtest import CmdTestRegtest from .swap import CmdTestSwapMethods from .ethswap import CmdTestEthSwapMethods -swap_server = ThornodeSwapServer() burn_addr = 'beefcafe22' * 4 method_template = """ def {name}(self): @@ -139,6 +138,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', 'stopping daemon'), ) cmd_subgroups = { @@ -292,7 +292,8 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe ethbump_ltc = CmdTestRunner(cfg, t.repo_root, t.data_dir, t.trash_dir, t.trash_dir2) ethbump_ltc.init_group('ethbump_ltc') - swap_server.start() + self.swap_server = ThornodeSwapServer() + self.swap_server.start() def txcreate1(self): return self._txcreate(args=[f'{burn_addr},987'], acct='1') @@ -441,6 +442,9 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe token_swaptxbump1sign = token_swaptxbump2sign = swaptxbump1sign = swaptxbump2sign = token_txbump2sign token_swaptxbump1send = token_swaptxbump2send = swaptxbump1send = swaptxbump2send = token_txbump2send + def swap_server_stop(self): + return self._thornode_server_stop() + class CmdTestEthBumpLTC(CmdTestSwapMethods, CmdTestRegtest): network = ('ltc',) tmpdir_nums = [43] diff --git a/test/cmdtest_d/ethswap.py b/test/cmdtest_d/ethswap.py index 4337f46b..f63a7ad5 100755 --- a/test/cmdtest_d/ethswap.py +++ b/test/cmdtest_d/ethswap.py @@ -29,8 +29,6 @@ from .regtest import CmdTestRegtest from .swap import CmdTestSwapMethods from .ethdev import CmdTestEthdev -swap_server = ThornodeSwapServer() - method_template = """ def {name}(self): self.spawn(log_only=True) @@ -281,7 +279,8 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): ethswap_eth = CmdTestRunner(cfg, t.repo_root, t.data_dir, t.trash_dir, t.trash_dir2) ethswap_eth.init_group(self.eth_group) - swap_server.start() + self.swap_server = ThornodeSwapServer() + self.swap_server.start() def swaptxcreate1(self): t = self._swaptxcreate(['BTC', '8.765', 'ETH']) @@ -327,13 +326,7 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): return self._swaptxcreate_ui_common(t) def swap_server_stop(self): - self.spawn(msg_only=True) - if self.cfg.no_daemon_stop: - msg_r('(leaving thornode server running by user request)') - imsg('') - else: - swap_server.stop() - return 'ok' + return self._thornode_server_stop() class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev): 'Ethereum swap operations - Ethereum wallet' diff --git a/test/cmdtest_d/swap.py b/test/cmdtest_d/swap.py index 1993709b..68dfe351 100755 --- a/test/cmdtest_d/swap.py +++ b/test/cmdtest_d/swap.py @@ -17,15 +17,13 @@ from pathlib import Path from mmgen.protocol import init_proto from mmgen.wallet.mmgen import wallet as MMGenWallet -from ..include.common import make_burn_addr, gr_uc +from ..include.common import imsg, make_burn_addr, gr_uc from .include.common import dfl_bip39_file, dfl_words_file from .httpd.thornode_swap import ThornodeSwapServer from .autosign import CmdTestAutosign, CmdTestAutosignThreaded from .regtest import CmdTestRegtest, rt_data, dfl_wcls, rt_pw, strip_ansi_escapes -swap_server = ThornodeSwapServer() - sample1 = gr_uc[:24] sample2 = '00010203040506' @@ -262,6 +260,14 @@ class CmdTestSwapMethods: assert data return 'ok' + 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' + class CmdTestSwap(CmdTestSwapMethods, CmdTestRegtest, CmdTestAutosignThreaded): bdb_wallet = True networks = ('btc',) @@ -408,7 +414,8 @@ class CmdTestSwap(CmdTestSwapMethods, CmdTestRegtest, CmdTestAutosignThreaded): self.protos = [init_proto(cfg, k, network='regtest', need_amt=True) for k in ('btc', 'ltc', 'bch')] - swap_server.start() + self.swap_server = ThornodeSwapServer() + self.swap_server.start() self.opts.append('--bob') @@ -777,6 +784,4 @@ class CmdTestSwap(CmdTestSwapMethods, CmdTestRegtest, CmdTestAutosignThreaded): return self._mempool(2) def swap_server_stop(self): - self.spawn(msg_only=True) - swap_server.stop() - return 'ok' + return self._thornode_server_stop()