From c0af5bc2b59f0731fc7195536c2fb09db3ad8e09 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 25 Oct 2026 10:11:14 +0000 Subject: [PATCH] test suite thornode: improve inbound address creation --- test/cmdtest_d/ethswap.py | 5 ++++- test/cmdtest_d/httpd/thornode/__init__.py | 19 +++++++++++++++++++ test/cmdtest_d/httpd/thornode/rpc.py | 7 +++++-- test/cmdtest_d/httpd/thornode/swap.py | 18 +++--------------- test/cmdtest_d/include/common.py | 2 -- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/test/cmdtest_d/ethswap.py b/test/cmdtest_d/ethswap.py index a1e132db..c41f9196 100644 --- a/test/cmdtest_d/ethswap.py +++ b/test/cmdtest_d/ethswap.py @@ -17,12 +17,15 @@ from mmgen.fileutil import get_data_from_file from ..include.common import imsg, chk_equal -from .include.common import dfl_sid, eth_inbound_addr, thorchain_router_addr_file +from .include.common import dfl_sid, thorchain_router_addr_file from .include.proxy import TestProxy from .regtest import CmdTestRegtest from .swap import CmdTestSwapMethods, create_cross_methods from .ethdev import CmdTestEthdev +from .httpd.thornode import make_inbound_addr + +eth_inbound_addr = make_inbound_addr('ETH').removeprefix('0x') class CmdTestEthSwapMethods: diff --git a/test/cmdtest_d/httpd/thornode/__init__.py b/test/cmdtest_d/httpd/thornode/__init__.py index ae66adfa..c505ffb2 100644 --- a/test/cmdtest_d/httpd/thornode/__init__.py +++ b/test/cmdtest_d/httpd/thornode/__init__.py @@ -10,8 +10,27 @@ test.cmdtest_d.httpd.thornode: Thornode WSGI HTTP server """ +import time + +from mmgen.cfg import Config + from .. import HTTPD +day = int(time.time() // (24 * 60 * 60)) +cfg = Config() + +def make_inbound_addr(coin): + from mmgen.protocol import init_proto + from mmgen.tool.coin import tool_cmd + proto = init_proto(cfg, coin, network='regtest', need_amt=True) + n = (day + int('beadcafe' * 8, 16)) % (2 ** 256) # address changes every 24 hours + ret = tool_cmd( + cfg = cfg, + cmdname = 'privhex2addr', + proto = proto, + mmtype = proto.preferred_mmtypes[0]).privhex2addr(f'{n:064x}') + return ('0x' + ret) if coin.upper() == 'ETH' else ret.views[0] + class ThornodeServer(HTTPD): name = 'thornode server' content_type = 'application/json' diff --git a/test/cmdtest_d/httpd/thornode/rpc.py b/test/cmdtest_d/httpd/thornode/rpc.py index 0cc17da6..0db0250b 100644 --- a/test/cmdtest_d/httpd/thornode/rpc.py +++ b/test/cmdtest_d/httpd/thornode/rpc.py @@ -15,11 +15,14 @@ from wsgiref.util import request_uri from mmgen.cfg import Config -from . import ThornodeServer +from . import ThornodeServer, make_inbound_addr def get_inbounds_info(): with open('test/ref/thorchain/inbound.json') as fh: - return json.loads(fh.read()) + data = json.loads(fh.read()) + for d in data: + d['address'] = make_inbound_addr(d['chain']) + return data class ThornodeRPCServer(ThornodeServer): port = 18800 diff --git a/test/cmdtest_d/httpd/thornode/swap.py b/test/cmdtest_d/httpd/thornode/swap.py index 0ebc3fbb..b3b43fa3 100644 --- a/test/cmdtest_d/httpd/thornode/swap.py +++ b/test/cmdtest_d/httpd/thornode/swap.py @@ -16,9 +16,9 @@ from wsgiref.util import request_uri from mmgen.amt import UniAmt from mmgen.protocol import init_proto -from ...include.common import eth_inbound_addr, thorchain_router_addr_file +from ...include.common import thorchain_router_addr_file -from . import ThornodeServer +from . import ThornodeServer, make_inbound_addr # https://thornode.ninerealms.com/thorchain/quote/swap?from_asset=BCH.BCH&to_asset=LTC.LTC&amount=1000000 prices = { @@ -127,18 +127,6 @@ data_template_eth = { 'total_swap_seconds': 24 } -def make_inbound_addr(cfg, proto, mmtype): - if proto.is_evm: - return '0x' + eth_inbound_addr # non-checksummed as per ninerealms thornode - else: - from mmgen.tool.coin import tool_cmd - n = int(time.time()) // (60 * 60 * 24) + int('beadcafe' * 8, 16) # increments once every 24 hrs - return tool_cmd( - cfg = cfg, - cmdname = 'privhex2addr', - proto = proto, - mmtype = mmtype).privhex2addr(f'{n:064x}') - class ThornodeSwapServer(ThornodeServer): port = 18900 name = 'thornode swap server' @@ -166,7 +154,7 @@ class ThornodeSwapServer(ThornodeServer): if send_asset != 'RUNE': send_proto = init_proto(self.cfg, send_chain, network='regtest', need_amt=True) data.update({ - 'inbound_address': make_inbound_addr(self.cfg, send_proto, send_proto.preferred_mmtypes[0]), + 'inbound_address': make_inbound_addr(send_chain), 'gas_rate_units': gas_rate_units[send_proto.base_proto_coin], 'recommended_gas_rate': recommended_gas_rate[send_proto.base_proto_coin]}) diff --git a/test/cmdtest_d/include/common.py b/test/cmdtest_d/include/common.py index 84e76b97..7586aa4f 100644 --- a/test/cmdtest_d/include/common.py +++ b/test/cmdtest_d/include/common.py @@ -70,8 +70,6 @@ chksum_pat = r'\b[A-F0-9]{4} [A-F0-9]{4} [A-F0-9]{4} [A-F0-9]{4}\b' Ctrl_U = '\x15' -eth_inbound_addr = (28 * '0') + 'feedbeefcafe' - thorchain_router_addr_file = os.path.join(cfg.test_datadir, 'thorchain_router_addr') def ok_msg():