1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 23:08:14 +00:00

tests/ui: reseed each ui test before running it

This commit is contained in:
Tomas Susanka 2020-01-07 09:16:08 +00:00
parent 8796ca96b9
commit 0c820091a8
14 changed files with 34 additions and 37 deletions

View File

@ -99,7 +99,6 @@ def client(request):
passphrase=False,
needs_backup=False,
no_backup=False,
random_seed=None,
)
marker = request.node.get_closest_marker("setup_client")
@ -129,10 +128,16 @@ def client(request):
client.open()
if setup_params["random_seed"] is not None:
client.debug.reseed(setup_params["random_seed"])
test_ui = request.config.getoption("ui")
if test_ui not in ("", "record", "test"):
raise ValueError("Invalid ui option.")
with ui_tests.screen_recording(client, request):
run_ui_tests = not request.node.get_closest_marker("skip_ui") and test_ui
if run_ui_tests:
client.debug.reseed(0)
with ui_tests.screen_recording(client, request):
yield client
else:
yield client
client.close()

View File

@ -32,7 +32,7 @@ from ..common import (
@pytest.mark.skip_t1 # TODO we want this for t1 too
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC12, random_seed=0)
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC12)
def test_backup_bip39(client):
assert client.features.needs_backup is True
mnemonic = None
@ -71,9 +71,7 @@ def test_backup_bip39(client):
@pytest.mark.skip_t1
@pytest.mark.setup_client(
needs_backup=True, mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6, random_seed=0
)
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6)
def test_backup_slip39_basic(client):
assert client.features.needs_backup is True
mnemonics = []
@ -138,9 +136,7 @@ def test_backup_slip39_basic(client):
@pytest.mark.skip_t1
@pytest.mark.setup_client(
needs_backup=True, mnemonic=MNEMONIC_SLIP39_ADVANCED_20, random_seed=0
)
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC_SLIP39_ADVANCED_20)
def test_backup_slip39_advanced(client):
assert client.features.needs_backup is True
mnemonics = []

View File

@ -100,7 +100,7 @@ def _check_wipe_code(client, pin, wipe_code):
device.change_pin(client)
@pytest.mark.setup_client(pin=PIN4, random_seed=0)
@pytest.mark.setup_client(pin=PIN4)
def test_set_remove_wipe_code(client):
# Test set wipe code.
assert client.features.wipe_code_protection is False
@ -143,7 +143,7 @@ def test_set_remove_wipe_code(client):
assert client.features.wipe_code_protection is False
@pytest.mark.setup_client(random_seed=0)
@pytest.mark.setup_client()
def test_set_wipe_code_mismatch(client):
# Let's set a wipe code.
def input_flow():
@ -171,7 +171,7 @@ def test_set_wipe_code_mismatch(client):
assert client.features.wipe_code_protection is False
@pytest.mark.setup_client(pin=PIN4, random_seed=0)
@pytest.mark.setup_client(pin=PIN4)
def test_set_wipe_code_to_pin(client):
def input_flow():
yield # do you want to set the wipe code?
@ -202,7 +202,7 @@ def test_set_wipe_code_to_pin(client):
_check_wipe_code(client, PIN4, WIPE_CODE4)
@pytest.mark.setup_client(random_seed=0)
@pytest.mark.setup_client()
def test_set_pin_to_wipe_code(client):
# Set wipe code.
with client:
@ -223,7 +223,7 @@ def test_set_pin_to_wipe_code(client):
device.change_pin(client)
# TODO: this UI test should not be skipped, but when setting random_seed=0 it fails
# TODO: this UI test should not be skipped, but because of the reseed it fails
# on device id match and I am not sure why
@pytest.mark.setup_client(pin=PIN4)
@pytest.mark.skip_ui

View File

@ -96,7 +96,7 @@ def _check_no_pin(client):
assert client.features.pin_protection is False
@pytest.mark.setup_client(random_seed=0)
@pytest.mark.setup_client()
def test_set_pin(client):
assert client.features.pin_protection is False
@ -117,7 +117,7 @@ def test_set_pin(client):
_check_pin(client, PIN6)
@pytest.mark.setup_client(pin=PIN4, random_seed=0)
@pytest.mark.setup_client(pin=PIN4)
def test_change_pin(client):
assert client.features.pin_protection is True
@ -140,7 +140,7 @@ def test_change_pin(client):
_check_pin(client, PIN6)
@pytest.mark.setup_client(pin=PIN4, random_seed=0)
@pytest.mark.setup_client(pin=PIN4)
def test_remove_pin(client):
assert client.features.pin_protection is True
@ -162,7 +162,7 @@ def test_remove_pin(client):
_check_no_pin(client)
@pytest.mark.setup_client(random_seed=0)
@pytest.mark.setup_client()
def test_set_failed(client):
assert client.features.pin_protection is False
@ -196,7 +196,7 @@ def test_set_failed(client):
_check_no_pin(client)
@pytest.mark.setup_client(pin=PIN4, random_seed=0)
@pytest.mark.setup_client(pin=PIN4)
def test_change_failed(client):
assert client.features.pin_protection is True

View File

@ -23,7 +23,7 @@ from ..common import MNEMONIC12
@pytest.mark.skip_t1
class TestMsgRecoverydeviceT2:
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_pin_passphrase(self, client):
mnemonic = MNEMONIC12.split(" ")
ret = client.call_raw(

View File

@ -66,7 +66,7 @@ def test_secret(client, shares, secret):
assert debug.read_mnemonic_secret().hex() == secret
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_extra_share_entered(client):
debug = client.debug

View File

@ -70,7 +70,7 @@ def test_secret(client, shares, secret):
assert debug.read_mnemonic_secret().hex() == secret
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_recover_with_pin_passphrase(client):
debug = client.debug

View File

@ -35,7 +35,7 @@ EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2
@pytest.mark.skip_t1
class TestMsgResetDeviceT2:
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device(self, client):
mnemonic = None
strength = 128
@ -110,7 +110,7 @@ class TestMsgResetDeviceT2:
with pytest.raises(TrezorFailure, match="ProcessError: Seed already backed up"):
device.backup(client)
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_pin(self, client):
mnemonic = None
strength = 128
@ -207,7 +207,7 @@ class TestMsgResetDeviceT2:
assert resp.pin_protection is True
assert resp.passphrase_protection is True
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_failed_pin(self, client):
# external_entropy = b'zlutoucky kun upel divoke ody' * 2
strength = 128

View File

@ -31,7 +31,7 @@ EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2
@pytest.mark.skip_t1
class TestMsgResetDeviceT2:
# TODO: test with different options
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_slip39_advanced(self, client):
strength = 128
word_count = 20

View File

@ -36,7 +36,7 @@ from ..common import (
@pytest.mark.skip_t1
class TestMsgResetDeviceT2:
# TODO: test with different options
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_slip39_basic(self, client):
strength = 128
member_threshold = 3

View File

@ -178,7 +178,7 @@ VECTORS = [
@pytest.mark.skip_t1
@pytest.mark.parametrize("backup_type, backup_flow", VECTORS)
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_skip_backup_msg(client, backup_type, backup_flow):
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
@ -213,7 +213,7 @@ def test_skip_backup_msg(client, backup_type, backup_flow):
@pytest.mark.skip_t1
@pytest.mark.parametrize("backup_type, backup_flow", VECTORS)
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_skip_backup_manual(client, backup_type, backup_flow):
def reset_skip_input_flow():
yield # Confirm Recovery

View File

@ -28,7 +28,7 @@ from ..common import EXTERNAL_ENTROPY, click_through, read_and_confirm_mnemonic
@pytest.mark.skip_t1
@pytest.mark.skip_ui
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_reset_recovery(client):
mnemonic = reset(client)
address_before = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))

View File

@ -32,7 +32,7 @@ from ..common import (
@pytest.mark.skip_t1
@pytest.mark.skip_ui
@pytest.mark.setup_client(uninitialized=True, random_seed=0)
@pytest.mark.setup_client(uninitialized=True)
def test_reset_recovery(client):
mnemonics = reset(client)
address_before = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))

View File

@ -87,10 +87,6 @@ def _process_tested(fixture_test_path, test_name):
@contextmanager
def screen_recording(client, request):
test_ui = request.config.getoption("ui")
if request.node.get_closest_marker("skip_ui") or not test_ui:
yield
return
test_name = _get_test_dirname(request.node)
fixture_test_path = Path(__file__).parent.resolve() / "fixtures" / test_name