|
|
|
@ -24,8 +24,6 @@ from trezorlib.device import apply_settings, wipe as wipe_device
|
|
|
|
|
from trezorlib.messages.PassphraseSourceType import HOST as PASSPHRASE_ON_HOST
|
|
|
|
|
from trezorlib.transport import enumerate_devices, get_transport
|
|
|
|
|
|
|
|
|
|
TREZOR_VERSION = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_device():
|
|
|
|
|
path = os.environ.get("TREZOR_PATH")
|
|
|
|
@ -48,20 +46,38 @@ def get_device():
|
|
|
|
|
raise RuntimeError("No debuggable device found")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def device_version():
|
|
|
|
|
client = get_device()
|
|
|
|
|
if client.features.model == "T":
|
|
|
|
|
return 2
|
|
|
|
|
else:
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
|
def client(request):
|
|
|
|
|
client = get_device()
|
|
|
|
|
wipe_device(client)
|
|
|
|
|
"""Client fixture.
|
|
|
|
|
|
|
|
|
|
client.open()
|
|
|
|
|
Every test function that requires a client instance will get it from here.
|
|
|
|
|
If we can't connect to a debuggable device, the test will fail.
|
|
|
|
|
If 'skip_t2' is used and TT is connected, the test is skipped. Vice versa with T1
|
|
|
|
|
and 'skip_t1'.
|
|
|
|
|
|
|
|
|
|
The client instance is wiped and preconfigured with "all all all..." mnemonic, no
|
|
|
|
|
password and no pin. It is possible to customize this with the `setup_client`
|
|
|
|
|
marker.
|
|
|
|
|
|
|
|
|
|
To specify a custom mnemonic and/or custom pin and/or enable passphrase:
|
|
|
|
|
|
|
|
|
|
@pytest.mark.setup_client(mnemonic=MY_MNEMONIC, pin="9999", passphrase=True)
|
|
|
|
|
|
|
|
|
|
To receive a client instance that was not initialized:
|
|
|
|
|
|
|
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
client = get_device()
|
|
|
|
|
except RuntimeError:
|
|
|
|
|
pytest.fail("No debuggable Trezor is available")
|
|
|
|
|
|
|
|
|
|
if request.node.get_closest_marker("skip_t2") and client.features.model == "T":
|
|
|
|
|
pytest.skip("Test excluded on Trezor T")
|
|
|
|
|
if request.node.get_closest_marker("skip_t1") and client.features.model == "1":
|
|
|
|
|
pytest.skip("Test excluded on Trezor 1")
|
|
|
|
|
|
|
|
|
|
wipe_device(client)
|
|
|
|
|
|
|
|
|
|
# fmt: off
|
|
|
|
|
setup_params = dict(
|
|
|
|
@ -92,18 +108,16 @@ def client(request):
|
|
|
|
|
if setup_params["passphrase"] and client.features.model != "1":
|
|
|
|
|
apply_settings(client, passphrase_source=PASSPHRASE_ON_HOST)
|
|
|
|
|
|
|
|
|
|
client.open()
|
|
|
|
|
yield client
|
|
|
|
|
client.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_configure(config):
|
|
|
|
|
# try to figure out trezor version
|
|
|
|
|
global TREZOR_VERSION
|
|
|
|
|
try:
|
|
|
|
|
TREZOR_VERSION = device_version()
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
"""Called at testsuite setup time.
|
|
|
|
|
|
|
|
|
|
Registers known markers, enables verbose output if requested.
|
|
|
|
|
"""
|
|
|
|
|
# register known markers
|
|
|
|
|
config.addinivalue_line("markers", "skip_t1: skip the test on Trezor One")
|
|
|
|
|
config.addinivalue_line("markers", "skip_t2: skip the test on Trezor T")
|
|
|
|
@ -121,23 +135,14 @@ def pytest_configure(config):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_runtest_setup(item):
|
|
|
|
|
"""
|
|
|
|
|
Called for each test item (class, individual tests).
|
|
|
|
|
"""Called for each test item (class, individual tests).
|
|
|
|
|
|
|
|
|
|
Performs custom processing, mainly useful for trezor CI testing:
|
|
|
|
|
* 'skip_t2' tests are skipped on T2 and 'skip_t1' tests are skipped on T1.
|
|
|
|
|
* no test should have both skips at the same time
|
|
|
|
|
Ensures that altcoin tests are skipped, and that no test is skipped on
|
|
|
|
|
both T1 and TT.
|
|
|
|
|
"""
|
|
|
|
|
if TREZOR_VERSION is None:
|
|
|
|
|
pytest.fail("No debuggable Trezor is available")
|
|
|
|
|
|
|
|
|
|
if item.get_closest_marker("skip_t1") and item.get_closest_marker("skip_t2"):
|
|
|
|
|
pytest.fail("Don't skip tests for both trezors!")
|
|
|
|
|
|
|
|
|
|
skip_altcoins = int(os.environ.get("TREZOR_PYTEST_SKIP_ALTCOINS", 0))
|
|
|
|
|
if item.get_closest_marker("altcoin") and skip_altcoins:
|
|
|
|
|
pytest.skip("Skipping altcoin test")
|
|
|
|
|
if item.get_closest_marker("skip_t2") and TREZOR_VERSION == 2:
|
|
|
|
|
pytest.skip("Test excluded on Trezor T")
|
|
|
|
|
if item.get_closest_marker("skip_t1") and TREZOR_VERSION == 1:
|
|
|
|
|
pytest.skip("Test excluded on Trezor 1")
|
|
|
|
|