autosign, led, unit test testdep: minor cleanups

This commit is contained in:
The MMGen Project 2024-09-06 12:20:13 +00:00
commit 0a15307e05
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
8 changed files with 54 additions and 48 deletions

View file

@ -329,6 +329,15 @@ class Autosign:
macOS_ramdisk_name = 'AutosignRamDisk'
wallet_subdir = 'autosign'
cmds = ('setup', 'xmr_setup', 'sign', 'wait')
util_cmds = (
'gen_key',
'macos_ramdisk_setup',
'macos_ramdisk_delete',
'clean',
'wipe_key')
mn_fmts = {
'mmgen': 'words',
'bip39': 'bip39',
@ -416,7 +425,7 @@ class Autosign:
if cfg.xmrwallets and not 'XMR' in self.coins:
self.coins.append('XMR')
if not self.coins and cmd not in ('gen_key','wipe_key'):
if not self.coins and cmd in self.cmds:
ymsg('Warning: no coins specified, defaulting to BTC')
self.coins = ['BTC']

View file

@ -78,10 +78,7 @@ class LEDControl:
msg(f'{board.name} board detected')
if self.debug:
msg(fmt(f"""
Status file: {board.status}
Trigger file: {board.trigger}
""",indent=' ',strip_char='\t'))
msg(f'\n Status file: {board.status}\n Trigger file: {board.trigger}')
def check_access(fn,desc,init_val=None):
try:
@ -114,15 +111,6 @@ class LEDControl:
with open(db.trigger,'w') as fp:
fp.write(db.trigger_states[1]+'\n')
@classmethod
def delete_dummy_control_files(cls):
db = cls.boards['dummy']
for fn in (db.status, db.trigger):
try:
os.unlink(fn)
except Exception as e:
msg(str(e))
def noop(self,*args,**kwargs):
pass

View file

@ -70,8 +70,8 @@ gen_key - generate the wallet encryption key and copy it to the removable
configured)
setup - full setup: run gen_key and create temporary signing wallet(s)
for all configured coins
xmr_setup - set up Monero temporary signing wallet(s). Not required in normal
operation: use setup with --xmrwallets instead
xmr_setup - set up Monero temporary signing wallet(s). Not required during
normal operation: use setup with --xmrwallets instead
macos_ramdisk_setup - set up the ramdisk used for storing the temporary signing
wallet(s) (macOS only). Required only when creating the wallet(s)
manually, without setup
@ -191,18 +191,7 @@ cfg = Config(
cmd = cfg._args[0] if len(cfg._args) == 1 else 'sign' if not cfg._args else cfg._opts.usage()
valid_cmds = (
'gen_key',
'setup',
'xmr_setup',
'macos_ramdisk_setup',
'macos_ramdisk_delete',
'sign',
'wait',
'clean',
'wipe_key')
if cmd not in valid_cmds:
if cmd not in Autosign.cmds + Autosign.util_cmds:
die(1,f'{cmd}’: unrecognized command')
if cmd != 'setup':

View file

@ -456,3 +456,12 @@ def wrap_ripemd160(called=[]):
def exit_if_mswin(feature):
if sys.platform == 'win32':
die(2, capfirst(feature) + ' not supported on the MSWin / MSYS2 platform' )
def have_sudo(silent=False):
from subprocess import run, DEVNULL
redir = DEVNULL if silent else None
try:
run(['sudo', '--non-interactive', 'true'], stdout=redir, stderr=redir, check=True)
return True
except:
return False

View file

@ -1004,6 +1004,9 @@ if __name__ == '__main__':
if tr.daemon_started and not cfg.no_daemon_stop:
stop_test_daemons(network_id, remove_datadir=True)
tr.warn_skipped()
if hasattr(tr, 'tg'):
del tr.tg
del tr
die(1,yellow('\ntest.py exiting at user request'))
except TestSuiteSpawnedScriptException as e:
# if spawned script is not running under exec_wrapper, output brief error msg:

View file

@ -83,8 +83,17 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet)
self.opts.append('--alice')
def _alice_txcreate(self, chg_addr, opts=[], exit_val=0, expect=None):
def _alice_txcreate(self, chg_addr, opts=[], exit_val=0, expect_str=None):
def do_return():
if expect_str:
t.expect(expect_str)
t.read()
self.remove_device_online()
return t
self.insert_device_online()
sid = self._user_sid('alice')
t = self.spawn(
'mmgen-txcreate',
@ -92,21 +101,17 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet)
+ ['--alice', '--autosign']
+ [f'{self.burn_addr},1.23456', f'{sid}:{chg_addr}'],
exit_val = exit_val or None)
if exit_val:
t.expect(expect)
t.read()
self.remove_device_online()
return t
return do_return()
t = self.txcreate_ui_common(
t,
inputs = '1',
interactive_fee = '32s',
file_desc = 'Unsigned automount transaction')
if expect:
t.expect(expect)
t.read()
self.remove_device_online()
return t
return do_return()
def alice_txcreate1(self):
return self._alice_txcreate(chg_addr='C:5')
@ -155,10 +160,10 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtestBDBWallet)
alice_txsend_abort5 = alice_txsend_abort2
def alice_txcreate_bad_have_unsigned(self):
return self._alice_txcreate(chg_addr='C:5', exit_val=2, expect='already present')
return self._alice_txcreate(chg_addr='C:5', exit_val=2, expect_str='already present')
def alice_txcreate_bad_have_unsent(self):
return self._alice_txcreate(chg_addr='C:5', exit_val=2, expect='unsent transaction')
return self._alice_txcreate(chg_addr='C:5', exit_val=2, expect_str='unsent transaction')
def copy_wallet(self):
self.spawn('', msg_only=True)

View file

@ -90,7 +90,10 @@ class CmdTestAutosignBase(CmdTestBase):
def __del__(self):
if hasattr(self,'have_dummy_control_files'):
LEDControl.delete_dummy_control_files()
db = LEDControl.boards['dummy']
for fn in (db.status, db.trigger):
run('sudo rm -f {fn}'.split(), check=True)
if hasattr(self, 'txdev'):
del self.txdev
if not cfg.no_daemon_stop:
@ -781,7 +784,7 @@ class CmdTestAutosign(CmdTestAutosignBase):
tx_desc = Signable.transaction.desc
self.insert_device()
def do_exit():
def do_return():
if expect_str:
t.expect(expect_str)
t.read()
@ -795,7 +798,7 @@ class CmdTestAutosign(CmdTestAutosignBase):
exit_val = exc_exit_val or (1 if self.bad_tx_count or (have_msg and self.bad_msg_count) else None))
if exc_exit_val:
return do_exit()
return do_return()
t.expect(
f'{self.tx_count} {tx_desc}{suf(self.tx_count)} signed' if self.tx_count else
@ -815,7 +818,7 @@ class CmdTestAutosign(CmdTestAutosignBase):
f'{self.bad_msg_count} message file{suf(self.bad_msg_count)}{{0,1}} failed to sign',
regex = True)
return do_exit()
return do_return()
def sign_quiet(self):
return self.do_sign(['--quiet'])

View file

@ -16,7 +16,7 @@ class unit_tests:
altcoin_deps = ('pycoin','monero_python','keyconv','zcash_mini','ethkey','ssh_socks_proxy')
win_skip = ('losetup', 'zcash_mini', 'sudo')
mac_skip = ('losetup', 'sudo')
mac_skip = ('losetup',)
def pylint(self,name,ut):
try:
@ -76,9 +76,9 @@ class unit_tests:
return CmdTestXMRWallet.init_proxy(external_call=True)
def sudo(self,name,ut):
try:
run(['sudo', '--non-interactive', 'true'], check=True)
from mmgen.util import have_sudo
if have_sudo():
return True
except:
else:
ymsg(f'To run the test suite, please enable sudo without password for user ‘{os.getenv("USER")}')
return False