1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-09 06:50:58 +00:00

tests: refactor test_msg_resetdevice_skipbackup

This commit is contained in:
Pavol Rusnak 2018-10-11 17:26:20 +02:00
parent 16d9d58ee1
commit 3d5fa7a2f6
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -24,15 +24,16 @@ from .common import TrezorTest, generate_entropy
@pytest.mark.skip_t2 @pytest.mark.skip_t2
class TestMsgResetDeviceSkipbackup(TrezorTest): class TestMsgResetDeviceSkipbackup(TrezorTest):
def test_reset_device_skip_backup(self):
external_entropy = b"zlutoucky kun upel divoke ody" * 2 external_entropy = b"zlutoucky kun upel divoke ody" * 2
strength = 128 strength = 128
def test_reset_device_skip_backup(self):
ret = self.client.call_raw( ret = self.client.call_raw(
proto.ResetDevice( proto.ResetDevice(
display_random=False, display_random=False,
strength=strength, strength=self.strength,
passphrase_protection=False, passphrase_protection=False,
pin_protection=False, pin_protection=False,
language="english", language="english",
@ -44,7 +45,7 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
# Provide entropy # Provide entropy
assert isinstance(ret, proto.EntropyRequest) assert isinstance(ret, proto.EntropyRequest)
internal_entropy = self.client.debug.read_reset_entropy() internal_entropy = self.client.debug.read_reset_entropy()
ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy)) ret = self.client.call_raw(proto.EntropyAck(entropy=self.external_entropy))
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
# Check if device is properly initialized # Check if device is properly initialized
@ -55,14 +56,16 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
assert ret.no_backup is False assert ret.no_backup is False
# Generate mnemonic locally # Generate mnemonic locally
entropy = generate_entropy(strength, internal_entropy, external_entropy) entropy = generate_entropy(
self.strength, internal_entropy, self.external_entropy
)
expected_mnemonic = Mnemonic("english").to_mnemonic(entropy) expected_mnemonic = Mnemonic("english").to_mnemonic(entropy)
# start Backup workflow # start Backup workflow
ret = self.client.call_raw(proto.BackupDevice()) ret = self.client.call_raw(proto.BackupDevice())
mnemonic = [] mnemonic = []
for _ in range(strength // 32 * 3): for _ in range(self.strength // 32 * 3):
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_reset_word()) mnemonic.append(self.client.debug.read_reset_word())
self.client.debug.press_yes() self.client.debug.press_yes()
@ -74,7 +77,7 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
assert mnemonic == expected_mnemonic assert mnemonic == expected_mnemonic
mnemonic = [] mnemonic = []
for _ in range(strength // 32 * 3): for _ in range(self.strength // 32 * 3):
assert isinstance(ret, proto.ButtonRequest) assert isinstance(ret, proto.ButtonRequest)
mnemonic.append(self.client.debug.read_reset_word()) mnemonic.append(self.client.debug.read_reset_word())
self.client.debug.press_yes() self.client.debug.press_yes()
@ -93,13 +96,10 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
def test_reset_device_skip_backup_break(self): def test_reset_device_skip_backup_break(self):
external_entropy = b"zlutoucky kun upel divoke ody" * 2
strength = 128
ret = self.client.call_raw( ret = self.client.call_raw(
proto.ResetDevice( proto.ResetDevice(
display_random=False, display_random=False,
strength=strength, strength=self.strength,
passphrase_protection=False, passphrase_protection=False,
pin_protection=False, pin_protection=False,
language="english", language="english",
@ -110,7 +110,7 @@ class TestMsgResetDeviceSkipbackup(TrezorTest):
# Provide entropy # Provide entropy
assert isinstance(ret, proto.EntropyRequest) assert isinstance(ret, proto.EntropyRequest)
ret = self.client.call_raw(proto.EntropyAck(entropy=external_entropy)) ret = self.client.call_raw(proto.EntropyAck(entropy=self.external_entropy))
assert isinstance(ret, proto.Success) assert isinstance(ret, proto.Success)
# Check if device is properly initialized # Check if device is properly initialized