From 955fe5aa28158f87f64a35a7ffebe2f20f96dd49 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 2 Sep 2026 13:52:39 +0000 Subject: [PATCH] cfg, txsign, test suite: minor cleanups --- mmgen/cfg.py | 6 +++--- mmgen/main_txsign.py | 4 +++- mmgen/proto/btc/tx/unsigned.py | 2 +- mmgen/proto/vm/tx/unsigned.py | 2 +- mmgen/tx/unsigned.py | 2 +- test/cmdtest_d/runeswap.py | 4 ++-- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/mmgen/cfg.py b/mmgen/cfg.py index acb995f4..5a3e826f 100755 --- a/mmgen/cfg.py +++ b/mmgen/cfg.py @@ -539,7 +539,7 @@ class Config(Lockable): # Step 3: set cfg from environment, skipping already-set opts; save names set from environment: self._envopts = tuple(self._set_cfg_from_env()) if self._use_env else () - # Step 4: finalize some cmdline-only opts: + # Step 4: finalize some non-cfg-file opts: self.coin = self.coin.upper() self.token = self.token.upper() if self.token else None if ( @@ -803,7 +803,7 @@ class Config(Lockable): bad = [k for k in self.__dict__ if k in group and k in self._uopts and getattr(self, k) is not None] if len(bad) > 1: - die(1, 'Conflicting options: {}'.format(', '.join(map(fmt_opt, bad)))) + die('UserOptError', 'Conflicting options: {}'.format(', '.join(map(fmt_opt, bad)))) def _set_quiet(self, val): from .util import Util @@ -1004,7 +1004,7 @@ def conv_type(name, val, refval, *, src, invert_bool=False): 'cmdline': 'command-line', 'cfg': 'Config', 'env': 'environment var'} - die(1, '{a!r}: invalid value for {b} option {c!r}{d} (must be of type {e!r})'.format( + die('UserOptError', '{a!r}: invalid value for {b} option {c!r}{d} (must be of type {e!r})'.format( a = val, b = desc.get(src, 'config file'), c = fmt_opt(name) if src == 'cmdline' else name, diff --git a/mmgen/main_txsign.py b/mmgen/main_txsign.py index 07d8fedc..800b40d0 100755 --- a/mmgen/main_txsign.py +++ b/mmgen/main_txsign.py @@ -143,7 +143,9 @@ async def main(): if not cfg.yes: tx1.info.view_with_prompt(f'View data for transaction{tx_num_disp}?') - if tx2 := await tx1.sign(TxKeys(cfg, tx1, seedfiles=seedfiles).keys, tx_num_disp): + if tx2 := await tx1.sign( + TxKeys(cfg, tx1, seedfiles=seedfiles).keys, + tx_num_str = tx_num_disp): if not cfg.yes: tx2.add_comment() # edits an existing comment tx2.file.write(ask_write=not cfg.yes, ask_write_default_yes=True, add_desc=tx_num_disp) diff --git a/mmgen/proto/btc/tx/unsigned.py b/mmgen/proto/btc/tx/unsigned.py index 0e8f7bf2..39a2ab8a 100755 --- a/mmgen/proto/btc/tx/unsigned.py +++ b/mmgen/proto/btc/tx/unsigned.py @@ -21,7 +21,7 @@ class Unsigned(Completed, TxBase.Unsigned): desc = 'unsigned transaction' # Return signed object or False. Don’t exit or raise exception: - async def proto_sign(self, keys, tx_num_str=''): + async def proto_sign(self, keys, *, tx_num_str): if (self.has_segwit_inputs() or self.has_segwit_outputs()) and not self.proto.cap('segwit'): ymsg(f"TX has Segwit inputs or outputs, but {self.coin} doesn't support Segwit!") diff --git a/mmgen/proto/vm/tx/unsigned.py b/mmgen/proto/vm/tx/unsigned.py index 8030c4f0..1756b703 100755 --- a/mmgen/proto/vm/tx/unsigned.py +++ b/mmgen/proto/vm/tx/unsigned.py @@ -18,7 +18,7 @@ class Unsigned: desc = 'unsigned transaction' # Return signed object or False. Don’t exit or raise exception: - async def proto_sign(self, keys, tx_num_str=''): + async def proto_sign(self, keys, *, tx_num_str): o = self.txobj diff --git a/mmgen/tx/unsigned.py b/mmgen/tx/unsigned.py index 597860e0..118458b8 100755 --- a/mmgen/tx/unsigned.py +++ b/mmgen/tx/unsigned.py @@ -21,7 +21,7 @@ class Unsigned(Completed): automount = False # Return signed object or False. Don’t exit or raise exception, unless fatal: - async def sign(self, keys, tx_num_str=''): + async def sign(self, keys, *, tx_num_str=''): if self.file_format == 'legacy': # fatal die('LegacyTxSignRequestError', diff --git a/test/cmdtest_d/runeswap.py b/test/cmdtest_d/runeswap.py index be06d2f8..af024336 100755 --- a/test/cmdtest_d/runeswap.py +++ b/test/cmdtest_d/runeswap.py @@ -136,7 +136,7 @@ class CmdTestRuneSwapRune(CmdTestSwapMethods, CmdTestRune): t = self._swaptxsend(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: - self.tr.parent_group.tr.warn('txid mismatch') + if (chk := md5(txhex.encode()).hexdigest()[:8]) != self.txhex_chksum: + self.tr.parent_group.tr.warn(f'txid mismatch ({chk} != {self.txhex_chksum})') return 'ok' return t