From 2bf4f540f77ea25f6b134fe63071d947ba9a572b Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 4 Jun 2025 15:35:42 +0300 Subject: [PATCH] new `test.cmdtest_d.httpd.thornode` package --- MANIFEST.in | 1 + test/cmdtest_d/ethbump.py | 2 +- test/cmdtest_d/ethswap.py | 2 +- test/cmdtest_d/httpd/thornode/__init__.py | 20 +++++++++++++ .../httpd/{thornode.py => thornode/rpc.py} | 30 +++++++++---------- .../{thornode_swap.py => thornode/swap.py} | 7 ++--- test/cmdtest_d/rune.py | 4 +-- test/cmdtest_d/swap.py | 2 +- 8 files changed, 44 insertions(+), 24 deletions(-) create mode 100755 test/cmdtest_d/httpd/thornode/__init__.py rename test/cmdtest_d/httpd/{thornode.py => thornode/rpc.py} (51%) rename test/cmdtest_d/httpd/{thornode_swap.py => thornode/swap.py} (96%) diff --git a/MANIFEST.in b/MANIFEST.in index 5d490c27..10bd56fa 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -14,6 +14,7 @@ include nix/* include test/*.py include test/*/*.py include test/*/*/*.py +include test/*/*/*/*.py include test/ref/* include test/ref/*/* include test/ref/*/*/* diff --git a/test/cmdtest_d/ethbump.py b/test/cmdtest_d/ethbump.py index eb18540b..ee89e131 100755 --- a/test/cmdtest_d/ethbump.py +++ b/test/cmdtest_d/ethbump.py @@ -22,7 +22,7 @@ from ..include.common import imsg, omsg_r from .include.common import cleanup_env, dfl_words_file, dfl_sid from .include.runner import CmdTestRunner -from .httpd.thornode_swap import ThornodeSwapServer +from .httpd.thornode.swap import ThornodeSwapServer from .ethdev import CmdTestEthdev, CmdTestEthdevMethods from .regtest import CmdTestRegtest diff --git a/test/cmdtest_d/ethswap.py b/test/cmdtest_d/ethswap.py index f63a7ad5..3c20079c 100755 --- a/test/cmdtest_d/ethswap.py +++ b/test/cmdtest_d/ethswap.py @@ -23,7 +23,7 @@ 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 .httpd.thornode.swap import ThornodeSwapServer from .regtest import CmdTestRegtest from .swap import CmdTestSwapMethods diff --git a/test/cmdtest_d/httpd/thornode/__init__.py b/test/cmdtest_d/httpd/thornode/__init__.py new file mode 100755 index 00000000..47bc6df5 --- /dev/null +++ b/test/cmdtest_d/httpd/thornode/__init__.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# +# MMGen Wallet, a terminal-based cryptocurrency wallet +# Copyright (C)2013-2025 The MMGen Project +# Licensed under the GNU General Public License, Version 3: +# https://www.gnu.org/licenses +# Public project repositories: +# https://github.com/mmgen/mmgen-wallet +# https://gitlab.com/mmgen/mmgen-wallet + +""" +test.cmdtest_d.httpd.thornode: Thornode WSGI HTTP server +""" + +from .. import HTTPD + +class ThornodeServer(HTTPD): + name = 'thornode server' + port = 18800 + content_type = 'application/json' diff --git a/test/cmdtest_d/httpd/thornode.py b/test/cmdtest_d/httpd/thornode/rpc.py similarity index 51% rename from test/cmdtest_d/httpd/thornode.py rename to test/cmdtest_d/httpd/thornode/rpc.py index 10842d30..0b86e7e9 100755 --- a/test/cmdtest_d/httpd/thornode.py +++ b/test/cmdtest_d/httpd/thornode/rpc.py @@ -9,28 +9,28 @@ # https://gitlab.com/mmgen/mmgen-wallet """ -test.cmdtest_d.httpd.thornode: Thornode WSGI http server +test.cmdtest_d.httpd.thornode.rpc: Thornode RPC HTTP server """ import re, json from wsgiref.util import request_uri -from . import HTTPD +from . import ThornodeServer -class ThornodeServer(HTTPD): - name = 'thornode server' - port = 18800 - content_type = 'application/json' - request_pat = r'/bank/balances/(\S+)' +class ThornodeRPCServer(ThornodeServer): + name = 'thornode RPC server' def make_response_body(self, method, environ): req_str = request_uri(environ) - m = re.search(self.request_pat, req_str) - assert m[1], f'‘{req_str}’: malformed query path' - data = { - 'result': [ - {'denom': 'foocoin', 'amount': 321321321321}, - {'denom': 'rune', 'amount': 987654321321}, - {'denom': 'barcoin', 'amount': 123123123123}, - ]} + + if re.search(r'/bank/balances/(\S+)', req_str): + data = { + 'result': [ + {'denom': 'foocoin', 'amount': 321321321321}, + {'denom': 'rune', 'amount': 987654321321}, + {'denom': 'barcoin', 'amount': 123123123123}, + ]} + else: + raise ValueError(f'‘{req_str}’: malformed query path') + return json.dumps(data).encode() diff --git a/test/cmdtest_d/httpd/thornode_swap.py b/test/cmdtest_d/httpd/thornode/swap.py similarity index 96% rename from test/cmdtest_d/httpd/thornode_swap.py rename to test/cmdtest_d/httpd/thornode/swap.py index e55aa15b..97904655 100755 --- a/test/cmdtest_d/httpd/thornode_swap.py +++ b/test/cmdtest_d/httpd/thornode/swap.py @@ -9,7 +9,7 @@ # https://gitlab.com/mmgen/mmgen-wallet """ -test.cmdtest_d.httpd.thornode_swap: Thornode swap WSGI http server +test.cmdtest_d.httpd.thornode.swap: Thornode swap HTTP server """ import time, re, json @@ -19,10 +19,9 @@ from mmgen.cfg import Config 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 eth_inbound_addr, thorchain_router_addr_file -from . import HTTPD -from .thornode import ThornodeServer +from . import ThornodeServer cfg = Config() diff --git a/test/cmdtest_d/rune.py b/test/cmdtest_d/rune.py index 5b8677ec..23fdf0c5 100755 --- a/test/cmdtest_d/rune.py +++ b/test/cmdtest_d/rune.py @@ -13,7 +13,7 @@ test.cmdtest_d.rune: THORChain RUNE tests for the cmdtest.py test suite """ from .include.common import dfl_sid -from .httpd.thornode import ThornodeServer +from .httpd.thornode.rpc import ThornodeRPCServer from .ethdev import CmdTestEthdevMethods from .base import CmdTestBase from .shared import CmdTestShared @@ -59,7 +59,7 @@ class CmdTestRune(CmdTestEthdevMethods, CmdTestBase, CmdTestShared): self.proto = init_proto(cfg, network_id=self.proto.coin + '_rt', need_amt=True) self.spawn_env['MMGEN_BOGUS_SEND'] = '' - self.thornode_server = ThornodeServer() + self.thornode_server = ThornodeRPCServer() self.thornode_server.start() def addrgen(self): diff --git a/test/cmdtest_d/swap.py b/test/cmdtest_d/swap.py index 68dfe351..fa9d907b 100755 --- a/test/cmdtest_d/swap.py +++ b/test/cmdtest_d/swap.py @@ -19,7 +19,7 @@ from mmgen.wallet.mmgen import wallet as MMGenWallet 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 .httpd.thornode.swap import ThornodeSwapServer from .autosign import CmdTestAutosign, CmdTestAutosignThreaded from .regtest import CmdTestRegtest, rt_data, dfl_wcls, rt_pw, strip_ansi_escapes