From 3baac863abc11df6f35b81d5e96235215ec056c5 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 22 Feb 2024 12:48:12 +0000 Subject: [PATCH] fixes and cleanups --- mmgen/autosign.py | 8 ++++---- mmgen/main_txcreate.py | 4 ++-- mmgen/main_txdo.py | 2 +- mmgen/main_txsend.py | 2 +- test/cmdtest.py | 4 ++-- test/cmdtest_py_d/cfg.py | 34 ++++++++++++++++---------------- test/cmdtest_py_d/ct_autosign.py | 30 +++++++++++++++++----------- test/cmdtest_py_d/ct_regtest.py | 4 ++++ 8 files changed, 49 insertions(+), 39 deletions(-) diff --git a/mmgen/autosign.py b/mmgen/autosign.py index cdf7101c..93866433 100755 --- a/mmgen/autosign.py +++ b/mmgen/autosign.py @@ -36,9 +36,8 @@ class Signable: self.parent = parent self.cfg = parent.cfg self.dir = getattr(parent,self.dir_name) - self.long_desc = ( - 'non-Monero transaction' if self.desc == 'transaction' and 'XMR' in self.parent.coins else - self.desc) + self.long_desc = getattr(self, 'xmr_desc', self.desc) if 'XMR' in self.parent.coins else self.desc + self.name = type(self).__name__ @property def unsigned(self): @@ -68,6 +67,7 @@ class Signable: class transaction(base): desc = 'transaction' + xmr_desc = 'non-Monero transaction' rawext = 'rawtx' sigext = 'sigtx' dir_name = 'tx_dir' @@ -289,7 +289,7 @@ class Autosign: async def check_daemons_running(self): from .protocol import init_proto for coin in self.coins: - proto = init_proto( self.cfg, coin, testnet=self.cfg.network=='testnet', need_amt=True ) + proto = init_proto(self.cfg, coin, network=self.cfg.network, need_amt=True) if proto.sign_mode == 'daemon': self.cfg._util.vmsg(f'Checking {coin} daemon') from .rpc import rpc_init diff --git a/mmgen/main_txcreate.py b/mmgen/main_txcreate.py index 2db6db82..e8480b10 100755 --- a/mmgen/main_txcreate.py +++ b/mmgen/main_txcreate.py @@ -32,7 +32,7 @@ opts_data = { 'options': """ -h, --help Print this help message --, --longhelp Print help message for long options (common options) --a, --fee-adjust= f Adjust transaction fee by factor 'f' (see below) +-A, --fee-adjust= f Adjust transaction fee by factor 'f' (see below) -B, --no-blank Don't blank screen before displaying unspent outputs -c, --comment-file=f Source the transaction's comment from file 'f' -C, --fee-estimate-confs=c Desired number of confirmations for fee estimation @@ -96,6 +96,6 @@ async def main(): tx2.file.write( ask_write = not cfg.yes, ask_overwrite = not cfg.yes, - ask_write_default_yes = False ) + ask_write_default_yes = False) async_run(main()) diff --git a/mmgen/main_txdo.py b/mmgen/main_txdo.py index 8000c308..1cebe3b1 100755 --- a/mmgen/main_txdo.py +++ b/mmgen/main_txdo.py @@ -33,7 +33,7 @@ opts_data = { 'options': """ -h, --help Print this help message --, --longhelp Print help message for long options (common options) --a, --fee-adjust= f Adjust transaction fee by factor 'f' (see below) +-A, --fee-adjust= f Adjust transaction fee by factor 'f' (see below) -b, --brain-params=l,p Use seed length 'l' and hash preset 'p' for brainwallet input -B, --no-blank Don't blank screen before displaying unspent outputs diff --git a/mmgen/main_txsend.py b/mmgen/main_txsend.py index 8161c544..3927e4ee 100755 --- a/mmgen/main_txsend.py +++ b/mmgen/main_txsend.py @@ -61,7 +61,7 @@ async def main(): tx = await OnlineSignedTX( cfg = cfg, filename = infile, - quiet_open = True ) + quiet_open = True) from .rpc import rpc_init tx.rpc = await rpc_init(cfg,tx.proto) diff --git a/test/cmdtest.py b/test/cmdtest.py index 2f05b7c2..4659fffe 100755 --- a/test/cmdtest.py +++ b/test/cmdtest.py @@ -195,13 +195,13 @@ po = Config(opts_data=opts_data,parse_only=True)._parsed_opts data_dir = Config.test_datadir # step 1: delete data_dir symlink in ./test; -if not po.user_opts.get('skipping_deps'): +if not po.user_opts.get('skip_deps'): try: os.unlink(data_dir) except: pass -# step 2: opts.init will create new data_dir in ./test (if not cfg.skipping_deps) +# step 2: opts.init will create new data_dir in ./test (if not po.user_opts['skip_deps']) cfg = Config(opts_data=opts_data) if cfg.no_altcoin and cfg.coin != 'BTC': diff --git a/test/cmdtest_py_d/cfg.py b/test/cmdtest_py_d/cfg.py index ed0ef848..34dbce90 100755 --- a/test/cmdtest_py_d/cfg.py +++ b/test/cmdtest_py_d/cfg.py @@ -152,9 +152,9 @@ cfgs = { # addr_idx_lists (except 31,32,33,34) must contain exactly 8 addresses 'tool_encrypt.in.mmenc': 'tool_encrypt', }, }, - '11': {}, - '12': {}, - '13': {}, + '11': {}, # wallet + '12': {}, # wallet + '13': {}, # wallet '14': { 'kapasswd': 'Maxwell', 'wpasswd': 'The Halving', 'addr_idx_list': '61,998,502-504,7-9', @@ -183,8 +183,8 @@ cfgs = { # addr_idx_lists (except 31,32,33,34) must contain exactly 8 addresses pwfile: 'passchg_dfl_wallet', }, }, - '17': {}, - '18': {}, + '17': {}, # regtest + '18': {}, # autosign '19': { 'wpasswd':'abc' }, '20': { 'wpasswd': 'Vsize it', 'addr_idx_list': '1-8', @@ -206,19 +206,19 @@ cfgs = { # addr_idx_lists (except 31,32,33,34) must contain exactly 8 addresses 'sigtx': 'txsign6', }, }, - '22': {}, - '23': {}, - '26': {}, - '27': {}, - '28': {}, + '22': {}, # ethdev + '23': {}, # seedsplit + '26': {}, # ref_3seed + '27': {}, # ref_3seed + '28': {}, # ref_3seed '29': {}, # xmrwallet - '31': {}, - '32': {}, - '33': {}, - '34': {}, - '39': {}, - '40': {}, - '41': {}, + '31': {}, # ref_tx + '32': {}, # ref_tx + '33': {}, # ref_tx + '34': {}, # ref_tx + '39': {}, # xmr_autosign + '40': {}, # cfgfile + '41': {}, # opts '99': {}, # dummy } diff --git a/test/cmdtest_py_d/ct_autosign.py b/test/cmdtest_py_d/ct_autosign.py index f6397dc5..89b7ce90 100755 --- a/test/cmdtest_py_d/ct_autosign.py +++ b/test/cmdtest_py_d/ct_autosign.py @@ -28,7 +28,7 @@ from mmgen.cfg import Config from mmgen.color import red,green,blue,yellow,purple,gray from mmgen.util import msg,suf,die from mmgen.led import LEDControl -from mmgen.autosign import Autosign +from mmgen.autosign import Autosign, Signable from ..include.common import ( cfg, @@ -56,7 +56,7 @@ class CmdTestAutosignBase(CmdTestBase): def __init__(self,trunner,cfgs,spawn): - super().__init__(trunner,cfgs,spawn) + CmdTestBase.__init__(self,trunner,cfgs,spawn) if trunner is None: return @@ -114,7 +114,12 @@ class CmdTestAutosignBase(CmdTestBase): stop_test_daemons(*self.network_ids) return 'ok' - def run_setup(self,mn_type=None,mn_file=None,use_dfl_wallet=False): + def run_setup( + self, + mn_type = None, + mn_file = None, + use_dfl_wallet = False, + passwd = 'abc'): mn_desc = mn_type or 'default' mn_type = mn_type or 'mmgen' @@ -126,7 +131,7 @@ class CmdTestAutosignBase(CmdTestBase): if use_dfl_wallet: t.expect( 'Use default wallet for autosigning? (Y/n): ', 'y' ) - t.passphrase( 'MMGen wallet', 'abc' ) + t.passphrase('MMGen wallet', passwd) else: if use_dfl_wallet is not None: # None => no dfl wallet present t.expect( 'Use default wallet for autosigning? (Y/n): ', 'n' ) @@ -166,7 +171,7 @@ class CmdTestAutosignThreaded(CmdTestAutosignBase): def autosign_start_thread(self): def run(): - t = self.spawn('mmgen-autosign', self.opts + ['wait'], direct_exec=True) + t = self.spawn('mmgen-autosign', self.opts + ['--full-summary','wait'], direct_exec=True) self.write_to_tmpfile('autosign_thread_pid',str(t.ep.pid)) import threading threading.Thread(target=run, name='Autosign wait loop').start() @@ -456,26 +461,27 @@ class CmdTestAutosign(CmdTestAutosignBase): self.do_umount() return 'ok' - def do_sign(self,args,have_msg=False,tx_name='transaction'): - t = self.spawn('mmgen-autosign', self.opts + args ) + def do_sign(self, args, have_msg=False): + tx_desc = Signable.transaction.desc + t = self.spawn('mmgen-autosign', self.opts + args) t.expect( - f'{self.tx_count} {tx_name}{suf(self.tx_count)} signed' if self.tx_count else - 'No unsigned transactions' ) + f'{self.tx_count} {tx_desc}{suf(self.tx_count)} signed' if self.tx_count else + f'No unsigned {tx_desc}s') if self.bad_tx_count: - t.expect(f'{self.bad_tx_count} {tx_name}{suf(self.bad_tx_count)} failed to sign') + t.expect(f'{self.bad_tx_count} {tx_desc}{suf(self.bad_tx_count)} failed to sign') t.req_exit_val = 1 if have_msg: t.expect( f'{self.good_msg_count} message file{suf(self.good_msg_count)}{{0,1}} signed' if self.good_msg_count else - 'No unsigned message files', regex=True ) + 'No unsigned message files', regex=True) if self.bad_msg_count: t.expect( f'{self.bad_msg_count} message file{suf(self.bad_msg_count)}{{0,1}} failed to sign', - regex = True ) + regex = True) t.req_exit_val = 1 if 'wait' in args: diff --git a/test/cmdtest_py_d/ct_regtest.py b/test/cmdtest_py_d/ct_regtest.py index a07a1d30..17cc5cc5 100755 --- a/test/cmdtest_py_d/ct_regtest.py +++ b/test/cmdtest_py_d/ct_regtest.py @@ -440,11 +440,15 @@ class CmdTestRegtest(CmdTestBase,CmdTestShared): } def __init__(self,trunner,cfgs,spawn): + CmdTestBase.__init__(self,trunner,cfgs,spawn) + if trunner == None: return + if self.proto.testnet: die(2,'--testnet and --regtest options incompatible with regtest test suite') + self.proto = init_proto( cfg, self.proto.coin, network='regtest', need_amt=True ) coin = self.proto.coin.lower()