From 9dd97c77e369cfae9b079eedc821cdc0dd8331db Mon Sep 17 00:00:00 2001 From: matejcik Date: Wed, 15 Sep 2021 14:56:57 +0200 Subject: [PATCH] fix(tests): update prevhash test exclude the None value, because prev_hash is now required on protobuf level unify the parametrization across tests --- .../device_tests/test_msg_signtx_prevhash.py | 19 +++++++++---------- tests/ui_tests/fixtures.json | 3 --- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/device_tests/test_msg_signtx_prevhash.py b/tests/device_tests/test_msg_signtx_prevhash.py index 1da397c2c4..b0aeaa6884 100644 --- a/tests/device_tests/test_msg_signtx_prevhash.py +++ b/tests/device_tests/test_msg_signtx_prevhash.py @@ -61,22 +61,21 @@ def hash_tx(data: bytes) -> bytes: def _check_error_message(value: bytes, model: str, message: str): if model != "1": - if value is None: - assert message == "Failed to decode message: Missing" - else: - assert message == "Provided prev_hash is invalid." - return + assert message == "Provided prev_hash is invalid." # T1 has several possible errors - if value is None: - assert message.endswith("missing required field") elif len(value) > 32: assert message.endswith("bytes overflow") else: 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): inp1 = messages.TxInputType( 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) -@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): # prepare input with a valid prev-hash 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) -@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): cache = TxCache("Bitcoin") prev_tx = cache[TXHASH_157041] diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index 891afdce74..df91123272 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -554,17 +554,14 @@ "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_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[hello world]": "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_attack[None]": "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[x]": "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[hello world]": "612cad5b3bb70a8aed99345fe2ce3058cd1a153521c0b8b8bf9f8d7c0b2c76a2", "test_msg_signtx_prevhash.py::test_invalid_prev_hash_in_prevtx[x]": "612cad5b3bb70a8aed99345fe2ce3058cd1a153521c0b8b8bf9f8d7c0b2c76a2",