From 0d38b6208151e0c8a404d4834aa1661055f75c13 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 16 Feb 2025 14:42:32 +0000 Subject: [PATCH] minor fixes and cleanups --- mmgen/help/help_notes.py | 2 +- mmgen/main_txbump.py | 2 +- mmgen/tx/bump.py | 2 +- mmgen/tx/new_swap.py | 2 +- test/cmdtest_d/ct_automount.py | 41 +++++++++++++++++++--------------- test/cmdtest_d/ct_main.py | 2 +- test/cmdtest_d/ct_regtest.py | 4 ++-- test/cmdtest_d/ct_swap.py | 6 +++-- 8 files changed, 34 insertions(+), 27 deletions(-) diff --git a/mmgen/help/help_notes.py b/mmgen/help/help_notes.py index 6056963c..1c8faeca 100755 --- a/mmgen/help/help_notes.py +++ b/mmgen/help/help_notes.py @@ -24,7 +24,7 @@ class help_notes: return ( 'COIN1 [AMT CHG_ADDR] COIN2 [ADDR]' if target == 'swaptx' else - '[ADDR,AMT ... | DATA_SPEC] ADDR ' + '[ADDR,AMT ... | DATA_SPEC] ADDR' if self.proto.base_proto == 'Bitcoin' else 'ADDR,AMT') diff --git a/mmgen/main_txbump.py b/mmgen/main_txbump.py index 4801cc8e..cd5dcf94 100755 --- a/mmgen/main_txbump.py +++ b/mmgen/main_txbump.py @@ -29,7 +29,7 @@ opts_data = { 'filter_codes': ['-'], 'sets': [('yes', True, 'quiet', True)], 'text': { - 'desc': f""" + 'desc': """ Create, and optionally send and sign, a replacement transaction on networks that support replace-by-fee (RBF) """, diff --git a/mmgen/tx/bump.py b/mmgen/tx/bump.py index 3e13fbd1..7d94f6fd 100755 --- a/mmgen/tx/bump.py +++ b/mmgen/tx/bump.py @@ -30,7 +30,7 @@ class Bump(Completed, New): # If sending, require original tx to be sent if check_sent and not self.coin_txid: - die(1, 'Transaction {self.txid!r} was not broadcast to the network') + die(1, f'Transaction {self.txid!r} was not broadcast to the network') self.coin_txid = '' self.sent_timestamp = None diff --git a/mmgen/tx/new_swap.py b/mmgen/tx/new_swap.py index 9cd26a97..b98ea2bb 100755 --- a/mmgen/tx/new_swap.py +++ b/mmgen/tx/new_swap.py @@ -18,5 +18,5 @@ class NewSwap(New): desc = 'swap transaction' is_swap = True - async def process_swap_cmdline_args(self, cmd_args, addrfile_args): + async def process_swap_cmdline_args(self, cmd_args, addrfiles): raise NotImplementedError(f'Swap not implemented for protocol {self.proto.__name__}') diff --git a/test/cmdtest_d/ct_automount.py b/test/cmdtest_d/ct_automount.py index 6dd7a083..af174994 100755 --- a/test/cmdtest_d/ct_automount.py +++ b/test/cmdtest_d/ct_automount.py @@ -78,7 +78,10 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet) self.opts.append('--alice') - def _alice_txcreate(self, chg_addr, opts=[], exit_val=0, expect_str=None, data_arg=None): + def _alice_txcreate(self, chg_addr, opts=[], exit_val=0, expect_str=None, data_arg=None, need_rbf=False): + + if need_rbf and not self.proto.cap('rbf'): + return 'skip' def do_return(): if expect_str: @@ -120,9 +123,7 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet) alice_txcreate3 = alice_txcreate2 def alice_txcreate4(self): - if cfg.coin == 'BCH': - return 'skip' - return self._alice_txcreate(chg_addr='L:4') + return self._alice_txcreate(chg_addr='L:4', need_rbf=True) def _alice_txsend_abort(self, err=False, send_resp='y', expect=None, shred_expect=[]): self.insert_device_online() @@ -170,16 +171,16 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet) return self._alice_txsend('This one’s worth a comment', no_wait=True) def alice_txsend2(self): - if cfg.coin == 'BCH': - return 'skip' - return self._alice_txsend() + return self._alice_txsend(need_rbf=True) def alice_txsend3(self): - if cfg.coin == 'BCH': - return 'skip' - return self._alice_txsend() + return self._alice_txsend(need_rbf=True) + + def _alice_txstatus(self, expect, exit_val=None, need_rbf=False): + + if need_rbf and not self.proto.cap('rbf'): + return 'skip' - def _alice_txstatus(self, expect, exit_val=None): self.insert_device_online() t = self.spawn( 'mmgen-txsend', @@ -203,7 +204,11 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet) def alice_txstatus4(self): return self._alice_txstatus('1 confirmation', 0) - def _alice_txsend(self, comment=None, no_wait=False): + def _alice_txsend(self, comment=None, no_wait=False, need_rbf=False): + + if need_rbf and not self.proto.cap('rbf'): + return 'skip' + if not no_wait: self._wait_signed('transaction') self.insert_device_online() @@ -224,18 +229,18 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet) self.remove_device_online() return t - def _alice_txbump(self, bad_tx_desc=None): + def _alice_txbump(self, bad_tx_expect=None): if cfg.coin == 'BCH': return 'skip' self.insert_device_online() t = self.spawn( 'mmgen-txbump', ['--alice', '--autosign'], - exit_val = 1 if bad_tx_desc else None) - if bad_tx_desc: + exit_val = 1 if bad_tx_expect else None) + if bad_tx_expect: time.sleep(0.5) t.expect('Only sent transactions') - t.expect(bad_tx_desc) + t.expect(bad_tx_expect) else: t.expect(r'to deduct the fee from .* change output\): ', '\n', regex=True) t.expect(r'(Y/n): ', 'y') # output OK? @@ -248,11 +253,11 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet) return t def alice_txbump1(self): - return self._alice_txbump(bad_tx_desc='unsigned transaction') + return self._alice_txbump(bad_tx_expect='unsigned transaction') def alice_txbump2(self): self._wait_signed('transaction') - return self._alice_txbump(bad_tx_desc='unsent transaction') + return self._alice_txbump(bad_tx_expect='unsent transaction') def alice_txbump3(self): return self._alice_txbump() diff --git a/test/cmdtest_d/ct_main.py b/test/cmdtest_d/ct_main.py index e840a99e..89518f69 100755 --- a/test/cmdtest_d/ct_main.py +++ b/test/cmdtest_d/ct_main.py @@ -1058,7 +1058,7 @@ class CmdTestMain(CmdTestBase, CmdTestShared): return self.txbump( f7, prepend_args = ['-p1', '-k', non_mm_file, '-M', f1], - seed_args = [f2, f3, f4, f5, f6, f8]) + seed_args = [f2, f3, f4, f6, f8]) def walletgen5(self, del_dw_run='dummy'): return self.walletgen() diff --git a/test/cmdtest_d/ct_regtest.py b/test/cmdtest_d/ct_regtest.py index b961f2e5..ba3f29a2 100755 --- a/test/cmdtest_d/ct_regtest.py +++ b/test/cmdtest_d/ct_regtest.py @@ -54,7 +54,8 @@ from .common import ( tw_comment_lat_cyr_gr, tw_comment_zh, tx_comment_jp, - get_env_without_debug_vars) + get_env_without_debug_vars, + rt_pw) from .ct_base import CmdTestBase from .ct_shared import CmdTestShared @@ -66,7 +67,6 @@ dfl_wcls = get_wallet_cls('mmgen') tx_fee = rtFundAmt = rtFee = rtBals = rtBals_gb = rtBobOp3 = rtAmts = None # ruff -rt_pw = 'abc-α' rt_data = { 'tx_fee': {'btc':'0.0001', 'bch':'0.001', 'ltc':'0.01'}, 'rtFundAmt': {'btc':'500', 'bch':'500', 'ltc':'5500'}, diff --git a/test/cmdtest_d/ct_swap.py b/test/cmdtest_d/ct_swap.py index 26777eb5..23d70ff3 100755 --- a/test/cmdtest_d/ct_swap.py +++ b/test/cmdtest_d/ct_swap.py @@ -14,6 +14,8 @@ test.cmdtest_d.ct_swap: asset swap tests for the cmdtest.py test suite from mmgen.protocol import init_proto +from ..include.common import gr_uc + from .ct_regtest import ( CmdTestRegtest, rt_data, @@ -21,7 +23,7 @@ from .ct_regtest import ( rt_pw, cfg) -sample1 = '=:ETH.ETH:0x86d526d6624AbC0178cF7296cD538Ecc080A95F1:0/1/0' +sample1 = gr_uc[:24] sample2 = '00010203040506' class CmdTestSwap(CmdTestRegtest): @@ -53,7 +55,7 @@ class CmdTestSwap(CmdTestRegtest): ), 'data': ( 'OP_RETURN data operations', - ('data_tx1_create', 'Creating a transaction with OP_RETURN data (hex-encoded ascii)'), + ('data_tx1_create', 'Creating a transaction with OP_RETURN data (hex-encoded UTF-8)'), ('data_tx1_sign', 'Signing the transaction'), ('data_tx1_send', 'Sending the transaction'), ('data_tx1_chk', 'Checking the sent transaction'),