Skip to content

Commit

Permalink
test(core): use internal model names
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
mmilata committed Mar 12, 2024
1 parent 73a7223 commit e7f2d3f
Show file tree
Hide file tree
Showing 102 changed files with 294 additions and 286 deletions.
4 changes: 2 additions & 2 deletions docs/developers/hello_world_feature_TT.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ VECTORS = ( # name, amount, show_display
)


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
@pytest.mark.parametrize("name, amount, show_display", VECTORS)
def test_hello_world(
client: Client, name: str, amount: Optional[int], show_display: bool
Expand All @@ -325,7 +325,7 @@ def test_hello_world(

Unlike in unit tests, [pytest](https://docs.pytest.org) is used as the test framework, which is more suitable for bigger and more complex test suites.

As the functionality is developed only for `TT`, to not break the `CI`, we want to skip this test's execution for model `T1`, by adding `@pytest.mark.skip_t1` decorator.
As the functionality is developed only for `TT`, to not break the `CI`, we want to skip this test's execution for model `T1`, by adding `@pytest.mark.skip_t1b1` decorator.

We are also using the `@pytest.mark.parametrize` decorator, which is an efficient way of testing multiple inputs into the same test case.

Expand Down
8 changes: 4 additions & 4 deletions docs/tests/device-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ the following marker:
This marker must be registered in `REGISTERED_MARKERS` file in `tests` folder.

Tests can be run only for specific models - it is done by disallowing the tests for the other models.
`@pytest.mark.skip_t1`
`@pytest.mark.skip_t2`
`@pytest.mark.skip_tr`
`@pytest.mark.skip_t1b1`
`@pytest.mark.skip_t2t1`
`@pytest.mark.skip_t2b1`
`@pytest.mark.skip_t3t1`
are valid markers to skip current test for T1, TT and TR respectively.
are valid markers to skip current test for Model 1, Model T, Safe 3, and T3T1 respectively.

[pytest-random-order]: https://pypi.org/project/pytest-random-order/

Expand Down
2 changes: 1 addition & 1 deletion tests/click_tests/test_passphrase_tr.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from ..device_handler import BackgroundDeviceHandler


pytestmark = [pytest.mark.skip_t1, pytest.mark.skip_t2, pytest.mark.skip_t3t1]
pytestmark = [pytest.mark.skip_t1b1, pytest.mark.skip_t2t1, pytest.mark.skip_t3t1]

# Testing the maximum length is really 50
# TODO: show some UI message when length reaches 50?
Expand Down
2 changes: 1 addition & 1 deletion tests/click_tests/test_passphrase_tt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ..device_handler import BackgroundDeviceHandler


pytestmark = [pytest.mark.skip_t1, pytest.mark.skip_tr]
pytestmark = [pytest.mark.skip_t1b1, pytest.mark.skip_t2b1]

# TODO: it is not possible to cancel the passphrase entry on TT
# NOTE: the prompt (underscoring) is not there when a space is entered
Expand Down
4 changes: 2 additions & 2 deletions tests/click_tests/test_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from ..device_handler import BackgroundDeviceHandler


pytestmark = pytest.mark.skip_t1
pytestmark = pytest.mark.skip_t1b1

PIN_CANCELLED = pytest.raises(exceptions.TrezorFailure, match="PIN entry cancelled")
PIN_INVALID = pytest.raises(exceptions.TrezorFailure, match="PIN invalid")
Expand Down Expand Up @@ -285,7 +285,7 @@ def test_pin_incorrect(device_handler: "BackgroundDeviceHandler"):
_input_see_confirm(debug, PIN4)


@pytest.mark.skip_tr("TODO: will we support cancelling on TR?")
@pytest.mark.skip_t2b1("TODO: will we support cancelling on T2B1?")
@pytest.mark.setup_client(pin=PIN4)
def test_pin_cancel(device_handler: "BackgroundDeviceHandler"):
with PIN_CANCELLED, prepare(device_handler) as debug:
Expand Down
2 changes: 1 addition & 1 deletion tests/click_tests/test_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ..device_handler import BackgroundDeviceHandler


pytestmark = [pytest.mark.skip_t1]
pytestmark = [pytest.mark.skip_t1b1]


@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion tests/click_tests/test_reset_bip39.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ..device_handler import BackgroundDeviceHandler


pytestmark = [pytest.mark.skip_t1]
pytestmark = [pytest.mark.skip_t1b1]


@pytest.mark.setup_client(uninitialized=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/click_tests/test_reset_slip39_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ..device_handler import BackgroundDeviceHandler


pytestmark = [pytest.mark.skip_t1]
pytestmark = [pytest.mark.skip_t1b1]


@pytest.mark.setup_client(uninitialized=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/click_tests/test_reset_slip39_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ..device_handler import BackgroundDeviceHandler


pytestmark = [pytest.mark.skip_t1]
pytestmark = [pytest.mark.skip_t1b1]


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion tests/click_tests/test_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


# T2B1-only
pytestmark = [pytest.mark.skip_t1, pytest.mark.skip_t2, pytest.mark.skip_t3t1]
pytestmark = [pytest.mark.skip_t1b1, pytest.mark.skip_t2t1, pytest.mark.skip_t3t1]


@contextmanager
Expand Down
6 changes: 3 additions & 3 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def parametrize_using_common_fixtures(*paths: str) -> "MarkDecorator":
skip_marks = []
for skip_model in skip_models:
if skip_model in ("t1", "t1b1"):
skip_marks.append(pytest.mark.skip_t1)
skip_marks.append(pytest.mark.skip_t1b1)
if skip_model in ("t2", "t2t1"):
skip_marks.append(pytest.mark.skip_t2)
skip_marks.append(pytest.mark.skip_t2t1)
if skip_model in ("tr", "t2b1"):
skip_marks.append(pytest.mark.skip_tr)
skip_marks.append(pytest.mark.skip_t2b1)
if skip_model == "t3t1":
skip_marks.append(pytest.mark.skip_t3t1)

Expand Down
33 changes: 20 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _raw_client(request: pytest.FixtureRequest) -> Client:

# Setting the appropriate language
# Not doing it for T1
if client.features.model != "1":
if client.model is not models.T1B1:
lang = request.session.config.getoption("lang") or "en"
assert isinstance(lang, str)
translations.set_language(client, lang)
Expand Down Expand Up @@ -179,8 +179,8 @@ def client(
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'. Same with TR.
If 'skip_t2t1' is used and TT is connected, the test is skipped. Vice versa with T1
and 'skip_t1b1'. Same with T2B1, T3T1.
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`
Expand All @@ -198,15 +198,21 @@ def client(
@pytest.mark.experimental
"""
if request.node.get_closest_marker("skip_t2") and _raw_client.features.model == "T":
if (
request.node.get_closest_marker("skip_t2t1")
and _raw_client.model is models.T2T1
):
pytest.skip("Test excluded on Trezor T")
if request.node.get_closest_marker("skip_t1") and _raw_client.features.model == "1":
if (
request.node.get_closest_marker("skip_t1b1")
and _raw_client.model is models.T1B1
):
pytest.skip("Test excluded on Trezor 1")
if (
request.node.get_closest_marker("skip_tr")
and _raw_client.features.model == "Safe 3"
request.node.get_closest_marker("skip_t2b1")
and _raw_client.model is models.T2B1
):
pytest.skip("Test excluded on Trezor R")
pytest.skip("Test excluded on Trezor T2B1")
if (
request.node.get_closest_marker("skip_t3t1")
and _raw_client.model is models.T3T1
Expand Down Expand Up @@ -245,7 +251,7 @@ def client(
wipe_device(_raw_client)

# Load language again, as it got erased in wipe
if _raw_client.features.model != "1":
if _raw_client.model is not models.T1B1:
lang = request.session.config.getoption("lang") or "en"
assert isinstance(lang, str)
if lang != "en":
Expand Down Expand Up @@ -392,9 +398,9 @@ def pytest_configure(config: "Config") -> None:
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")
config.addinivalue_line("markers", "skip_tr: skip the test on Trezor R")
config.addinivalue_line("markers", "skip_t1b1: skip the test on Trezor One")
config.addinivalue_line("markers", "skip_t2t1: skip the test on Trezor T")
config.addinivalue_line("markers", "skip_t2b1: skip the test on Trezor T2B1")
config.addinivalue_line("markers", "skip_t3t1: skip the test on Trezor T3T1")
config.addinivalue_line(
"markers", "experimental: enable experimental features on Trezor"
Expand All @@ -419,7 +425,8 @@ def pytest_runtest_setup(item: pytest.Item) -> None:
both T1 and TT.
"""
if all(
item.get_closest_marker(marker) for marker in ("skip_t1", "skip_t2", "skip_tr")
item.get_closest_marker(marker)
for marker in ("skip_t1b1", "skip_t2t1", "skip_t2b1")
):
raise RuntimeError("Don't skip tests for all trezor models!")

Expand Down
2 changes: 1 addition & 1 deletion tests/device_tests/binance/test_get_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
pytestmark = [
pytest.mark.altcoin,
pytest.mark.binance,
pytest.mark.skip_t1, # T1 support is not planned
pytest.mark.skip_t1b1, # T1 support is not planned
pytest.mark.setup_client(
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin"
),
Expand Down
2 changes: 1 addition & 1 deletion tests/device_tests/binance/test_get_public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@pytest.mark.altcoin
@pytest.mark.binance
@pytest.mark.skip_t1 # T1 support is not planned
@pytest.mark.skip_t1b1 # T1 support is not planned
@pytest.mark.setup_client(
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/device_tests/binance/test_sign_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

@pytest.mark.altcoin
@pytest.mark.binance
@pytest.mark.skip_t1 # T1 support is not planned
@pytest.mark.skip_t1b1 # T1 support is not planned
@pytest.mark.setup_client(
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/device_tests/bitcoin/test_bcash.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def getmultisig(chain, nr, signatures):
)


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
def test_send_bch_external_presigned(client: Client):
inp1 = messages.TxInputType(
# address_n=parse_path("44'/145'/0'/1/0"),
Expand Down
4 changes: 2 additions & 2 deletions tests/device_tests/bitcoin/test_bgold.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"a63dbedd8cd284bf0d3c468e84b9b0eeb14c3a08824eab8f80e7723a299f30db"
)

pytestmark = [pytest.mark.altcoin, pytest.mark.skip_tr]
pytestmark = [pytest.mark.altcoin, pytest.mark.skip_t2b1]


# All data taken from T1
Expand Down Expand Up @@ -548,7 +548,7 @@ def test_send_mixed_inputs(client: Client):
)


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
def test_send_btg_external_presigned(client: Client):
# NOTE: fake input tx used

Expand Down
2 changes: 1 addition & 1 deletion tests/device_tests/bitcoin/test_dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"15575a1c874bd60a819884e116c42e6791c8283ce1fc3b79f0d18531a61bbb8a"
)

pytestmark = [pytest.mark.altcoin, pytest.mark.skip_tr]
pytestmark = [pytest.mark.altcoin, pytest.mark.skip_t2b1]


def test_send_dash(client: Client):
Expand Down
6 changes: 3 additions & 3 deletions tests/device_tests/bitcoin/test_decred.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
pytestmark = [
pytest.mark.altcoin,
pytest.mark.decred,
pytest.mark.skip_tr,
pytest.mark.skip_t2b1,
pytest.mark.skip_t3t1,
]

Expand Down Expand Up @@ -105,7 +105,7 @@ def test_send_decred(client: Client):
)


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
def test_purchase_ticket_decred(client: Client):
# NOTE: fake input tx used

Expand Down Expand Up @@ -168,7 +168,7 @@ def test_purchase_ticket_decred(client: Client):
)


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
def test_spend_from_stake_generation_and_revocation_decred(client: Client):
# NOTE: fake input tx used

Expand Down
2 changes: 1 addition & 1 deletion tests/device_tests/bitcoin/test_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _address_n(purpose, coin, account, script_type):
return res


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
@pytest.mark.parametrize(
"coin, account, purpose, script_type, descriptors", VECTORS_DESCRIPTORS
)
Expand Down
4 changes: 2 additions & 2 deletions tests/device_tests/bitcoin/test_getaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_elements(client: Client):
)


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
def test_address_mac(client: Client):
resp = btc.get_authenticated_address(
client, "Bitcoin", parse_path("m/44h/0h/0h/1/0")
Expand All @@ -163,7 +163,7 @@ def test_address_mac(client: Client):
assert resp.mac is None


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
@pytest.mark.altcoin
def test_altcoin_address_mac(client: Client):
resp = btc.get_authenticated_address(
Expand Down
10 changes: 5 additions & 5 deletions tests/device_tests/bitcoin/test_getaddress_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
)


@pytest.mark.skip_t2
@pytest.mark.skip_tr
@pytest.mark.skip_t2t1
@pytest.mark.skip_t2b1
@pytest.mark.skip_t3t1
@pytest.mark.parametrize("path, script_type, address", VECTORS)
def test_show_t1(
Expand All @@ -78,7 +78,7 @@ def input_flow_t1():
)


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
@pytest.mark.parametrize("chunkify", (True, False))
@pytest.mark.parametrize("path, script_type, address", VECTORS)
def test_show_tt(
Expand All @@ -104,7 +104,7 @@ def test_show_tt(
)


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
@pytest.mark.parametrize("path, script_type, address", VECTORS)
def test_show_cancel(
client: Client, path: str, script_type: messages.InputScriptType, address: str
Expand Down Expand Up @@ -231,7 +231,7 @@ def test_show_multisig_3(client: Client):
)


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
@pytest.mark.multisig
@pytest.mark.parametrize(
"script_type, bip48_type, address, xpubs, ignore_xpub_magic", VECTORS_MULTISIG
Expand Down
2 changes: 1 addition & 1 deletion tests/device_tests/bitcoin/test_getpublickey.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_get_public_node(client: Client, coin_name, xpub_magic, path, xpub):
assert bip32.serialize(res.node, xpub_magic) == xpub


@pytest.mark.skip_t1
@pytest.mark.skip_t1b1
@pytest.mark.parametrize("coin_name, xpub_magic, path, xpub", VECTORS_BITCOIN)
def test_get_public_node_show(client: Client, coin_name, xpub_magic, path, xpub):
with client:
Expand Down
4 changes: 2 additions & 2 deletions tests/device_tests/bitcoin/test_multisig.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import pytest

from trezorlib import btc, messages
from trezorlib import btc, messages, models
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_missing_pubkey(client: Client):
with pytest.raises(TrezorFailure) as exc:
btc.sign_tx(client, "Bitcoin", [inp1], [out1], prev_txes=TX_API)

if client.features.model == "1":
if client.model is models.T1B1:
assert exc.value.message.endswith("Failed to derive scriptPubKey")
else:
assert exc.value.message.endswith("Pubkey not found in multisig script")
Expand Down
Loading

0 comments on commit e7f2d3f

Please sign in to comment.