mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-04-12 21:36:18 +00:00
test(device): Test safety checks on T1.
This commit is contained in:
parent
2dbde040c4
commit
7f2f32ff8a
@ -165,11 +165,10 @@ class TestMsgApplysettings:
|
||||
_set_expected_responses(client)
|
||||
device.apply_settings(client, homescreen=img)
|
||||
|
||||
@pytest.mark.skip_t1
|
||||
@pytest.mark.setup_client(pin=None)
|
||||
def test_safety_checks(self, client):
|
||||
def get_bad_address():
|
||||
btc.get_address(client, "Bitcoin", parse_path("m/0"))
|
||||
btc.get_address(client, "Bitcoin", parse_path("m/44'"), show_display=True)
|
||||
|
||||
assert client.features.safety_checks == messages.SafetyCheckLevel.Strict
|
||||
|
||||
@ -179,17 +178,22 @@ class TestMsgApplysettings:
|
||||
client.set_expected_responses([messages.Failure])
|
||||
get_bad_address()
|
||||
|
||||
with client:
|
||||
client.set_expected_responses(EXPECTED_RESPONSES_NOPIN)
|
||||
device.apply_settings(
|
||||
client, safety_checks=messages.SafetyCheckLevel.PromptAlways
|
||||
if client.features.model != "1":
|
||||
with client:
|
||||
client.set_expected_responses(EXPECTED_RESPONSES_NOPIN)
|
||||
device.apply_settings(
|
||||
client, safety_checks=messages.SafetyCheckLevel.PromptAlways
|
||||
)
|
||||
|
||||
assert (
|
||||
client.features.safety_checks == messages.SafetyCheckLevel.PromptAlways
|
||||
)
|
||||
|
||||
assert client.features.safety_checks == messages.SafetyCheckLevel.PromptAlways
|
||||
|
||||
with client:
|
||||
client.set_expected_responses([messages.Address])
|
||||
get_bad_address()
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[messages.ButtonRequest, messages.ButtonRequest, messages.Address]
|
||||
)
|
||||
get_bad_address()
|
||||
|
||||
with client:
|
||||
client.set_expected_responses(EXPECTED_RESPONSES_NOPIN)
|
||||
@ -216,7 +220,9 @@ class TestMsgApplysettings:
|
||||
)
|
||||
|
||||
with client:
|
||||
client.set_expected_responses([messages.Address])
|
||||
client.set_expected_responses(
|
||||
[messages.ButtonRequest, messages.ButtonRequest, messages.Address]
|
||||
)
|
||||
get_bad_address()
|
||||
|
||||
@pytest.mark.skip_t1
|
||||
|
@ -229,19 +229,22 @@ class TestMsgGetaddress:
|
||||
assert address1 == address2
|
||||
|
||||
|
||||
@pytest.mark.skip_t1
|
||||
def test_invalid_path(client):
|
||||
with pytest.raises(TrezorFailure, match="Forbidden key path"):
|
||||
# slip44 id mismatch
|
||||
btc.get_address(client, "Bitcoin", parse_path("m/44'/111'/0'/0/0"))
|
||||
btc.get_address(
|
||||
client, "Bitcoin", parse_path("m/44'/111'/0'/0/0"), show_display=True
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skip_t1
|
||||
def test_unknown_path_tt(client):
|
||||
def test_unknown_path(client):
|
||||
UNKNOWN_PATH = parse_path("m/44'/9'/0'/0/0")
|
||||
with pytest.raises(TrezorFailure, match="Forbidden key path"):
|
||||
# account number is too high
|
||||
btc.get_address(client, "Bitcoin", UNKNOWN_PATH)
|
||||
with client:
|
||||
client.set_expected_responses([messages.Failure])
|
||||
|
||||
with pytest.raises(TrezorFailure, match="Forbidden key path"):
|
||||
# account number is too high
|
||||
btc.get_address(client, "Bitcoin", UNKNOWN_PATH, show_display=True)
|
||||
|
||||
# disable safety checks
|
||||
device.apply_settings(client, safety_checks=SafetyCheckLevel.PromptTemporarily)
|
||||
@ -265,26 +268,6 @@ def test_unknown_path_tt(client):
|
||||
btc.get_address(client, "Bitcoin", UNKNOWN_PATH, show_display=False)
|
||||
|
||||
|
||||
@pytest.mark.skip_t2
|
||||
def test_unknown_path_t1(client):
|
||||
UNKNOWN_PATH = parse_path("m/44'/9'/0'/0/0")
|
||||
with client:
|
||||
client.set_expected_responses(
|
||||
[
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.Other),
|
||||
messages.ButtonRequest(code=messages.ButtonRequestType.Address),
|
||||
messages.Address,
|
||||
]
|
||||
)
|
||||
# warning is shown when showing address
|
||||
btc.get_address(client, "Bitcoin", UNKNOWN_PATH, show_display=True)
|
||||
|
||||
with client:
|
||||
# no warning is displayed when the call is silent
|
||||
client.set_expected_responses([messages.Address])
|
||||
btc.get_address(client, "Bitcoin", UNKNOWN_PATH, show_display=False)
|
||||
|
||||
|
||||
@pytest.mark.altcoin
|
||||
def test_crw(client):
|
||||
assert (
|
||||
|
@ -27,34 +27,34 @@ class TestMsgGetaddressSegwitNative:
|
||||
btc.get_address(
|
||||
client,
|
||||
"Testnet",
|
||||
parse_path("49'/1'/0'/0/0"),
|
||||
parse_path("84'/1'/0'/0/0"),
|
||||
True,
|
||||
None,
|
||||
script_type=proto.InputScriptType.SPENDWITNESS,
|
||||
)
|
||||
== "tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s"
|
||||
== "tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9"
|
||||
)
|
||||
assert (
|
||||
btc.get_address(
|
||||
client,
|
||||
"Testnet",
|
||||
parse_path("49'/1'/0'/1/0"),
|
||||
parse_path("84'/1'/0'/1/0"),
|
||||
False,
|
||||
None,
|
||||
script_type=proto.InputScriptType.SPENDWITNESS,
|
||||
)
|
||||
== "tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu"
|
||||
== "tb1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt96jk9x"
|
||||
)
|
||||
assert (
|
||||
btc.get_address(
|
||||
client,
|
||||
"Testnet",
|
||||
parse_path("44'/1'/0'/0/0"),
|
||||
parse_path("84'/1'/0'/0/0"),
|
||||
False,
|
||||
None,
|
||||
script_type=proto.InputScriptType.SPENDWITNESS,
|
||||
)
|
||||
== "tb1q54un3q39sf7e7tlfq99d6ezys7qgc62a6rxllc"
|
||||
== "tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9"
|
||||
)
|
||||
assert (
|
||||
btc.get_address(
|
||||
|
@ -74,6 +74,7 @@ def test_show_multisig_3(client):
|
||||
tools.parse_path(f"45h/0/0/{i}"),
|
||||
show_display=True,
|
||||
multisig=multisig,
|
||||
script_type=messages.InputScriptType.SPENDMULTISIG,
|
||||
)
|
||||
== "35Q3tgZZfr9GhVpaqz7fbDK8WXV1V1KxfD"
|
||||
)
|
||||
@ -247,6 +248,7 @@ def test_show_multisig_15(client):
|
||||
tools.parse_path(f"45h/0/0/{i}"),
|
||||
show_display=True,
|
||||
multisig=multisig,
|
||||
script_type=messages.InputScriptType.SPENDMULTISIG,
|
||||
)
|
||||
== "3GG78bp1hA3mu9xv1vZLXiENmeabmi7WKQ"
|
||||
)
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from trezorlib import btc, messages as proto
|
||||
from trezorlib import btc, device, messages as proto
|
||||
from trezorlib.exceptions import TrezorFailure
|
||||
from trezorlib.tools import parse_path
|
||||
|
||||
@ -68,6 +68,35 @@ class TestMsgSigntxInvalidPath:
|
||||
assert exc.value.code == proto.FailureType.DataError
|
||||
assert exc.value.message.endswith("Forbidden key path")
|
||||
|
||||
# Adapted from TestMsgSigntx.test_one_one_fee,
|
||||
# only changed the coin from Bitcoin to Litecoin and set safety checks to prompt.
|
||||
# Litecoin does not have strong replay protection using SIGHASH_FORKID, but
|
||||
# spending from Bitcoin path should pass with safety checks set to prompt.
|
||||
@pytest.mark.altcoin
|
||||
def test_invalid_path_prompt(self, client):
|
||||
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
|
||||
# input 0: 0.0039 BTC
|
||||
|
||||
inp1 = proto.TxInputType(
|
||||
address_n=parse_path("44h/0h/0h/0/0"),
|
||||
amount=390000,
|
||||
prev_hash=TXHASH_d5f65e,
|
||||
prev_index=0,
|
||||
)
|
||||
|
||||
# address is converted from 1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1 by changing the version
|
||||
out1 = proto.TxOutputType(
|
||||
address="LfWz9wLHmqU9HoDkMg9NqbRosrHvEixeVZ",
|
||||
amount=390000 - 10000,
|
||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||
)
|
||||
|
||||
device.apply_settings(
|
||||
client, safety_checks=proto.SafetyCheckLevel.PromptTemporarily
|
||||
)
|
||||
|
||||
btc.sign_tx(client, "Litecoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET)
|
||||
|
||||
# Adapted from TestMsgSigntx.test_one_one_fee,
|
||||
# only changed the coin from Bitcoin to Bcash.
|
||||
# Bcash does have strong replay protection using SIGHASH_FORKID,
|
||||
|
@ -114,7 +114,7 @@
|
||||
"test_msg_applysettings.py-test_apply_settings_rotation": "b4983c819399cc837b3634e1de7638b6c31c72354fe097ebd0abeebb5cadbea9",
|
||||
"test_msg_applysettings.py-test_experimental_features": "7b5274ab956e173f9b02855b2e733a2aba5485fa8bcc87496e5f901f664163df",
|
||||
"test_msg_applysettings.py-test_label_too_long": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586",
|
||||
"test_msg_applysettings.py-test_safety_checks": "4d37de3654678b7f16643cf4ef912a0bced545e0e0526e41ea0c9b820560344e",
|
||||
"test_msg_applysettings.py-test_safety_checks": "7f39e9eb709e813472a0ca1c91cd32cb2036e79a34c0df55488a2c190db03996",
|
||||
"test_msg_authorize_coinjoin.py::test_cancel_authorization": "d8a608beb6165f5667cc44dcff6bdc17ebb4638ddd3bd09e7f0e1e75d1e21135",
|
||||
"test_msg_authorize_coinjoin.py::test_multisession_authorization": "dbcc5c1b3deb9953d215a39d31363ab9e4e9efe87579dbdc348bb2cb1d5aeb77",
|
||||
"test_msg_authorize_coinjoin.py::test_no_anonymity": "fd09da284b650e893990b95047b63a35b6b695fc5301d595f17a6d2cf9d90bcb",
|
||||
@ -212,7 +212,7 @@
|
||||
"test_msg_getaddress.py-test_tbtc": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586",
|
||||
"test_msg_getaddress.py::test_crw": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586",
|
||||
"test_msg_getaddress.py::test_invalid_path": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586",
|
||||
"test_msg_getaddress.py::test_unknown_path_tt": "0f6e15d265d012a341811965b72e75fbe0e76a17091f0bb2e89caa4a75c550a0",
|
||||
"test_msg_getaddress.py::test_unknown_path": "0f6e15d265d012a341811965b72e75fbe0e76a17091f0bb2e89caa4a75c550a0",
|
||||
"test_msg_getaddress_segwit.py-test_multisig_missing[False]": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586",
|
||||
"test_msg_getaddress_segwit.py-test_multisig_missing[True]": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586",
|
||||
"test_msg_getaddress_segwit.py-test_show_multisig_3": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586",
|
||||
@ -221,7 +221,7 @@
|
||||
"test_msg_getaddress_segwit_native.py-test_multisig_missing[False]": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586",
|
||||
"test_msg_getaddress_segwit_native.py-test_multisig_missing[True]": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586",
|
||||
"test_msg_getaddress_segwit_native.py-test_show_multisig_3": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586",
|
||||
"test_msg_getaddress_segwit_native.py-test_show_segwit": "e6b8007c78b6d375635ff5a1b3047bfe57727b9a449a3c19d2ebf64648ac3946",
|
||||
"test_msg_getaddress_segwit_native.py-test_show_segwit": "f244e9af9be9c3b8d7c5b3de68fab52496758a00f453ca07bc20856e77d8ba48",
|
||||
"test_msg_getaddress_segwit_native.py-test_show_segwit_altcoin": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586",
|
||||
"test_msg_getaddress_show.py::test_show[m-44h-0h-12h-0-0-0-1FM6Kz3oT3GoGv65jNpU8AFFun8nHAXrPk]": "098da5c20c502a8cb755cf81a82bf914ab941254f1e3d003567ac598a53384bf",
|
||||
"test_msg_getaddress_show.py::test_show[m-49h-0h-12h-0-0-4-3HfEUkuwmtZ87XzowkiD5nMp5Q3hqKXZ2i]": "062e352dfa3e1944a7e293c1ae23fbce6f0923fe9168dfcc67c101a51db37a47",
|
||||
@ -485,6 +485,7 @@
|
||||
"test_msg_signtx_grs.py-test_send_segwit_p2sh_change": "6c352ab975a75a150f7c3415a967fb8635395ff8db0de89ecb9c2011cb519509",
|
||||
"test_msg_signtx_invalid_path.py-test_invalid_path_fail": "b0f22cba2dbab2cd21c15c002b66ed89b6c728b10daa8d0c0e78abd4164a3912",
|
||||
"test_msg_signtx_invalid_path.py-test_invalid_path_pass_forkid": "667dcb09b569e5b4e091e6b1ac7e8e057c0c730c931b22f8c0ee64050f3f467b",
|
||||
"test_msg_signtx_invalid_path.py-test_invalid_path_prompt": "e0fd27e38bd6d1b15a4fcf5b675de596e2b1216cf538ed0ba710c66e7dcc174d",
|
||||
"test_msg_signtx_komodo.py-test_one_one_fee_sapling": "5643a961909bbac2ff7cc7df9766836957ba78b2bf35ba101f2ef7df18445cfe",
|
||||
"test_msg_signtx_komodo.py-test_one_one_rewards_claim": "0cd0d0609522ace94f970ded00f7aebfe0503d2894d516aa9d674b9573779d2d",
|
||||
"test_msg_signtx_mixed_inputs.py::test_non_segwit_segwit_inputs": "d72acb396bbc3109054919bddc823e8900bb30b6c41c553922beb449af9bb51d",
|
||||
|
Loading…
Reference in New Issue
Block a user