new test.cmdtest_d.httpd.thornode package

This commit is contained in:
The MMGen Project 2025-06-04 15:35:42 +03:00
commit 2bf4f540f7
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
8 changed files with 44 additions and 24 deletions

View file

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

View file

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

View file

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

View file

@ -0,0 +1,20 @@
#!/usr/bin/env python3
#
# MMGen Wallet, a terminal-based cryptocurrency wallet
# Copyright (C)2013-2025 The MMGen Project <mmgen@tuta.io>
# 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'

View file

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

View file

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

View file

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

View file

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