mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-11 07:50:57 +00:00
fix(tests): set_filter must be used in with-block
This makes sure filters are properly cleared when the with-block exits
This commit is contained in:
parent
45d377f5b8
commit
b3312d1ef7
@ -407,6 +407,9 @@ class TrezorClientDebugLink(TrezorClient):
|
||||
|
||||
Useful for test scenarios with an active malicious actor on the wire.
|
||||
"""
|
||||
if not self.in_with_statement:
|
||||
raise RuntimeError("Must be called inside 'with' statement")
|
||||
|
||||
self.filters[message_type] = callback
|
||||
|
||||
def _filter_message(self, msg):
|
||||
@ -477,6 +480,7 @@ class TrezorClientDebugLink(TrezorClient):
|
||||
|
||||
self.in_with_statement -= 1
|
||||
self.ui.clear()
|
||||
self.filters.clear()
|
||||
self.watch_layout(False)
|
||||
|
||||
if _type is not None:
|
||||
|
@ -826,12 +826,12 @@ class TestMsgSigntx:
|
||||
|
||||
return msg
|
||||
|
||||
with client, pytest.raises(
|
||||
TrezorFailure, match="Transaction has changed during signing"
|
||||
):
|
||||
# Set up attack processors
|
||||
client.set_filter(messages.TxAck, attack_processor)
|
||||
|
||||
with pytest.raises(
|
||||
TrezorFailure, match="Transaction has changed during signing"
|
||||
):
|
||||
btc.sign_tx(
|
||||
client,
|
||||
"Bitcoin",
|
||||
@ -879,12 +879,12 @@ class TestMsgSigntx:
|
||||
|
||||
return msg
|
||||
|
||||
with client, pytest.raises(
|
||||
TrezorFailure, match="Transaction has changed during signing"
|
||||
):
|
||||
# Set up attack processors
|
||||
client.set_filter(messages.TxAck, attack_processor)
|
||||
|
||||
with pytest.raises(
|
||||
TrezorFailure, match="Transaction has changed during signing"
|
||||
):
|
||||
btc.sign_tx(
|
||||
client, "Testnet", [inp1], [out1, out2], prev_txes=TX_CACHE_TESTNET
|
||||
)
|
||||
@ -933,9 +933,9 @@ class TestMsgSigntx:
|
||||
|
||||
return msg
|
||||
|
||||
client.set_filter(messages.TxAck, attack_processor)
|
||||
# Now run the attack, must trigger the exception
|
||||
with client:
|
||||
client.set_filter(messages.TxAck, attack_processor)
|
||||
client.set_expected_responses(
|
||||
[
|
||||
request_input(0),
|
||||
|
@ -230,9 +230,8 @@ class TestMsgSigntxBch:
|
||||
|
||||
return msg
|
||||
|
||||
client.set_filter(proto.TxAck, attack_processor)
|
||||
|
||||
with client:
|
||||
client.set_filter(proto.TxAck, attack_processor)
|
||||
client.set_expected_responses(
|
||||
[
|
||||
request_input(0),
|
||||
|
@ -172,8 +172,8 @@ class TestMsgSigntxBitcoinGold:
|
||||
|
||||
return msg
|
||||
|
||||
client.set_filter(proto.TxAck, attack_processor)
|
||||
with client:
|
||||
client.set_filter(proto.TxAck, attack_processor)
|
||||
client.set_expected_responses(
|
||||
[
|
||||
request_input(0),
|
||||
|
@ -319,8 +319,8 @@ class TestMsgSigntxSegwit:
|
||||
return msg
|
||||
|
||||
# Now run the attack, must trigger the exception
|
||||
client.set_filter(proto.TxAck, attack_processor)
|
||||
with client:
|
||||
client.set_filter(proto.TxAck, attack_processor)
|
||||
client.set_expected_responses(
|
||||
[
|
||||
request_input(0),
|
||||
|
@ -294,8 +294,8 @@ class TestMultisig:
|
||||
attack_count -= 1
|
||||
return msg
|
||||
|
||||
client.set_filter(proto.TxAck, attack_processor)
|
||||
with client:
|
||||
client.set_filter(proto.TxAck, attack_processor)
|
||||
client.set_expected_responses(
|
||||
[
|
||||
request_input(0),
|
||||
|
Loading…
Reference in New Issue
Block a user