From 55dfcb8f8df53041c8f429680441b9c80e2c3324 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 2 Oct 2026 10:02:32 +0000 Subject: [PATCH] minor fixes and cleanups --- mmgen/proto/rune/rpc/remote.py | 18 ++++++++--------- mmgen/proto/rune/tx/protobuf.py | 9 +++++---- mmgen/ui.py | 6 ++++-- mmgen/util.py | 5 ++++- test/cmdtest_d/httpd/thornode/rpc.py | 2 +- test/cmdtest_d/rune.py | 30 ++++++++++++++-------------- test/cmdtest_d/runeswap.py | 1 - test/cmdtest_d/swap.py | 2 +- test/test-release.d/cfg.sh | 13 ++++++------ 9 files changed, 45 insertions(+), 41 deletions(-) diff --git a/mmgen/proto/rune/rpc/remote.py b/mmgen/proto/rune/rpc/remote.py index d00d873c..a2245757 100755 --- a/mmgen/proto/rune/rpc/remote.py +++ b/mmgen/proto/rune/rpc/remote.py @@ -36,7 +36,7 @@ class ThornodeRemoteRESTClient(RemoteJSONClient): timeout = 15 class THORChainRemoteRPCClient(RemoteRPCClient): - "communicate with remote THORChain JSON-RPC endpoint" + "retrieve data from a remote THORChain JSON-RPC endpoint" server_proto = 'THORChain' @@ -48,8 +48,14 @@ class THORChainRemoteRPCClient(RemoteRPCClient): self.rest_api = ThornodeRemoteRESTClient(cfg, proto) self.rpc_api = ThornodeRemoteRPCClient(cfg, proto) + def acct_info(self, addr: str, *, block=None): + "get account information for a given address" + return process_response( + self.rest_api.get(path=f'/auth/accounts/{addr}'), + errmsg = f'address ‘{addr}’ not found in blockchain')['value'] + def balance(self, addr: str, *, block=None): - "get balance for a given address, optionally at a given block height" + "get balance for a given address" res = process_response( self.rest_api.get(path=f'/bank/balances/{addr}'), errmsg = f'address ‘{addr}’ not found in blockchain') @@ -57,14 +63,8 @@ class THORChainRemoteRPCClient(RemoteRPCClient): assert len(rune_res) == 1, f'{rune_res}: result length is not one!' return self.proto.coin_amt(int(rune_res[0]['amount']), from_unit='satoshi') - def acct_info(self, addr: str, *, block=None): - "get account information for a given address, optionally at a given block height" - return process_response( - self.rest_api.get(path=f'/auth/accounts/{addr}'), - errmsg = f'address ‘{addr}’ not found in blockchain')['value'] - def tx_info(self, txid: str): - "get transaction information for a given TxID" + "get information for a transaction by TxID" return process_response( self.rpc_api.post( path = '/tx', diff --git a/mmgen/proto/rune/tx/protobuf.py b/mmgen/proto/rune/tx/protobuf.py index f1a89513..5e450da8 100755 --- a/mmgen/proto/rune/tx/protobuf.py +++ b/mmgen/proto/rune/tx/protobuf.py @@ -50,17 +50,18 @@ send_tx_parms = namedtuple( 'signature'], defaults = (0, None, None, None)) +# superset of swap_tx_parms, differences as noted (##): deposit_tx_parms = namedtuple( 'rune_deposit_tx_parms', [ - 'chain', - 'symbol', - 'ticker', + 'chain', ## 'THOR' + 'symbol', ## 'RUNE' + 'ticker', ## 'RUNE' 'from_addr', 'amt', 'gas_limit', 'account_number', 'sequence', - 'decimals', + 'decimals', ## 8 'memo', 'fee', # begin default fields 'synth', diff --git a/mmgen/ui.py b/mmgen/ui.py index c4ac6b52..d486d15c 100755 --- a/mmgen/ui.py +++ b/mmgen/ui.py @@ -152,8 +152,10 @@ def do_pager(text): from subprocess import run for pager in pagers: try: - m = text + ('' if pager == 'less' else end_msg) - run([pager], input=m.encode(), check=True) + run( + [pager], + input = text.encode() if pager == 'less' else (text + end_msg).encode(), + check = True) msg_r('\r') except: pass diff --git a/mmgen/util.py b/mmgen/util.py index b12b8ed5..28c7b7b8 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -187,7 +187,10 @@ def indent(s, *, indent=' ', append='\n'): def fmt(s, *, indent='', strip_char=None, append='\n'): "de-indent multiple lines of text, or indent with specified string" - return indent + ('\n'+indent).join([l.lstrip(strip_char) for l in s.strip().splitlines()]) + append + return ( + indent + + ('\n'+indent).join(l.lstrip(strip_char) for l in s.strip().splitlines()) + + append) def fmt_list(iterable, *, fmt='dfl', indent='', conv=None): "pretty-format a list" diff --git a/test/cmdtest_d/httpd/thornode/rpc.py b/test/cmdtest_d/httpd/thornode/rpc.py index e7b2c1c3..be151ad7 100755 --- a/test/cmdtest_d/httpd/thornode/rpc.py +++ b/test/cmdtest_d/httpd/thornode/rpc.py @@ -74,7 +74,7 @@ class ThornodeRPCServer(ThornodeServer): res.update({'hash': 'BD30B8FD9FC278A26E7A81ABB36C4709260DE64087EB578900BD23CEBF11D1A2'}) return res - pat_info = ( + pat_info = ( # these are matched in order, so more specific patterns must go first ('balance', 'GET', r'/bank/balances/(\S+)'), ('acct_info', 'GET', r'/auth/accounts/(\S+)'), ('tx_info', 'POST', r'/tx$'), diff --git a/test/cmdtest_d/rune.py b/test/cmdtest_d/rune.py index ff5c3431..f2743672 100755 --- a/test/cmdtest_d/rune.py +++ b/test/cmdtest_d/rune.py @@ -16,7 +16,6 @@ from hashlib import md5 from mmgen.fileutil import get_data_from_file -from ..include.common import imsg from .include.common import dfl_words_file from .include.proxy import TestProxy from .ethdev import CmdTestEthdevMethods @@ -101,14 +100,13 @@ class CmdTestRune(CmdTestRuneMethods, CmdTestEthdevMethods, CmdTestBase, CmdTest ), 'main': ( 'tracking wallet and transaction operations', - ('twview', 'viewing unspent outputs in tracking wallet'), - ('bal_refresh', 'refreshing address balance in tracking wallet'), - ('txcreate1', 'creating a transaction'), - ('txsign1', 'signing the transaction'), - ('txsend1_test', 'testing whether the transaction can be sent'), - ('txsend1', 'sending the transaction'), - ('txhex1', 'dumping the transaction hex')) - } + ('twview', 'viewing unspent outputs in tracking wallet'), + ('bal_refresh', 'refreshing address balance in tracking wallet'), + ('txcreate1', 'creating a transaction'), + ('txsign1', 'signing the transaction'), + ('txsend1_test', 'testing whether the transaction can be sent'), + ('txsend1', 'sending the transaction'), + ('txhex1', 'dumping the transaction hex'))} def __init__(self, cfg, trunner, cfgs, spawn): CmdTestBase.__init__(self, cfg, trunner, cfgs, spawn) @@ -147,21 +145,23 @@ class CmdTestRune(CmdTestRuneMethods, CmdTestEthdevMethods, CmdTestBase, CmdTest def twview(self): return self.spawn('mmgen-tool', self.rune_opts + self.add_eth_opts + ['twview']) + def bal_refresh(self): + return self._rune_bal_refresh() + def txcreate1(self): return self._rune_txcreate(add_opts=['--fee=0.2']) - bal_refresh = CmdTestRuneMethods._rune_bal_refresh - txsign1 = CmdTestRuneMethods._rune_txsign - _txsend = CmdTestRuneMethods._rune_txsend + def txsign1(self): + return self._rune_txsign() def txsend1_test(self): - return self._txsend(add_opts=['--test', f'--proxy=localhost:{TestProxy.port}'], test=True) + return self._rune_txsend(add_opts=['--test', f'--proxy=localhost:{TestProxy.port}'], test=True) def txsend1(self): - return self._txsend() + return self._rune_txsend() def txhex1(self): - t = self._txsend(add_opts=[f'--dump-hex={self.txhex_file}'], dump_hex=True) + t = self._rune_txsend(add_opts=[f'--dump-hex={self.txhex_file}'], dump_hex=True) t.read() txhex = get_data_from_file(self.cfg, self.txhex_file, silent=True) if md5(txhex.encode()).hexdigest()[:8] != self.txhex_chksum: diff --git a/test/cmdtest_d/runeswap.py b/test/cmdtest_d/runeswap.py index efdc9bbc..f928649f 100755 --- a/test/cmdtest_d/runeswap.py +++ b/test/cmdtest_d/runeswap.py @@ -16,7 +16,6 @@ from hashlib import md5 from mmgen.fileutil import get_data_from_file -from .httpd.thornode.swap import ThornodeSwapServer from .include.proxy import TestProxy from .regtest import CmdTestRegtest diff --git a/test/cmdtest_d/swap.py b/test/cmdtest_d/swap.py index 95f0fdf9..5e5b665f 100755 --- a/test/cmdtest_d/swap.py +++ b/test/cmdtest_d/swap.py @@ -20,7 +20,7 @@ from mmgen.protocol import init_proto from mmgen.wallet.mmgen import wallet as MMGenWallet from mmgen.tx.file import txfile_json_dumps # pylint: disable=no-name-in-module -from ..include.common import make_burn_addr, gr_uc +from ..include.common import make_burn_addr, gr_uc, imsg from .include.runner import CmdTestRunner from .include.common import dfl_words_file diff --git a/test/test-release.d/cfg.sh b/test/test-release.d/cfg.sh index 8b9bb6dc..2573fcd9 100755 --- a/test/test-release.d/cfg.sh +++ b/test/test-release.d/cfg.sh @@ -313,16 +313,15 @@ init_tests() { - $cmdtest_py --coin=ltc runeswap " - [ "$SOC" ] && { - xmr_env1="MMGEN_TEST_SUITE_PEXPECT_TIMEOUT=${MMGEN_TEST_SUITE_PEXPECT_TIMEOUT:-600} " - xmr_env2="MMGEN_HTTP_TIMEOUT=${MMGEN_HTTP_TIMEOUT:-600} " - xmr_env3="MMGEN_DAEMON_STATE_TIMEOUT=${MMGEN_DAEMON_STATE_TIMEOUT:-300} " - } + [ "$SOC" ] && xmr_env=( + "MMGEN_TEST_SUITE_PEXPECT_TIMEOUT=${MMGEN_TEST_SUITE_PEXPECT_TIMEOUT:-600}" + "MMGEN_HTTP_TIMEOUT=${MMGEN_HTTP_TIMEOUT:-600}" + "MMGEN_DAEMON_STATE_TIMEOUT=${MMGEN_DAEMON_STATE_TIMEOUT:-300}") d_xmr="Monero xmrwallet operations" t_xmr=" - - $xmr_env1$xmr_env2$xmr_env3$cmdtest_py --coin=xmr --exclude help - s $xmr_env1$xmr_env2$xmr_env3$cmdtest_py --coin=xmr xmr_autosign_nocompat + - ${xmr_env[*]} $cmdtest_py --coin=xmr --exclude help + s ${xmr_env[*]} $cmdtest_py --coin=xmr xmr_autosign_nocompat " [ "$FAST" ] && t_xmr_skip='s'