From 7739825cc6f14dba7302136d0b6677940922b7cf Mon Sep 17 00:00:00 2001 From: Tomas Krnak Date: Thu, 31 Mar 2022 15:36:59 +0200 Subject: [PATCH] test: add device tests for Zcash v5 --- tests/device_tests/zcash/__init__.py | 0 tests/device_tests/zcash/test_sign_tx.py | 258 +++++++++++++++++++++++ tests/ui_tests/fixtures.json | 5 + 3 files changed, 263 insertions(+) create mode 100644 tests/device_tests/zcash/__init__.py create mode 100644 tests/device_tests/zcash/test_sign_tx.py diff --git a/tests/device_tests/zcash/__init__.py b/tests/device_tests/zcash/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/device_tests/zcash/test_sign_tx.py b/tests/device_tests/zcash/test_sign_tx.py new file mode 100644 index 000000000..7d5e1cff4 --- /dev/null +++ b/tests/device_tests/zcash/test_sign_tx.py @@ -0,0 +1,258 @@ +# This file is part of the Trezor project. +# +# Copyright (C) 2012-2019 SatoshiLabs and contributors +# +# This library is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the License along with this library. +# If not, see . + +import pytest + +from trezorlib import btc, messages +from trezorlib.exceptions import TrezorFailure +from trezorlib.tools import parse_path + +from ..bitcoin.signtx import request_finished, request_input, request_output + +B = messages.ButtonRequestType + +TXHASH_aaf51e = bytes.fromhex( + "aaf51e4606c264e47e5c42c958fe4cf1539c5172684721e38e69f4ef634d75dc" +) +TXHASH_e38206 = bytes.fromhex( + "e3820602226974b1dd87b7113cc8aea8c63e5ae29293991e7bfa80c126930368" +) + +pytestmark = [pytest.mark.altcoin, pytest.mark.zcash, pytest.mark.skip_t1] + + +def test_version_group_id_missing(client): + inp1 = messages.TxInputType( + # tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu + address_n=parse_path("m/44h/1h/0h/0/0"), + amount=300000000, + prev_hash=TXHASH_e38206, + prev_index=0, + ) + out1 = messages.TxOutputType( + address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z", + amount=300000000 - 1940, + script_type=messages.OutputScriptType.PAYTOADDRESS, + ) + + with pytest.raises(TrezorFailure, match="Version group ID must be set."): + btc.sign_tx( + client, + "Zcash Testnet", + [inp1], + [out1], + version=5, + ) + + +def test_one_one(client): + inp1 = messages.TxInputType( + # tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu + address_n=parse_path("m/44h/1h/0h/0/0"), + amount=300000000, + prev_hash=TXHASH_e38206, + prev_index=0, + ) + + out1 = messages.TxOutputType( + address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z", + amount=300000000 - 1940, + script_type=messages.OutputScriptType.PAYTOADDRESS, + ) + + with client: + client.set_expected_responses( + [ + request_input(0), + request_output(0), + messages.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.SignTx), + request_input(0), + request_output(0), + request_finished(), + ] + ) + + btc.sign_tx( + client, + "Zcash Testnet", + [inp1], + [out1], + version=5, + version_group_id=0x892F2085, + branch_id=0x76B809BB, + ) + + # TODO: send tx to testnet + # TODO: check serialized_tx + + +def test_one_two(client): + inp1 = messages.TxInputType( + # tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu + address_n=parse_path("m/44h/1h/0h/0/0"), + amount=300000000, + prev_hash=TXHASH_e38206, + prev_index=0, + ) + + out1 = messages.TxOutputType( + address="tmNvfeKR5PkcQazLEqddTskFr6Ev9tsovfQ", + amount=100000000, + script_type=messages.OutputScriptType.PAYTOADDRESS, + ) + + out2 = messages.TxOutputType( + address_n=parse_path("m/44h/1h/0h/0/0"), + amount=200000000 - 2000, + script_type=messages.OutputScriptType.PAYTOADDRESS, + ) + + with client: + client.set_expected_responses( + [ + request_input(0), + request_output(0), + messages.ButtonRequest(code=B.ConfirmOutput), + request_output(1), + messages.ButtonRequest(code=B.SignTx), + request_input(0), + request_output(0), + request_output(1), + request_finished(), + ] + ) + + btc.sign_tx( + client, + "Zcash Testnet", + [inp1], + [out1, out2], + version=5, + version_group_id=0x892F2085, + branch_id=0x76B809BB, + ) + + # TODO: send tx to testnet + # TODO: check serialized_tx + + +def test_external_presigned(client): + inp1 = messages.TxInputType( + # tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu + address_n=parse_path("m/44h/1h/0h/0/0"), + amount=300000000, + prev_hash=TXHASH_e38206, + prev_index=0, + ) + + inp2 = messages.TxInputType( + # tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu + # address_n=parse_path("m/44h/1h/0h/0/0"), + amount=300000000, + prev_hash=TXHASH_aaf51e, + prev_index=1, + script_type=messages.InputScriptType.EXTERNAL, + script_pubkey=bytes.fromhex( + "76a914a579388225827d9f2fe9014add644487808c695d88ac" + ), + script_sig=bytes.fromhex( + "48304502210090020ba5d1c945145f04e940c4b6026a24d2b9e58e7ae53834eca6f606e457e4022040d214cb7ad2bd2cff14bac8d7b8eab0bb603c239a962ecd8535ea49ca25071e0121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0" + ), + ) + + out1 = messages.TxOutputType( + address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z", + amount=300000000 + 300000000 - 1940, + script_type=messages.OutputScriptType.PAYTOADDRESS, + ) + + with client: + client.set_expected_responses( + [ + request_input(0), + request_input(1), + request_output(0), + messages.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.SignTx), + request_input(1), + request_input(0), + request_input(1), + request_output(0), + request_finished(), + ] + ) + + btc.sign_tx( + client, + "Zcash Testnet", + [inp1, inp2], + [out1], + version=5, + version_group_id=0x892F2085, + branch_id=0x76B809BB, + ) + + # TODO: send tx to testnet + # TODO: check serialized + + +def test_refuse_replacement_tx(client): + inp1 = messages.TxInputType( + address_n=parse_path("m/44h/1h/0h/0/4"), + amount=174998, + prev_hash=bytes.fromhex( + "beafc7cbd873d06dbee88a7002768ad5864228639db514c81cfb29f108bb1e7a" + ), + prev_index=0, + orig_hash=bytes.fromhex( + "50f6f1209ca92d7359564be803cb2c932cde7d370f7cee50fd1fad6790f6206d" + ), + orig_index=0, + ) + + out1 = messages.TxOutputType( + address_n=parse_path("m/44h/1h/0h/1/2"), + amount=174998 - 50000 - 1111, + script_type=messages.OutputScriptType.PAYTOADDRESS, + orig_hash=bytes.fromhex( + "50f6f1209ca92d7359564be803cb2c932cde7d370f7cee50fd1fad6790f6206d" + ), + orig_index=0, + ) + + out2 = messages.TxOutputType( + address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z", + amount=50000, + script_type=messages.OutputScriptType.PAYTOADDRESS, + orig_hash=bytes.fromhex( + "50f6f1209ca92d7359564be803cb2c932cde7d370f7cee50fd1fad6790f6206d" + ), + orig_index=1, + ) + + with pytest.raises( + TrezorFailure, match="Replacement transactions are not supported." + ): + btc.sign_tx( + client, + "Zcash Testnet", + [inp1], + [out1, out2], + version=5, + version_group_id=0x892F2085, + branch_id=0x76B809BB, + ) diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index 3f289bb7c..c4cf8e780 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -1601,6 +1601,11 @@ "TT_tezos-test_sign_tx.py::test_tezos_smart_contract_transfer_to_contract": "cadca03c9ce7db592663bc0224364c0d4bf99fcae60e0982b4a844ce629e500c", "TT_webauthn-test_msg_webauthn.py::test_add_remove": "3219e5ad2719319e74b5c75b1096ca7e3d30467215c15f57e57e475afdaa188f", "TT_webauthn-test_u2f_counter.py::test_u2f_counter": "19f77e2d284431da5fadac938f5822c1a6b17c07ee6c801085efd84974f3163f", +"TT_zcash-test_sign_tx.py::test_external_presigned": "08a22a49793201f8387a085a554f006387d1df1b37ed8a34bef7aa79b363b44b", +"TT_zcash-test_sign_tx.py::test_one_one": "b8aff4ae3c9b417acadf1ede52d7d45870dd4ef1f9251bf8e8f2ebf5280b9f3b", +"TT_zcash-test_sign_tx.py::test_one_two": "d59aa3d5d03a276a31d3023c8214af940dbb8dec3cd686576608881965789fcb", +"TT_zcash-test_sign_tx.py::test_refuse_replacement_tx": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738", +"TT_zcash-test_sign_tx.py::test_version_group_id_missing": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", "TTui2_binance-test_get_address.py::test_binance_get_address[m-44h-714h-0h-0-0-bnb1hgm0p7khfk85zpz-68e2cb5a": "f03b50df7f4a161078fa903c44f37272961b70358d4014d30a12888e1fd2caf1", "TTui2_binance-test_get_address.py::test_binance_get_address[m-44h-714h-0h-0-1-bnb1egswqkszzfc2uq7-1adfb691": "f03b50df7f4a161078fa903c44f37272961b70358d4014d30a12888e1fd2caf1", "TTui2_binance-test_get_public_key.py::test_binance_get_public_key": "f03b50df7f4a161078fa903c44f37272961b70358d4014d30a12888e1fd2caf1",