test suite thornode: improve inbound address creation

This commit is contained in:
The MMGen Project 2026-10-25 10:11:14 +00:00
commit c0af5bc2b5
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 31 additions and 20 deletions

View file

@ -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:

View file

@ -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'

View file

@ -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

View file

@ -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]})

View file

@ -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():