diff --git a/testing/README.md b/testing/README.md index 1e6d8256..e0820d4e 100644 --- a/testing/README.md +++ b/testing/README.md @@ -3,6 +3,9 @@ None of this code ships on the product itself, but it does get used for testing purposes. +## Dependencies +* 7z + ## Background - pytest is used to track test cases and fixtures, etc diff --git a/testing/conftest.py b/testing/conftest.py index 64ac7c56..415a8960 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -1,6 +1,6 @@ # (c) Copyright 2020 by Coinkite Inc. This file is covered by license found in COPYING-CC. # -import pytest, glob, time, sys, random, re +import pytest, glob, time, sys, random, re, ndef from pprint import pprint from ckcc.protocol import CCProtocolPacker, CCProtoError from helpers import B2A, U2SAT, prandom @@ -418,7 +418,10 @@ def qr_quality_check(): scale=3 rv = Image.new('RGB', (w*scale, ((h*scale)+TH)*count), color=(64,64,64)) y = 0 - fnt = ImageFont.truetype('Courier', size=10) + try: + fnt = ImageFont.truetype('Courier', size=10) + except: + fnt = ImageFont.load_default() dr = ImageDraw.Draw(rv) mw = int((w*scale) / dr.textsize('M', fnt)[0]) @@ -866,7 +869,6 @@ def decode_with_bitcoind(bitcoind): def doit(raw_txn): # verify our understanding of a TXN (and esp its outputs) matches # the same values as what bitcoind generates - try: return bitcoind.decoderawtransaction(B2A(raw_txn)) except ConnectionResetError: @@ -947,7 +949,6 @@ def try_sign_microsd(open_microsd, cap_story, pick_menu_item, goto_home, need_ke # like "try_sign" but use "air gapped" file transfer via microSD def doit(f_or_data, accept=True, finalize=False, accept_ms_import=False, complete=False, encoding='binary', del_after=0): - if f_or_data[0:5] == b'psbt\xff': ip = f_or_data filename = 'memory' @@ -965,7 +966,7 @@ def try_sign_microsd(open_microsd, cap_story, pick_menu_item, goto_home, need_ke pat = microsd_path(psbtname+'*.psbt') for f in glob(pat): assert 'psbt' in f - os.unlink(f) + os.remove(f) if encoding == 'hex': ip = b2a_hex(ip) @@ -986,8 +987,7 @@ def try_sign_microsd(open_microsd, cap_story, pick_menu_item, goto_home, need_ke if 'Choose PSBT file' in story: need_keypress('y') time.sleep(.1) - - pick_menu_item(psbtname+'.psbt') + pick_menu_item(psbtname+'.psbt') time.sleep(.1) @@ -1305,7 +1305,7 @@ def nfc_write(request, only_mk4): @pytest.fixture() def nfc_read_json(nfc_read): def doit(): - import ndef, json + import json got = list(ndef.message_decoder(nfc_read())) assert len(got) == 1 got = got[0] @@ -1317,7 +1317,6 @@ def nfc_read_json(nfc_read): @pytest.fixture() def nfc_read_text(nfc_read): def doit(): - import ndef got = list(ndef.message_decoder(nfc_read())) assert len(got) == 1 got = got[0] diff --git a/testing/devtest/backups.py b/testing/devtest/backups.py index ac85f56b..590e856c 100644 --- a/testing/devtest/backups.py +++ b/testing/devtest/backups.py @@ -98,7 +98,7 @@ async def test_7z(): if had_policy: from hsm import POLICY_FNAME - uos.unlink(POLICY_FNAME) + uos.remove(POLICY_FNAME) assert not hsm.hsm_policy_available() with SFFile(0, ll) as fd: diff --git a/testing/requirements.txt b/testing/requirements.txt index fbe0d4e3..46dbd93c 100644 --- a/testing/requirements.txt +++ b/testing/requirements.txt @@ -13,7 +13,8 @@ zbar-py==1.0.4 # NFC and NDEF handling nfcpy==1.0.3 -ndef==0.2 +# commentt out below dependency 'ndef==0.2' if on debian based OS +#ndef==0.2 # optional, and only helpful if you have a desktop NFC-V capable reader pyscard==2.0.2 diff --git a/testing/test_export.py b/testing/test_export.py index 21515061..58c58111 100644 --- a/testing/test_export.py +++ b/testing/test_export.py @@ -464,7 +464,7 @@ def test_export_public_txt(dev, cap_menu, pick_menu_item, goto_home, cap_story, time.sleep(0.1) title, story = cap_story() - assert 'Saves a text file to' in story + assert 'Saves a text file' in story need_keypress('y') time.sleep(0.1) diff --git a/testing/test_hsm.py b/testing/test_hsm.py index b7b84e61..869c591d 100644 --- a/testing/test_hsm.py +++ b/testing/test_hsm.py @@ -57,7 +57,7 @@ def hsm_reset(dev, sim_exec): # make sure we can setup an HSM now; often need to restart simulator tho # clear defined config - cmd = 'import uos, hsm; uos.unlink(hsm.POLICY_FNAME)' + cmd = 'import uos, hsm; uos.remove(hsm.POLICY_FNAME)' sim_exec(cmd) # reset HSM code, to clear previous HSM setup @@ -74,7 +74,7 @@ def hsm_reset(dev, sim_exec): yield doit try: - cmd = 'import uos, hsm; uos.unlink(hsm.POLICY_FNAME)' + cmd = 'import uos, hsm; uos.remove(hsm.POLICY_FNAME)' sim_exec(cmd) except: pass diff --git a/testing/test_rng.py b/testing/test_rng.py index 1a602302..aa2f20a9 100644 --- a/testing/test_rng.py +++ b/testing/test_rng.py @@ -5,7 +5,7 @@ # - needs "dieharder" installed, see # # - on mac: "brew install dieharder" -# +# - on ubuntu20: "sudo apt-get install dieharder" import pytest, subprocess, os from helpers import B2A diff --git a/unix/variant/ffilib.py b/unix/variant/ffilib.py index dc4d672a..ab6837d4 100644 --- a/unix/variant/ffilib.py +++ b/unix/variant/ffilib.py @@ -14,7 +14,7 @@ def open(name, maxver=10, extra=()): except KeyError: pass def libs(): - if sys.platform == "linux": + if sys.platform in ["linux", "linux2", "coldcard-unix"]: yield '%s.so' % name for i in range(maxver, -1, -1): yield '%s.so.%u' % (name, i)