ct_autosign.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2024 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. test.cmdtest_py_d.ct_autosign: Autosign tests for the cmdtest.py test suite
  20. """
  21. import sys,os,time,shutil
  22. from subprocess import run,DEVNULL
  23. from pathlib import Path
  24. from mmgen.cfg import Config
  25. from mmgen.color import red,green,blue,yellow,purple,gray
  26. from mmgen.util import msg,suf,die
  27. from mmgen.led import LEDControl
  28. from mmgen.autosign import Autosign, Signable
  29. from ..include.common import (
  30. cfg,
  31. omsg,
  32. omsg_r,
  33. oqmsg,
  34. oqmsg_r,
  35. start_test_daemons,
  36. stop_test_daemons,
  37. joinpath,
  38. imsg,
  39. read_from_file
  40. )
  41. from .common import ref_dir,dfl_words_file,dfl_bip39_file
  42. from .ct_base import CmdTestBase
  43. from .input import stealth_mnemonic_entry
  44. class CmdTestAutosignBase(CmdTestBase):
  45. networks = ('btc',)
  46. tmpdir_nums = [18]
  47. color = True
  48. win_skip = True
  49. threaded = False
  50. daemon_coins = []
  51. def __init__(self,trunner,cfgs,spawn):
  52. CmdTestBase.__init__(self,trunner,cfgs,spawn)
  53. if trunner is None:
  54. return
  55. self.silent_mount = self.live or not (cfg.exact_output or cfg.verbose)
  56. self.network_ids = [c+'_tn' for c in self.daemon_coins] + self.daemon_coins
  57. self._create_autosign_instances(create_dirs=not cfg.skipping_deps)
  58. if not (cfg.skipping_deps or self.live):
  59. self._create_removable_device()
  60. self.opts = ['--coins='+','.join(self.coins)]
  61. if not self.live:
  62. self.spawn_env['MMGEN_TEST_SUITE_ROOT_PFX'] = self.tmpdir
  63. if self.threaded:
  64. self.spawn_env['MMGEN_TEST_SUITE_AUTOSIGN_THREADED'] = '1'
  65. def _create_autosign_instances(self,create_dirs):
  66. d = {'offline': {'name':'asi'}}
  67. if self.have_online:
  68. d['online'] = {'name':'asi_online'}
  69. for subdir,data in d.items():
  70. if create_dirs and not self.live:
  71. for k in ('mountpoint','wallet_dir','dev_label_dir'):
  72. if k == 'wallet_dir' and subdir == 'online':
  73. continue
  74. (Path(self.tmpdir) / (subdir + getattr(Autosign,'dfl_'+k))).mkdir(parents=True,exist_ok=True)
  75. setattr(self,data['name'],
  76. Autosign(
  77. Config({
  78. 'coins': ','.join(self.coins),
  79. 'test_suite': True,
  80. 'test_suite_xmr_autosign': self.name == 'CmdTestXMRAutosign',
  81. 'test_suite_autosign_threaded': self.threaded,
  82. 'test_suite_root_pfx': None if self.live else self.tmpdir,
  83. 'online': subdir == 'online',
  84. })))
  85. def _create_removable_device(self):
  86. redir = DEVNULL
  87. img_file = str(self.asi.fs_image_path)
  88. run(['truncate', '--size=10M', img_file], check=True)
  89. run(['/sbin/mkfs.ext2', '-E', f'root_owner={os.getuid()}:{os.getgid()}', img_file],
  90. stdout=redir, stderr=redir, check=True)
  91. self.do_mount(no_dir_chk=True)
  92. (self.asi.mountpoint / 'tx').mkdir()
  93. self.do_umount()
  94. def start_daemons(self):
  95. self.spawn('',msg_only=True)
  96. start_test_daemons(*self.network_ids)
  97. return 'ok'
  98. def stop_daemons(self):
  99. self.spawn('',msg_only=True)
  100. stop_test_daemons(*self.network_ids)
  101. return 'ok'
  102. def run_setup(
  103. self,
  104. mn_type = None,
  105. mn_file = None,
  106. use_dfl_wallet = False,
  107. passwd = 'abc'):
  108. mn_desc = mn_type or 'default'
  109. mn_type = mn_type or 'mmgen'
  110. t = self.spawn(
  111. 'mmgen-autosign',
  112. self.opts
  113. + ([] if mn_desc == 'default' else [f'--mnemonic-fmt={mn_type}'])
  114. + ['setup'],
  115. no_passthru_opts = True)
  116. if use_dfl_wallet:
  117. t.expect( 'Use default wallet for autosigning? (Y/n): ', 'y' )
  118. t.passphrase('MMGen wallet', passwd)
  119. else:
  120. if use_dfl_wallet is not None: # None => no dfl wallet present
  121. t.expect( 'Use default wallet for autosigning? (Y/n): ', 'n' )
  122. mn_file = mn_file or { 'mmgen': dfl_words_file, 'bip39': dfl_bip39_file }[mn_type]
  123. mn = read_from_file(mn_file).strip().split()
  124. from mmgen.mn_entry import mn_entry
  125. entry_mode = 'full'
  126. mne = mn_entry( cfg, mn_type, entry_mode )
  127. t.expect('words: ',{ 12:'1', 18:'2', 24:'3' }[len(mn)])
  128. t.expect('OK? (Y/n): ','\n')
  129. t.expect('Type a number.*: ',str(mne.entry_modes.index(entry_mode)+1),regex=True)
  130. stealth_mnemonic_entry(t,mne,mn,entry_mode)
  131. t.written_to_file('Autosign wallet')
  132. return t
  133. def _mount_ops(self, loc, cmd, *args, **kwargs):
  134. return getattr(getattr(self,loc),cmd)(*args, silent=self.silent_mount, **kwargs)
  135. def do_mount(self, *args, **kwargs):
  136. return self._mount_ops('asi', 'do_mount', *args, **kwargs)
  137. def do_umount(self, *args, **kwargs):
  138. return self._mount_ops('asi', 'do_umount', *args, **kwargs)
  139. def do_mount_online(self, *args, **kwargs):
  140. return self._mount_ops('asi_online', 'do_mount', *args, **kwargs)
  141. def do_umount_online(self, *args, **kwargs):
  142. return self._mount_ops('asi_online', 'do_umount', *args, **kwargs)
  143. class CmdTestAutosignThreaded(CmdTestAutosignBase):
  144. have_online = True
  145. live = False
  146. no_insert_check = False
  147. threaded = True
  148. def autosign_start_thread(self):
  149. def run():
  150. t = self.spawn(
  151. 'mmgen-autosign',
  152. self.opts + ['--full-summary','wait'],
  153. direct_exec = True,
  154. no_passthru_opts = True,
  155. spawn_env_override = self.spawn_env | {'EXEC_WRAPPER_DO_RUNTIME_MSG': ''})
  156. self.write_to_tmpfile('autosign_thread_pid',str(t.ep.pid))
  157. import threading
  158. threading.Thread(target=run, name='Autosign wait loop').start()
  159. time.sleep(0.2)
  160. return 'silent'
  161. def autosign_kill_thread(self):
  162. self.spawn('',msg_only=True)
  163. pid = int(self.read_from_tmpfile('autosign_thread_pid'))
  164. self.delete_tmpfile('autosign_thread_pid')
  165. from signal import SIGTERM
  166. imsg(purple(f'Killing autosign wait loop [PID {pid}]'))
  167. try:
  168. os.kill(pid,SIGTERM)
  169. except:
  170. imsg(yellow(f'{pid}: no such process'))
  171. return 'ok'
  172. def _wait_signed(self,desc):
  173. oqmsg_r(gray(f'→ offline wallet{"s" if desc.endswith("s") else ""} signing {desc}'))
  174. assert not self.device_inserted, f'‘{self.asi.dev_label_path}’ is inserted!'
  175. assert not self.asi.mountpoint.is_mount(), f'‘{self.asi.mountpoint}’ is mounted!'
  176. self.insert_device()
  177. while True:
  178. oqmsg_r(gray('.'))
  179. if self.asi.mountpoint.is_mount():
  180. oqmsg_r(gray('..working..'))
  181. break
  182. time.sleep(0.5)
  183. while True:
  184. oqmsg_r(gray('.'))
  185. if not self.asi.mountpoint.is_mount():
  186. oqmsg(gray('..done'))
  187. break
  188. time.sleep(0.5)
  189. imsg('')
  190. self.remove_device()
  191. @property
  192. def device_inserted(self):
  193. return self.asi.dev_label_path.exists()
  194. def insert_device(self):
  195. self.asi.dev_label_path.touch()
  196. def remove_device(self):
  197. if self.asi.dev_label_path.exists():
  198. self.asi.dev_label_path.unlink()
  199. @property
  200. def device_inserted_online(self):
  201. return self.asi_online.dev_label_path.exists()
  202. def insert_device_online(self):
  203. self.asi_online.dev_label_path.touch()
  204. def remove_device_online(self):
  205. if self.asi_online.dev_label_path.exists():
  206. self.asi_online.dev_label_path.unlink()
  207. class CmdTestAutosign(CmdTestAutosignBase):
  208. 'autosigning transactions for all supported coins'
  209. coins = ['btc','bch','ltc','eth']
  210. daemon_coins = ['btc','bch','ltc']
  211. txfile_coins = ['btc','bch','ltc','eth','mm1','etc']
  212. have_online = False
  213. live = False
  214. simulate_led = True
  215. no_insert_check = True
  216. filedir_map = (
  217. ('btc',''),
  218. ('bch',''),
  219. ('ltc','litecoin'),
  220. ('eth','ethereum'),
  221. ('mm1','ethereum'),
  222. ('etc','ethereum_classic'),
  223. )
  224. cmd_group = (
  225. ('start_daemons', 'starting daemons'),
  226. ('copy_tx_files', 'copying transaction files'),
  227. ('gen_key', 'generating key'),
  228. ('create_dfl_wallet', 'creating default MMGen wallet'),
  229. ('run_setup_dfl_wallet', 'running ‘autosign setup’ (with default wallet)'),
  230. ('sign_quiet', 'signing transactions (--quiet)'),
  231. ('remove_signed_txfiles', 'removing signed transaction files'),
  232. ('run_setup_bip39', 'running ‘autosign setup’ (BIP39 mnemonic)'),
  233. ('create_bad_txfiles', 'creating bad transaction files'),
  234. ('sign_full_summary', 'signing transactions (--full-summary)'),
  235. ('remove_signed_txfiles_btc','removing transaction files (BTC only)'),
  236. ('remove_bad_txfiles', 'removing bad transaction files'),
  237. ('sign_led', 'signing transactions (--led - BTC files only)'),
  238. ('remove_signed_txfiles', 'removing signed transaction files'),
  239. ('sign_stealth_led', 'signing transactions (--stealth-led)'),
  240. ('remove_signed_txfiles', 'removing signed transaction files'),
  241. ('copy_msgfiles', 'copying message files'),
  242. ('sign_quiet_msg', 'signing transactions and messages (--quiet)'),
  243. ('remove_signed_txfiles', 'removing signed transaction files'),
  244. ('create_bad_txfiles2', 'creating bad transaction files'),
  245. ('remove_signed_msgfiles', 'removing signed message files'),
  246. ('create_invalid_msgfile', 'creating invalid message file'),
  247. ('sign_full_summary_msg', 'signing transactions and messages (--full-summary)'),
  248. ('remove_invalid_msgfile', 'removing invalid message file'),
  249. ('remove_bad_txfiles2', 'removing bad transaction files'),
  250. ('sign_no_unsigned_msg', 'signing transactions and messages (nothing to sign)'),
  251. ('stop_daemons', 'stopping daemons'),
  252. )
  253. def __init__(self,trunner,cfgs,spawn):
  254. super().__init__(trunner,cfgs,spawn)
  255. if trunner is None:
  256. return
  257. if self.live and not cfg.exact_output:
  258. die(1,red('autosign_live tests must be run with --exact-output enabled!'))
  259. if self.no_insert_check:
  260. self.opts.append('--no-insert-check')
  261. self.tx_file_ops('set_count') # initialize self.tx_count here so we can resume anywhere
  262. self.bad_tx_count = 0
  263. def gen_msg_fns():
  264. fmap = dict(self.filedir_map)
  265. for coin in self.coins:
  266. if coin == 'xmr':
  267. continue
  268. sdir = os.path.join('test','ref',fmap[coin])
  269. for fn in os.listdir(sdir):
  270. if fn.endswith(f'[{coin.upper()}].rawmsg.json'):
  271. yield os.path.join(sdir,fn)
  272. self.ref_msgfiles = tuple(gen_msg_fns())
  273. self.good_msg_count = 0
  274. self.bad_msg_count = 0
  275. if self.simulate_led:
  276. LEDControl.create_dummy_control_files()
  277. self.have_dummy_control_files = True
  278. self.spawn_env['MMGEN_TEST_SUITE_AUTOSIGN_LED_SIMULATE'] = '1'
  279. def __del__(self):
  280. if hasattr(self,'have_dummy_control_files'):
  281. LEDControl.delete_dummy_control_files()
  282. def gen_key(self):
  283. t = self.spawn( 'mmgen-autosign', self.opts + ['gen_key'] )
  284. t.expect_getend('Wrote key file ')
  285. return t
  286. def create_dfl_wallet(self):
  287. t = self.spawn( 'mmgen-walletconv', [
  288. f'--outdir={cfg.data_dir}',
  289. '--usr-randchars=0', '--quiet', '--hash-preset=1', '--label=foo',
  290. 'test/ref/98831F3A.hex'
  291. ]
  292. )
  293. t.passphrase_new('new MMGen wallet','abc')
  294. t.written_to_file('MMGen wallet')
  295. return t
  296. def run_setup_dfl_wallet(self):
  297. return self.run_setup(mn_type='default',use_dfl_wallet=True)
  298. def run_setup_bip39(self):
  299. return self.run_setup(mn_type='bip39')
  300. def copy_tx_files(self):
  301. self.spawn('',msg_only=True)
  302. return self.tx_file_ops('copy')
  303. def remove_signed_txfiles(self):
  304. self.tx_file_ops('remove_signed')
  305. return 'skip'
  306. def remove_signed_txfiles_btc(self):
  307. self.tx_file_ops('remove_signed',txfile_coins=['btc'])
  308. return 'skip'
  309. def tx_file_ops(self,op,txfile_coins=[]):
  310. assert op in ('copy','set_count','remove_signed')
  311. from .ct_ref import CmdTestRef
  312. def gen():
  313. d = CmdTestRef.sources['ref_tx_file']
  314. dirmap = [e for e in self.filedir_map if e[0] in (txfile_coins or self.txfile_coins)]
  315. for coin,coindir in dirmap:
  316. for network in (0,1):
  317. fn = d[coin][network]
  318. if fn:
  319. yield (coindir,fn)
  320. data = list(gen()) + [('','25EFA3[2.34].testnet.rawtx')] # TX with 2 non-MMGen outputs
  321. self.tx_count = len(data)
  322. if op == 'set_count':
  323. return
  324. self.do_mount()
  325. for coindir,fn in data:
  326. src = joinpath(ref_dir,coindir,fn)
  327. if cfg.debug_utf8:
  328. ext = '.testnet.rawtx' if fn.endswith('.testnet.rawtx') else '.rawtx'
  329. fn = fn[:-len(ext)] + '-α' + ext
  330. target = joinpath(self.asi.mountpoint,'tx',fn)
  331. if not op == 'remove_signed':
  332. shutil.copyfile(src,target)
  333. try:
  334. os.unlink(target.replace('.rawtx','.sigtx'))
  335. except:
  336. pass
  337. self.do_umount()
  338. return 'ok'
  339. def create_bad_txfiles(self):
  340. return self.bad_txfiles('create')
  341. def remove_bad_txfiles(self):
  342. return self.bad_txfiles('remove')
  343. create_bad_txfiles2 = create_bad_txfiles
  344. remove_bad_txfiles2 = remove_bad_txfiles
  345. def bad_txfiles(self,op):
  346. self.do_mount()
  347. # create or delete 2 bad tx files
  348. self.spawn('',msg_only=True)
  349. fns = [joinpath(self.asi.mountpoint,'tx',f'bad{n}.rawtx') for n in (1,2)]
  350. if op == 'create':
  351. for fn in fns:
  352. with open(fn,'w') as fp:
  353. fp.write('bad tx data\n')
  354. self.bad_tx_count = 2
  355. elif op == 'remove':
  356. for fn in fns:
  357. try:
  358. os.unlink(fn)
  359. except:
  360. pass
  361. self.bad_tx_count = 0
  362. self.do_umount()
  363. return 'ok'
  364. def copy_msgfiles(self):
  365. return self.msgfile_ops('copy')
  366. def remove_signed_msgfiles(self):
  367. return self.msgfile_ops('remove_signed')
  368. def create_invalid_msgfile(self):
  369. return self.msgfile_ops('create_invalid')
  370. def remove_invalid_msgfile(self):
  371. return self.msgfile_ops('remove_invalid')
  372. def msgfile_ops(self,op):
  373. self.spawn('',msg_only=True)
  374. destdir = joinpath(self.asi.mountpoint,'msg')
  375. self.do_mount()
  376. os.makedirs(destdir,exist_ok=True)
  377. if op.endswith('_invalid'):
  378. fn = os.path.join(destdir,'DEADBE[BTC].rawmsg.json')
  379. if op == 'create_invalid':
  380. with open(fn,'w') as fp:
  381. fp.write('bad data\n')
  382. self.bad_msg_count += 1
  383. elif op == 'remove_invalid':
  384. os.unlink(fn)
  385. self.bad_msg_count -= 1
  386. else:
  387. for fn in self.ref_msgfiles:
  388. if op == 'copy':
  389. if os.path.basename(fn) == 'ED405C[BTC].rawmsg.json': # contains bad Seed ID
  390. self.bad_msg_count += 1
  391. else:
  392. self.good_msg_count += 1
  393. imsg(f'Copying: {fn} -> {destdir}')
  394. shutil.copy2(fn,destdir)
  395. elif op == 'remove_signed':
  396. os.unlink(os.path.join( destdir, os.path.basename(fn).replace('rawmsg','sigmsg') ))
  397. self.do_umount()
  398. return 'ok'
  399. def do_sign(self, args, have_msg=False):
  400. tx_desc = Signable.transaction.desc
  401. t = self.spawn('mmgen-autosign', self.opts + args)
  402. t.expect(
  403. f'{self.tx_count} {tx_desc}{suf(self.tx_count)} signed' if self.tx_count else
  404. f'No unsigned {tx_desc}s')
  405. if self.bad_tx_count:
  406. t.expect(f'{self.bad_tx_count} {tx_desc}{suf(self.bad_tx_count)} failed to sign')
  407. t.req_exit_val = 1
  408. if have_msg:
  409. t.expect(
  410. f'{self.good_msg_count} message file{suf(self.good_msg_count)}{{0,1}} signed'
  411. if self.good_msg_count else
  412. 'No unsigned message files', regex=True)
  413. if self.bad_msg_count:
  414. t.expect(
  415. f'{self.bad_msg_count} message file{suf(self.bad_msg_count)}{{0,1}} failed to sign',
  416. regex = True)
  417. t.req_exit_val = 1
  418. if 'wait' in args:
  419. t.expect('Waiting')
  420. imsg(purple('\nKilling wait loop!'))
  421. t.kill(2)
  422. t.req_exit_val = 1
  423. else:
  424. t.read()
  425. imsg('')
  426. return t
  427. def sign_quiet(self):
  428. return self.do_sign(['--quiet','wait'])
  429. def sign_full_summary(self):
  430. return self.do_sign(['--full-summary','wait'])
  431. def sign_led(self):
  432. return self.do_sign(['--quiet','--led'])
  433. def sign_stealth_led(self):
  434. return self.do_sign(['--quiet','--stealth-led','wait'])
  435. def sign_quiet_msg(self):
  436. return self.do_sign(['--quiet','wait'],have_msg=True)
  437. def sign_full_summary_msg(self):
  438. return self.do_sign(['--full-summary','wait'],have_msg=True)
  439. def sign_no_unsigned_msg(self):
  440. self.tx_count = 0
  441. self.good_msg_count = 0
  442. self.bad_msg_count = 0
  443. return self.do_sign(['--quiet','wait'],have_msg=True)
  444. class CmdTestAutosignBTC(CmdTestAutosign):
  445. 'autosigning BTC transactions'
  446. coins = ['btc']
  447. daemon_coins = ['btc']
  448. txfile_coins = ['btc']
  449. class CmdTestAutosignLive(CmdTestAutosignBTC):
  450. 'live autosigning BTC transactions'
  451. live = True
  452. simulate_led = False
  453. no_insert_check = False
  454. cmd_group = (
  455. ('start_daemons', 'starting daemons'),
  456. ('copy_tx_files', 'copying transaction files'),
  457. ('gen_key', 'generating key'),
  458. ('run_setup_mmgen', 'running ‘autosign setup’ (MMGen native mnemonic)'),
  459. ('sign_live', 'signing transactions'),
  460. ('create_bad_txfiles', 'creating bad transaction files'),
  461. ('sign_live_led', 'signing transactions (--led)'),
  462. ('remove_bad_txfiles', 'removing bad transaction files'),
  463. ('sign_live_stealth_led','signing transactions (--stealth-led)'),
  464. ('stop_daemons', 'stopping daemons'),
  465. )
  466. def __init__(self,trunner,cfgs,spawn):
  467. super().__init__(trunner,cfgs,spawn)
  468. if trunner is None:
  469. return
  470. try:
  471. cf = LEDControl(enabled=True,simulate=self.simulate_led)
  472. except Exception as e:
  473. msg(str(e))
  474. die(2,'LEDControl initialization failed')
  475. for path in (cf.board.status,cf.board.trigger):
  476. if path:
  477. run(['sudo','chmod','0666',path],check=True)
  478. def run_setup_mmgen(self):
  479. return self.run_setup(mn_type='mmgen',use_dfl_wallet=None)
  480. def sign_live(self):
  481. return self.do_sign_live([])
  482. def sign_live_led(self):
  483. return self.do_sign_live(['--led'])
  484. def sign_live_stealth_led(self):
  485. return self.do_sign_live(['--stealth-led'])
  486. def do_sign_live(self,led_opts):
  487. def prompt_remove():
  488. omsg_r(blue('\nRemove removable device and then hit ENTER '))
  489. input()
  490. def prompt_insert_sign(t):
  491. omsg(blue(insert_msg))
  492. t.expect(f'{self.tx_count} transactions signed')
  493. if self.bad_tx_count:
  494. t.expect(f'{self.bad_tx_count} transactions failed to sign')
  495. t.expect('Waiting')
  496. if led_opts:
  497. opts_msg = "'" + ' '.join(led_opts) + "'"
  498. info_msg = f"Running 'mmgen-autosign wait' with {led_opts[0]}. " + {
  499. '--led': "The LED should start blinking slowly now",
  500. '--stealth-led': "You should see no LED activity now"
  501. }[led_opts[0]]
  502. insert_msg = 'Insert removable device and watch for fast LED activity during signing'
  503. else:
  504. opts_msg = 'no LED'
  505. info_msg = "Running 'mmgen-autosign wait'"
  506. insert_msg = 'Insert removable device '
  507. omsg(purple(f'Running autosign test with {opts_msg}'))
  508. self.do_umount()
  509. prompt_remove()
  510. omsg(green(info_msg))
  511. t = self.spawn(
  512. 'mmgen-autosign',
  513. self.opts + led_opts + ['--quiet','--no-summary','wait'])
  514. if not cfg.exact_output:
  515. omsg('')
  516. prompt_insert_sign(t)
  517. self.do_mount() # race condition due to device insertion detection
  518. self.remove_signed_txfiles()
  519. self.do_umount()
  520. imsg(purple('\nKilling wait loop!'))
  521. t.kill(2) # 2 = SIGINT
  522. t.req_exit_val = 1
  523. if self.simulate_led and led_opts:
  524. t.expect("Stopping LED")
  525. return t
  526. class CmdTestAutosignLiveSimulate(CmdTestAutosignLive):
  527. 'live autosigning BTC transactions with simulated LED support'
  528. simulate_led = True