1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-25 17:09:44 +00:00

fix(tests): update prevhash test

exclude the None value, because prev_hash is now required on protobuf
level

unify the parametrization across tests
This commit is contained in:
matejcik 2021-09-15 14:56:57 +02:00 committed by Martin Milata
parent 795ed2d339
commit 9dd97c77e3
2 changed files with 9 additions and 13 deletions

View File

@ -61,22 +61,21 @@ def hash_tx(data: bytes) -> bytes:
def _check_error_message(value: bytes, model: str, message: str): def _check_error_message(value: bytes, model: str, message: str):
if model != "1": if model != "1":
if value is None: assert message == "Provided prev_hash is invalid."
assert message == "Failed to decode message: Missing"
else:
assert message == "Provided prev_hash is invalid."
return
# T1 has several possible errors # T1 has several possible errors
if value is None:
assert message.endswith("missing required field")
elif len(value) > 32: elif len(value) > 32:
assert message.endswith("bytes overflow") assert message.endswith("bytes overflow")
else: else:
assert message.endswith("Encountered invalid prevhash") assert message.endswith("Encountered invalid prevhash")
@pytest.mark.parametrize("prev_hash", (None, b"", b"x", b"hello world", b"x" * 33)) with_bad_prevhashes = pytest.mark.parametrize(
"prev_hash", (b"", b"x", b"hello world", b"x" * 33)
)
@with_bad_prevhashes
def test_invalid_prev_hash(client, prev_hash): def test_invalid_prev_hash(client, prev_hash):
inp1 = messages.TxInputType( inp1 = messages.TxInputType(
address_n=tools.parse_path("m/44h/0h/0h/0/0"), address_n=tools.parse_path("m/44h/0h/0h/0/0"),
@ -96,7 +95,7 @@ def test_invalid_prev_hash(client, prev_hash):
_check_error_message(prev_hash, client.features.model, e.value.message) _check_error_message(prev_hash, client.features.model, e.value.message)
@pytest.mark.parametrize("prev_hash", (None, b"", b"x", b"hello world", b"x" * 33)) @with_bad_prevhashes
def test_invalid_prev_hash_attack(client, prev_hash): def test_invalid_prev_hash_attack(client, prev_hash):
# prepare input with a valid prev-hash # prepare input with a valid prev-hash
inp1 = messages.TxInputType( inp1 = messages.TxInputType(
@ -138,7 +137,7 @@ def test_invalid_prev_hash_attack(client, prev_hash):
_check_error_message(prev_hash, client.features.model, e.value.message) _check_error_message(prev_hash, client.features.model, e.value.message)
@pytest.mark.parametrize("prev_hash", (None, b"", b"x", b"hello world", b"x" * 33)) @with_bad_prevhashes
def test_invalid_prev_hash_in_prevtx(client, prev_hash): def test_invalid_prev_hash_in_prevtx(client, prev_hash):
cache = TxCache("Bitcoin") cache = TxCache("Bitcoin")
prev_tx = cache[TXHASH_157041] prev_tx = cache[TXHASH_157041]

View File

@ -554,17 +554,14 @@
"test_msg_signtx_peercoin.py::test_timestamp_included": "0e76606dba98b8389ef587f48c2ce65b66457d9b206eaecdda56a4e115e0c829", "test_msg_signtx_peercoin.py::test_timestamp_included": "0e76606dba98b8389ef587f48c2ce65b66457d9b206eaecdda56a4e115e0c829",
"test_msg_signtx_peercoin.py::test_timestamp_missing": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", "test_msg_signtx_peercoin.py::test_timestamp_missing": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1",
"test_msg_signtx_peercoin.py::test_timestamp_missing_prevtx": "fe6ecad8988b5c789419b9134317bbf018007c5005047dd9cba7b9655e56349c", "test_msg_signtx_peercoin.py::test_timestamp_missing_prevtx": "fe6ecad8988b5c789419b9134317bbf018007c5005047dd9cba7b9655e56349c",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash[None]": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash[]": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738", "test_msg_signtx_prevhash.py::test_invalid_prev_hash[]": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash[hello world]": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738", "test_msg_signtx_prevhash.py::test_invalid_prev_hash[hello world]": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash[x]": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738", "test_msg_signtx_prevhash.py::test_invalid_prev_hash[x]": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738", "test_msg_signtx_prevhash.py::test_invalid_prev_hash[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash_attack[None]": "91fa0c1fdb411c207cc5e7bca8fed5ee82e98b4b1fc092e576ad225a0f74724f",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash_attack[]": "91fa0c1fdb411c207cc5e7bca8fed5ee82e98b4b1fc092e576ad225a0f74724f", "test_msg_signtx_prevhash.py::test_invalid_prev_hash_attack[]": "91fa0c1fdb411c207cc5e7bca8fed5ee82e98b4b1fc092e576ad225a0f74724f",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash_attack[hello world]": "91fa0c1fdb411c207cc5e7bca8fed5ee82e98b4b1fc092e576ad225a0f74724f", "test_msg_signtx_prevhash.py::test_invalid_prev_hash_attack[hello world]": "91fa0c1fdb411c207cc5e7bca8fed5ee82e98b4b1fc092e576ad225a0f74724f",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash_attack[x]": "91fa0c1fdb411c207cc5e7bca8fed5ee82e98b4b1fc092e576ad225a0f74724f", "test_msg_signtx_prevhash.py::test_invalid_prev_hash_attack[x]": "91fa0c1fdb411c207cc5e7bca8fed5ee82e98b4b1fc092e576ad225a0f74724f",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash_attack[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]": "91fa0c1fdb411c207cc5e7bca8fed5ee82e98b4b1fc092e576ad225a0f74724f", "test_msg_signtx_prevhash.py::test_invalid_prev_hash_attack[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]": "91fa0c1fdb411c207cc5e7bca8fed5ee82e98b4b1fc092e576ad225a0f74724f",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash_in_prevtx[None]": "612cad5b3bb70a8aed99345fe2ce3058cd1a153521c0b8b8bf9f8d7c0b2c76a2",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash_in_prevtx[]": "612cad5b3bb70a8aed99345fe2ce3058cd1a153521c0b8b8bf9f8d7c0b2c76a2", "test_msg_signtx_prevhash.py::test_invalid_prev_hash_in_prevtx[]": "612cad5b3bb70a8aed99345fe2ce3058cd1a153521c0b8b8bf9f8d7c0b2c76a2",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash_in_prevtx[hello world]": "612cad5b3bb70a8aed99345fe2ce3058cd1a153521c0b8b8bf9f8d7c0b2c76a2", "test_msg_signtx_prevhash.py::test_invalid_prev_hash_in_prevtx[hello world]": "612cad5b3bb70a8aed99345fe2ce3058cd1a153521c0b8b8bf9f8d7c0b2c76a2",
"test_msg_signtx_prevhash.py::test_invalid_prev_hash_in_prevtx[x]": "612cad5b3bb70a8aed99345fe2ce3058cd1a153521c0b8b8bf9f8d7c0b2c76a2", "test_msg_signtx_prevhash.py::test_invalid_prev_hash_in_prevtx[x]": "612cad5b3bb70a8aed99345fe2ce3058cd1a153521c0b8b8bf9f8d7c0b2c76a2",