autosign: improve summary output, ts_autosign: refactor mnemonic entry code
This commit is contained in:
parent
13ab25764f
commit
85236cd601
3 changed files with 54 additions and 50 deletions
|
|
@ -166,7 +166,7 @@ def do_umount():
|
||||||
msg('Unmounting '+mountpoint)
|
msg('Unmounting '+mountpoint)
|
||||||
subprocess.call(['umount',mountpoint])
|
subprocess.call(['umount',mountpoint])
|
||||||
|
|
||||||
def sign_tx_file(txfile):
|
def sign_tx_file(txfile,signed_txs):
|
||||||
try:
|
try:
|
||||||
g.testnet = False
|
g.testnet = False
|
||||||
g.coin = 'BTC'
|
g.coin = 'BTC'
|
||||||
|
|
@ -194,7 +194,7 @@ def sign_tx_file(txfile):
|
||||||
|
|
||||||
if txsign(tx,wfs,None,None):
|
if txsign(tx,wfs,None,None):
|
||||||
tx.write_to_file(ask_write=False)
|
tx.write_to_file(ask_write=False)
|
||||||
txlist.append(tx)
|
signed_txs.append(tx)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
@ -211,17 +211,21 @@ def sign():
|
||||||
unsigned = [os.path.join(tx_dir,f) for f in raw if f[:-6] not in signed]
|
unsigned = [os.path.join(tx_dir,f) for f in raw if f[:-6] not in signed]
|
||||||
|
|
||||||
if unsigned:
|
if unsigned:
|
||||||
fails = 0
|
signed_txs,fails = [],[]
|
||||||
for txfile in unsigned:
|
for txfile in unsigned:
|
||||||
ret = sign_tx_file(txfile)
|
ret = sign_tx_file(txfile,signed_txs)
|
||||||
if not ret:
|
if not ret:
|
||||||
fails += 1
|
fails.append(txfile)
|
||||||
qmsg('')
|
qmsg('')
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
n_ok = len(unsigned) - fails
|
msg('{} transaction{} signed'.format(len(signed_txs),suf(signed_txs)))
|
||||||
msg('{} transaction{} signed'.format(n_ok,suf(n_ok)))
|
|
||||||
if fails:
|
if fails:
|
||||||
ymsg('{} transaction{} failed to sign'.format(fails,suf(fails)))
|
rmsg('{} transaction{} failed to sign'.format(len(fails),suf(fails)))
|
||||||
|
if signed_txs:
|
||||||
|
print_summary(signed_txs)
|
||||||
|
if fails:
|
||||||
|
rmsg('{}Failed transactions:'.format('' if opt.full_summary else '\n'))
|
||||||
|
rmsg(' ' + '\n '.join(sorted(fails)) + '\n')
|
||||||
return False if fails else True
|
return False if fails else True
|
||||||
else:
|
else:
|
||||||
msg('No unsigned transactions')
|
msg('No unsigned transactions')
|
||||||
|
|
@ -246,17 +250,17 @@ def decrypt_wallets():
|
||||||
return False if fails else True
|
return False if fails else True
|
||||||
|
|
||||||
|
|
||||||
def print_summary():
|
def print_summary(signed_txs):
|
||||||
|
|
||||||
if opt.full_summary:
|
if opt.full_summary:
|
||||||
bmsg('\nAutosign summary:')
|
bmsg('\nAutosign summary:\n')
|
||||||
for tx in txlist:
|
for tx in signed_txs:
|
||||||
init_coin(tx.coin,tx.chain == 'testnet')
|
init_coin(tx.coin,tx.chain == 'testnet')
|
||||||
msg_r(tx.format_view(terse=True))
|
msg_r(tx.format_view(terse=True))
|
||||||
return
|
return
|
||||||
|
|
||||||
body = []
|
body = []
|
||||||
for tx in txlist:
|
for tx in signed_txs:
|
||||||
non_mmgen = [o for o in tx.outputs if not o.mmid]
|
non_mmgen = [o for o in tx.outputs if not o.mmid]
|
||||||
if non_mmgen:
|
if non_mmgen:
|
||||||
body.append((tx,non_mmgen))
|
body.append((tx,non_mmgen))
|
||||||
|
|
@ -282,11 +286,7 @@ def do_sign():
|
||||||
key_ok = decrypt_wallets()
|
key_ok = decrypt_wallets()
|
||||||
if key_ok:
|
if key_ok:
|
||||||
if opt.stealth_led: set_led('busy')
|
if opt.stealth_led: set_led('busy')
|
||||||
global txlist
|
|
||||||
txlist = []
|
|
||||||
ret = sign()
|
ret = sign()
|
||||||
print_summary()
|
|
||||||
txlist = []
|
|
||||||
do_umount()
|
do_umount()
|
||||||
set_led(('standby','off','error')[(not ret)*2 or bool(opt.stealth_led)])
|
set_led(('standby','off','error')[(not ret)*2 or bool(opt.stealth_led)])
|
||||||
return ret
|
return ret
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
common.py: Shared routines and data for the test.py test suite
|
common.py: Shared routines and data for the test.py test suite
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os,subprocess
|
import os,time,subprocess
|
||||||
from mmgen.common import *
|
from mmgen.common import *
|
||||||
|
|
||||||
log_file = 'test.py.log'
|
log_file = 'test.py.log'
|
||||||
|
|
@ -168,3 +168,28 @@ def get_label(do_shuffle=False):
|
||||||
if do_shuffle: shuffle(labels)
|
if do_shuffle: shuffle(labels)
|
||||||
label_iter = iter(labels)
|
label_iter = iter(labels)
|
||||||
return next(label_iter)
|
return next(label_iter)
|
||||||
|
|
||||||
|
def stealth_mnemonic_entry(t,mn):
|
||||||
|
wnum = 1
|
||||||
|
max_wordlen = 12
|
||||||
|
|
||||||
|
def get_pad_chars(n):
|
||||||
|
ret = ''
|
||||||
|
for i in range(n):
|
||||||
|
m = int(os.urandom(1).hex(),16) % 32
|
||||||
|
ret += r'123579!@#$%^&*()_+-=[]{}"?/,.<>|'[m]
|
||||||
|
return ret
|
||||||
|
|
||||||
|
for i in range(len(mn)):
|
||||||
|
w = mn[i]
|
||||||
|
if len(w) > 5:
|
||||||
|
w = w + '\n'
|
||||||
|
else:
|
||||||
|
w = get_pad_chars(3 if randbool() else 0) + w[0] + get_pad_chars(3) + w[1:] + get_pad_chars(7)
|
||||||
|
w = w[:max_wordlen+1]
|
||||||
|
em,rm = 'Enter word #{}: ','Repeat word #{}: '
|
||||||
|
ret = t.expect((em.format(wnum),rm.format(wnum-1)))
|
||||||
|
if ret == 0: wnum += 1
|
||||||
|
for j in range(len(w)):
|
||||||
|
t.send(w[j])
|
||||||
|
time.sleep(0.005)
|
||||||
|
|
|
||||||
|
|
@ -67,29 +67,7 @@ class TestSuiteAutosign(TestSuiteBase):
|
||||||
mn_file = dfl_words_file
|
mn_file = dfl_words_file
|
||||||
mn = read_from_file(mn_file).strip().split()
|
mn = read_from_file(mn_file).strip().split()
|
||||||
mn = ['foo'] + mn[:5] + ['realiz','realized'] + mn[5:]
|
mn = ['foo'] + mn[:5] + ['realiz','realized'] + mn[5:]
|
||||||
wnum = 1
|
stealth_mnemonic_entry(t,mn)
|
||||||
max_wordlen = 12
|
|
||||||
|
|
||||||
def get_pad_chars(n):
|
|
||||||
ret = ''
|
|
||||||
for i in range(n):
|
|
||||||
m = int(os.urandom(1).hex(),16) % 32
|
|
||||||
ret += r'123579!@#$%^&*()_+-=[]{}"?/,.<>|'[m]
|
|
||||||
return ret
|
|
||||||
|
|
||||||
for i in range(len(mn)):
|
|
||||||
w = mn[i]
|
|
||||||
if len(w) > 5:
|
|
||||||
w = w + '\n'
|
|
||||||
else:
|
|
||||||
w = get_pad_chars(3 if randbool() else 0) + w[0] + get_pad_chars(3) + w[1:] + get_pad_chars(7)
|
|
||||||
w = w[:max_wordlen+1]
|
|
||||||
em,rm = 'Enter word #{}: ','Repeat word #{}: '
|
|
||||||
ret = t.expect((em.format(wnum),rm.format(wnum-1)))
|
|
||||||
if ret == 0: wnum += 1
|
|
||||||
for j in range(len(w)):
|
|
||||||
t.send(w[j])
|
|
||||||
time.sleep(0.005)
|
|
||||||
wf = t.written_to_file('Autosign wallet')
|
wf = t.written_to_file('Autosign wallet')
|
||||||
t.ok()
|
t.ok()
|
||||||
|
|
||||||
|
|
@ -114,13 +92,14 @@ class TestSuiteAutosign(TestSuiteBase):
|
||||||
try: os.unlink(target.replace('.rawtx','.sigtx'))
|
try: os.unlink(target.replace('.rawtx','.sigtx'))
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
# make a bad tx file
|
# make 2 bad tx files
|
||||||
bad_tx = joinpath(mountpoint,'tx','bad.rawtx')
|
for n in (1,2):
|
||||||
if include_bad_tx and not remove_signed_only:
|
bad_tx = joinpath(mountpoint,'tx','bad{}.rawtx'.format(n))
|
||||||
open(bad_tx,'w').write('bad tx data')
|
if include_bad_tx and not remove_signed_only:
|
||||||
if not include_bad_tx:
|
open(bad_tx,'w').write('bad tx data')
|
||||||
try: os.unlink(bad_tx)
|
if not include_bad_tx:
|
||||||
except: pass
|
try: os.unlink(bad_tx)
|
||||||
|
except: pass
|
||||||
|
|
||||||
def do_autosign_live(opts,mountpoint,led_opts=[],gen_wallet=True):
|
def do_autosign_live(opts,mountpoint,led_opts=[],gen_wallet=True):
|
||||||
|
|
||||||
|
|
@ -155,7 +134,7 @@ class TestSuiteAutosign(TestSuiteBase):
|
||||||
omsg(blue(m2))
|
omsg(blue(m2))
|
||||||
t.expect('{} transactions signed'.format(txcount))
|
t.expect('{} transactions signed'.format(txcount))
|
||||||
if not led_opts:
|
if not led_opts:
|
||||||
t.expect('1 transaction failed to sign')
|
t.expect('2 transactions failed to sign')
|
||||||
t.expect('Waiting')
|
t.expect('Waiting')
|
||||||
|
|
||||||
do_unmount()
|
do_unmount()
|
||||||
|
|
@ -177,7 +156,7 @@ class TestSuiteAutosign(TestSuiteBase):
|
||||||
copy_files(mountpoint,include_bad_tx=True)
|
copy_files(mountpoint,include_bad_tx=True)
|
||||||
t = self.spawn('mmgen-autosign',opts+['--full-summary','wait'],extra_desc='(sign - full summary)')
|
t = self.spawn('mmgen-autosign',opts+['--full-summary','wait'],extra_desc='(sign - full summary)')
|
||||||
t.expect('{} transactions signed'.format(txcount))
|
t.expect('{} transactions signed'.format(txcount))
|
||||||
t.expect('1 transaction failed to sign')
|
t.expect('2 transactions failed to sign')
|
||||||
t.expect('Waiting')
|
t.expect('Waiting')
|
||||||
t.kill(2)
|
t.kill(2)
|
||||||
t.req_exit_val = 1
|
t.req_exit_val = 1
|
||||||
|
|
@ -187,7 +166,7 @@ class TestSuiteAutosign(TestSuiteBase):
|
||||||
copy_files(mountpoint,remove_signed_only=True)
|
copy_files(mountpoint,remove_signed_only=True)
|
||||||
t = self.spawn('mmgen-autosign',opts+['wait'],extra_desc='(sign)')
|
t = self.spawn('mmgen-autosign',opts+['wait'],extra_desc='(sign)')
|
||||||
t.expect('{} transactions signed'.format(txcount))
|
t.expect('{} transactions signed'.format(txcount))
|
||||||
t.expect('1 transaction failed to sign')
|
t.expect('2 transactions failed to sign')
|
||||||
t.expect('Waiting')
|
t.expect('Waiting')
|
||||||
t.kill(2)
|
t.kill(2)
|
||||||
t.req_exit_val = 1
|
t.req_exit_val = 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue