mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-08 06:20:56 +00:00
chore(tests): replace function uninitialized_session in conftest by a pytest.marker
[no changelog]
This commit is contained in:
parent
e80bfca6cd
commit
bfc6431cff
@ -374,23 +374,14 @@ def client(
|
|||||||
def session(
|
def session(
|
||||||
request: pytest.FixtureRequest, client: Client
|
request: pytest.FixtureRequest, client: Client
|
||||||
) -> t.Generator[SessionDebugWrapper, None, None]:
|
) -> t.Generator[SessionDebugWrapper, None, None]:
|
||||||
derive_cardano = bool(request.node.get_closest_marker("cardano"))
|
if bool(request.node.get_closest_marker("uninitialized_session")):
|
||||||
passphrase = client.passphrase or ""
|
session = client.get_management_session()
|
||||||
session = client.get_session(derive_cardano=derive_cardano, passphrase=passphrase)
|
else:
|
||||||
try:
|
derive_cardano = bool(request.node.get_closest_marker("cardano"))
|
||||||
yield SessionDebugWrapper(session)
|
passphrase = client.passphrase or ""
|
||||||
finally:
|
session = client.get_session(
|
||||||
pass
|
derive_cardano=derive_cardano, passphrase=passphrase
|
||||||
# TODO
|
)
|
||||||
# session.end()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
|
||||||
def uninitialized_session(
|
|
||||||
request: pytest.FixtureRequest,
|
|
||||||
client: Client,
|
|
||||||
) -> t.Generator[SessionDebugWrapper, None, None]:
|
|
||||||
session = client.get_management_session()
|
|
||||||
try:
|
try:
|
||||||
yield SessionDebugWrapper(session)
|
yield SessionDebugWrapper(session)
|
||||||
finally:
|
finally:
|
||||||
@ -509,6 +500,10 @@ def pytest_configure(config: "Config") -> None:
|
|||||||
"markers",
|
"markers",
|
||||||
'setup_client(mnemonic="all all all...", pin=None, passphrase=False, uninitialized=False): configure the client instance',
|
'setup_client(mnemonic="all all all...", pin=None, passphrase=False, uninitialized=False): configure the client instance',
|
||||||
)
|
)
|
||||||
|
config.addinivalue_line(
|
||||||
|
"markers",
|
||||||
|
"uninitialized_session: use uninitialized session instance",
|
||||||
|
)
|
||||||
with open(os.path.join(os.path.dirname(__file__), "REGISTERED_MARKERS")) as f:
|
with open(os.path.join(os.path.dirname(__file__), "REGISTERED_MARKERS")) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
config.addinivalue_line("markers", line.strip())
|
config.addinivalue_line("markers", line.strip())
|
||||||
|
@ -29,18 +29,19 @@ from ..common import (
|
|||||||
|
|
||||||
pytestmark = [
|
pytestmark = [
|
||||||
pytest.mark.setup_client(uninitialized=True),
|
pytest.mark.setup_client(uninitialized=True),
|
||||||
|
pytest.mark.uninitialized_session,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_load_device_1(uninitialized_session: Session):
|
def test_load_device_1(session: Session):
|
||||||
debuglink.load_device(
|
debuglink.load_device(
|
||||||
uninitialized_session,
|
session,
|
||||||
mnemonic=MNEMONIC12,
|
mnemonic=MNEMONIC12,
|
||||||
pin="",
|
pin="",
|
||||||
passphrase_protection=False,
|
passphrase_protection=False,
|
||||||
label="test",
|
label="test",
|
||||||
)
|
)
|
||||||
session: Session = uninitialized_session.client.get_session()
|
session: Session = session.client.get_session()
|
||||||
state = session.client.debug.state()
|
state = session.client.debug.state()
|
||||||
assert state.mnemonic_secret == MNEMONIC12.encode()
|
assert state.mnemonic_secret == MNEMONIC12.encode()
|
||||||
assert state.pin is None
|
assert state.pin is None
|
||||||
@ -50,15 +51,15 @@ def test_load_device_1(uninitialized_session: Session):
|
|||||||
assert address == "mkqRFzxmkCGX9jxgpqqFHcxRUmLJcLDBer"
|
assert address == "mkqRFzxmkCGX9jxgpqqFHcxRUmLJcLDBer"
|
||||||
|
|
||||||
|
|
||||||
def test_load_device_2(uninitialized_session: Session):
|
def test_load_device_2(session: Session):
|
||||||
debuglink.load_device(
|
debuglink.load_device(
|
||||||
uninitialized_session,
|
session,
|
||||||
mnemonic=MNEMONIC12,
|
mnemonic=MNEMONIC12,
|
||||||
pin="1234",
|
pin="1234",
|
||||||
passphrase_protection=True,
|
passphrase_protection=True,
|
||||||
label="test",
|
label="test",
|
||||||
)
|
)
|
||||||
session: Session = uninitialized_session.client.get_session(passphrase="passphrase")
|
session: Session = session.client.get_session(passphrase="passphrase")
|
||||||
|
|
||||||
state = session.client.debug.state()
|
state = session.client.debug.state()
|
||||||
assert state.mnemonic_secret == MNEMONIC12.encode()
|
assert state.mnemonic_secret == MNEMONIC12.encode()
|
||||||
@ -73,8 +74,8 @@ def test_load_device_2(uninitialized_session: Session):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.models("core")
|
@pytest.mark.models("core")
|
||||||
def test_load_device_slip39_basic(uninitialized_session: Session):
|
def test_load_device_slip39_basic(session: Session):
|
||||||
session = uninitialized_session
|
session = session
|
||||||
debuglink.load_device(
|
debuglink.load_device(
|
||||||
session,
|
session,
|
||||||
mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6,
|
mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6,
|
||||||
@ -86,8 +87,8 @@ def test_load_device_slip39_basic(uninitialized_session: Session):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.models("core")
|
@pytest.mark.models("core")
|
||||||
def test_load_device_slip39_advanced(uninitialized_session: Session):
|
def test_load_device_slip39_advanced(session: Session):
|
||||||
session = uninitialized_session
|
session = session
|
||||||
debuglink.load_device(
|
debuglink.load_device(
|
||||||
session,
|
session,
|
||||||
mnemonic=MNEMONIC_SLIP39_ADVANCED_20,
|
mnemonic=MNEMONIC_SLIP39_ADVANCED_20,
|
||||||
@ -98,7 +99,7 @@ def test_load_device_slip39_advanced(uninitialized_session: Session):
|
|||||||
assert session.features.backup_type == BackupType.Slip39_Advanced
|
assert session.features.backup_type == BackupType.Slip39_Advanced
|
||||||
|
|
||||||
|
|
||||||
def test_load_device_utf(uninitialized_session: Session):
|
def test_load_device_utf(session: Session):
|
||||||
words_nfkd = "Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
|
words_nfkd = "Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
|
||||||
words_nfc = "P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
|
words_nfc = "P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
|
||||||
words_nfkc = "P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
|
words_nfkc = "P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
|
||||||
@ -114,14 +115,14 @@ def test_load_device_utf(uninitialized_session: Session):
|
|||||||
)
|
)
|
||||||
|
|
||||||
debuglink.load_device(
|
debuglink.load_device(
|
||||||
uninitialized_session,
|
session,
|
||||||
mnemonic=words_nfkd,
|
mnemonic=words_nfkd,
|
||||||
pin="",
|
pin="",
|
||||||
passphrase_protection=True,
|
passphrase_protection=True,
|
||||||
label="test",
|
label="test",
|
||||||
skip_checksum=True,
|
skip_checksum=True,
|
||||||
)
|
)
|
||||||
session: Session = uninitialized_session.client.get_session()
|
session: Session = session.client.get_session()
|
||||||
session.client.use_passphrase(passphrase_nfkd)
|
session.client.use_passphrase(passphrase_nfkd)
|
||||||
address_nfkd = get_test_address(session)
|
address_nfkd = get_test_address(session)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user