fixes; passes both Q and mk4

This commit is contained in:
Peter D. Gray 2024-03-28 10:13:45 -04:00
parent fd54ad7314
commit 64a2e5bc91
No known key found for this signature in database
GPG Key ID: A2DCD558C2BE5D7C
4 changed files with 32 additions and 10 deletions

View File

@ -458,7 +458,7 @@ def cap_image(request, sim_exec, is_q1, is_headless):
try:
sim_exec(f"from glob import dis; dis.dis.save_snapshot({fn!r})")
for _ in range(20):
time.sleep(0.010)
time.sleep(0.10)
try:
rv = Image.open(fn)
break
@ -1793,6 +1793,11 @@ def load_export(need_keypress, cap_story, microsd_path, virtdisk_path, nfc_read_
press_cancel() # exit NFC animation
return nfc_export
elif way == "qr":
if 'file written' in story:
assert not is_q1
# mk4 only does QR if fits in normal QR, becaise it can't do BBQr
pytest.skip('no BBQr on Mk4')
need_keypress(key_map["qr"])
time.sleep(0.3)
try:
@ -1800,10 +1805,11 @@ def load_export(need_keypress, cap_story, microsd_path, virtdisk_path, nfc_read_
if file_type == "J":
return json.loads(data)
elif file_type == "U":
return data
return data.decode('utf-8') if not isinstance(data, str) else data
else:
raise NotImplementedError
except:
raise
res = cap_screen_qr().decode('ascii')
try:
return json.loads(res)

View File

@ -46,7 +46,7 @@ def _dev_hw_label(device):
def _pick_menu_item(device, is_Q, text):
print(f"PICK menu item: {text}")
WRAP_IF_OVER = 16 # see ../shared/menu.py
WRAP_IF_OVER = 16 # see ../shared/menu.py .. this is larger of 10 or 16
_need_keypress(device, KEY_HOME if is_Q else "0")
m = _cap_menu(device)
@ -139,4 +139,4 @@ def _enter_complex(device, is_Q, target, apply=False, b39pass=True):
if apply:
_pick_menu_item(device, is_Q, "APPLY")
# EOF
# EOF

View File

@ -60,7 +60,9 @@ def readback_bbqr_ll(cap_screen_qr, sim_exec, cap_screen):
assert part < num_parts
if part in parts:
assert parts[part] == rb
if parts[part] != rb:
print(f"Wrong-read on part {part}")
continue
else:
parts[part] = rb
@ -80,15 +82,27 @@ def readback_bbqr_ll(cap_screen_qr, sim_exec, cap_screen):
def readback_bbqr(readback_bbqr_ll):
# give back just the decoded data and file_type
def doit():
import json
num_parts, encoding, file_type, parts = readback_bbqr_ll()
if num_parts == 0:
# not sent as BBQr .. assume Hex
rb = a2b_hex(parts)
file_type = 'P' if rb[0:4] == b'psbt' else 'T'
# not sent as BBQr .. assume Hex, else base32 but PSBT would be BBQr
# - but might be text too
try:
rb = a2b_hex(parts)
file_type = 'T'
except:
if parts[0] == '{' and parts[-1] == '}':
file_type = 'J'
else:
file_type = 'U'
rb = parts # already a string
else:
_, rb = join_qrs(parts.values())
assert rb[0:2] != 'B$'
return file_type, rb
return doit

View File

@ -525,7 +525,8 @@ def test_export_xpub(use_nfc, acct_num, dev, cap_menu, pick_menu_item, goto_home
press_select()
got_pub = cap_screen_qr().decode('ascii')
else:
assert f'Press {KEY_NFC if is_q1 else "(3)"}' in story
if f'Press {KEY_NFC if is_q1 else "(3)"}' not in story:
raise pytest.skip("NFC disabled")
assert 'NFC' in story
press_nfc()
time.sleep(0.2)
@ -649,7 +650,8 @@ def test_samourai_vs_generic(chain, account, settings_set, pick_menu_item, goto_
pick_menu_item("Segwit P2WPKH") # both postmix and premix are p2wpkh only
file_desc_generic = load_export("sd", label="Descriptor", is_json=False, addr_fmt=AF_P2WPKH)
press_select() # written
press_cancel() # go back to advanced
press_cancel() # back to export submenu
press_cancel() # back to advanced
pick_menu_item("Export Wallet")
pick_menu_item(f"Samourai {account}")
time.sleep(.1)