mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-21 03:52:04 +00:00
tests: only allow input_flow in a with-block
This commit is contained in:
parent
eca0a719db
commit
4eb98c254a
@ -237,6 +237,9 @@ class TrezorClientDebugLink(TrezorClient):
|
|||||||
self.ui.input_flow = None
|
self.ui.input_flow = None
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.in_with_statement:
|
||||||
|
raise RuntimeError("Must be called inside 'with' statement")
|
||||||
|
|
||||||
if callable(input_flow):
|
if callable(input_flow):
|
||||||
input_flow = input_flow()
|
input_flow = input_flow()
|
||||||
if not hasattr(input_flow, "send"):
|
if not hasattr(input_flow, "send"):
|
||||||
@ -252,6 +255,9 @@ class TrezorClientDebugLink(TrezorClient):
|
|||||||
def __exit__(self, _type, value, traceback):
|
def __exit__(self, _type, value, traceback):
|
||||||
self.in_with_statement -= 1
|
self.in_with_statement -= 1
|
||||||
|
|
||||||
|
# Clear input flow.
|
||||||
|
self.set_input_flow(None)
|
||||||
|
|
||||||
if _type is not None:
|
if _type is not None:
|
||||||
# Another exception raised
|
# Another exception raised
|
||||||
return False
|
return False
|
||||||
@ -268,6 +274,7 @@ class TrezorClientDebugLink(TrezorClient):
|
|||||||
# Cleanup
|
# Cleanup
|
||||||
self.expected_responses = None
|
self.expected_responses = None
|
||||||
self.current_response = None
|
self.current_response = None
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def set_expected_responses(self, expected):
|
def set_expected_responses(self, expected):
|
||||||
|
@ -194,6 +194,7 @@ class TestMsgTezosSignTx:
|
|||||||
debug.press_yes()
|
debug.press_yes()
|
||||||
|
|
||||||
def test_tezos_sign_tx_proposal(self, client):
|
def test_tezos_sign_tx_proposal(self, client):
|
||||||
|
with client:
|
||||||
client.set_input_flow(self.input_flow(client.debug, num_pages=1))
|
client.set_input_flow(self.input_flow(client.debug, num_pages=1))
|
||||||
resp = tezos.sign_tx(
|
resp = tezos.sign_tx(
|
||||||
client,
|
client,
|
||||||
@ -212,6 +213,7 @@ class TestMsgTezosSignTx:
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
resp.signature
|
resp.signature
|
||||||
== "edsigtfY16R32k2WVMYfFr7ymnro4ib5zMckk28vsuViYNN77DJAvCJLRNArd9L531pUCxT4YdcvCvBym5dhcZ1rknEVm6yZ8bB"
|
== "edsigtfY16R32k2WVMYfFr7ymnro4ib5zMckk28vsuViYNN77DJAvCJLRNArd9L531pUCxT4YdcvCvBym5dhcZ1rknEVm6yZ8bB"
|
||||||
@ -225,6 +227,7 @@ class TestMsgTezosSignTx:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_tezos_sign_tx_multiple_proposals(self, client):
|
def test_tezos_sign_tx_multiple_proposals(self, client):
|
||||||
|
with client:
|
||||||
client.set_input_flow(self.input_flow(client.debug, num_pages=2))
|
client.set_input_flow(self.input_flow(client.debug, num_pages=2))
|
||||||
resp = tezos.sign_tx(
|
resp = tezos.sign_tx(
|
||||||
client,
|
client,
|
||||||
@ -244,6 +247,7 @@ class TestMsgTezosSignTx:
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
resp.signature
|
resp.signature
|
||||||
== "edsigu6GAjhiWAQ64ctWTGEDYAZ16tYzLgzWzqc4CUyixK4FGRE8YUBVzFaVJ2fUCexZjZLMLdiNZGcUdzeL1bQhZ2h5oLrh7pA"
|
== "edsigu6GAjhiWAQ64ctWTGEDYAZ16tYzLgzWzqc4CUyixK4FGRE8YUBVzFaVJ2fUCexZjZLMLdiNZGcUdzeL1bQhZ2h5oLrh7pA"
|
||||||
|
@ -179,7 +179,6 @@ def reset(client, strength=128):
|
|||||||
language="english",
|
language="english",
|
||||||
backup_type=BackupType.Slip39_Advanced,
|
backup_type=BackupType.Slip39_Advanced,
|
||||||
)
|
)
|
||||||
client.set_input_flow(None)
|
|
||||||
|
|
||||||
# Check if device is properly initialized
|
# Check if device is properly initialized
|
||||||
assert client.features.initialized is True
|
assert client.features.initialized is True
|
||||||
@ -203,8 +202,6 @@ def recover(client, shares):
|
|||||||
client.set_input_flow(input_flow)
|
client.set_input_flow(input_flow)
|
||||||
ret = device.recover(client, pin_protection=False, label="label")
|
ret = device.recover(client, pin_protection=False, label="label")
|
||||||
|
|
||||||
client.set_input_flow(None)
|
|
||||||
|
|
||||||
# Workflow successfully ended
|
# Workflow successfully ended
|
||||||
assert ret == messages.Success(message="Device recovered")
|
assert ret == messages.Success(message="Device recovered")
|
||||||
assert client.features.pin_protection is False
|
assert client.features.pin_protection is False
|
||||||
|
@ -115,8 +115,6 @@ def reset(client, strength=128):
|
|||||||
backup_type=BackupType.Slip39_Basic,
|
backup_type=BackupType.Slip39_Basic,
|
||||||
)
|
)
|
||||||
|
|
||||||
client.set_input_flow(None)
|
|
||||||
|
|
||||||
# Check if device is properly initialized
|
# Check if device is properly initialized
|
||||||
assert client.features.initialized is True
|
assert client.features.initialized is True
|
||||||
assert client.features.needs_backup is False
|
assert client.features.needs_backup is False
|
||||||
@ -139,8 +137,6 @@ def recover(client, shares):
|
|||||||
client.set_input_flow(input_flow)
|
client.set_input_flow(input_flow)
|
||||||
ret = device.recover(client, pin_protection=False, label="label")
|
ret = device.recover(client, pin_protection=False, label="label")
|
||||||
|
|
||||||
client.set_input_flow(None)
|
|
||||||
|
|
||||||
# Workflow successfully ended
|
# Workflow successfully ended
|
||||||
assert ret == messages.Success(message="Device recovered")
|
assert ret == messages.Success(message="Device recovered")
|
||||||
assert client.features.pin_protection is False
|
assert client.features.pin_protection is False
|
||||||
|
Loading…
Reference in New Issue
Block a user