1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-30 03:18:20 +00:00
trezor-firmware/tests/device_tests/test_msg_signtx_zcash.py

166 lines
6.6 KiB
Python
Raw Normal View History

# This file is part of the Trezor project.
2017-01-03 18:40:05 +00:00
#
2019-05-29 16:44:09 +00:00
# Copyright (C) 2012-2019 SatoshiLabs and contributors
2017-01-03 18:40:05 +00:00
#
# 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.
2017-01-03 18:40:05 +00:00
#
# 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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
2018-08-13 16:21:24 +00:00
import pytest
2018-11-02 16:12:41 +00:00
from trezorlib import btc, messages as proto
from trezorlib.tools import parse_path
2019-09-11 12:43:32 +00:00
from ..tx_cache import tx_cache
2016-10-21 13:24:30 +00:00
2018-11-02 15:25:51 +00:00
TX_API = tx_cache("Zcash Testnet")
2018-08-13 16:21:24 +00:00
2018-09-12 18:34:26 +00:00
TXHASH_aaf51e = bytes.fromhex(
2018-08-13 16:21:24 +00:00
"aaf51e4606c264e47e5c42c958fe4cf1539c5172684721e38e69f4ef634d75dc"
)
2018-10-16 08:58:12 +00:00
TXHASH_e38206 = bytes.fromhex(
"e3820602226974b1dd87b7113cc8aea8c63e5ae29293991e7bfa80c126930368"
)
2017-06-23 19:31:42 +00:00
2017-07-28 13:24:18 +00:00
@pytest.mark.altcoin
@pytest.mark.zcash
2019-09-11 12:29:39 +00:00
class TestMsgSigntxZcash:
def test_one_one_fee_overwinter(self, client):
2018-10-16 08:58:12 +00:00
# prevout: aaf51e4606c264e47e5c42c958fe4cf1539c5172684721e38e69f4ef634d75dc:1
2018-06-05 14:02:51 +00:00
# input 1: 3.0 TAZ
2016-10-21 13:24:30 +00:00
inp1 = proto.TxInputType(
2018-08-13 16:21:24 +00:00
address_n=parse_path(
"m/Zcash Testnet/0h/0/0"
), # tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
2018-06-05 14:02:51 +00:00
amount=300000000,
prev_hash=TXHASH_aaf51e,
prev_index=1,
2017-06-23 19:31:42 +00:00
)
2016-10-21 13:24:30 +00:00
out1 = proto.TxOutputType(
2018-08-13 16:21:24 +00:00
address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z",
2018-06-05 14:02:51 +00:00
amount=300000000 - 1940,
script_type=proto.OutputScriptType.PAYTOADDRESS,
2017-06-23 19:31:42 +00:00
)
2016-10-21 13:24:30 +00:00
with client:
client.set_expected_responses(
2018-08-13 16:21:24 +00:00
[
proto.TxRequest(
request_type=proto.RequestType.TXINPUT,
details=proto.TxRequestDetailsType(request_index=0),
),
proto.TxRequest(
request_type=proto.RequestType.TXOUTPUT,
details=proto.TxRequestDetailsType(request_index=0),
),
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.TxRequest(
request_type=proto.RequestType.TXINPUT,
details=proto.TxRequestDetailsType(request_index=0),
),
proto.TxRequest(
request_type=proto.RequestType.TXOUTPUT,
details=proto.TxRequestDetailsType(request_index=0),
),
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
]
)
2016-10-21 13:24:30 +00:00
2018-11-02 15:25:51 +00:00
details = proto.SignTx(
2019-01-31 20:07:53 +00:00
version=3,
overwintered=True,
2019-02-14 23:23:37 +00:00
version_group_id=0x03C48270,
branch_id=0x5BA81B19,
2018-11-02 15:25:51 +00:00
)
_, serialized_tx = btc.sign_tx(
client,
2018-08-13 16:21:24 +00:00
"Zcash Testnet",
[inp1],
[out1],
2018-11-02 15:25:51 +00:00
details=details,
prev_txes=TX_API,
2018-08-13 16:21:24 +00:00
)
2016-10-21 13:24:30 +00:00
# Accepted by network: tx eda9b772c47f0c29310759960e0081c98707aa67a0a2738bcc71439fcf360675
2018-08-13 16:21:24 +00:00
assert (
2018-09-12 18:34:26 +00:00
serialized_tx.hex()
== "030000807082c40301dc754d63eff4698ee321476872519c53f14cfe58c9425c7ee464c206461ef5aa010000006a47304402207e45f303b4e42be824513855eb21653e1d2749cd94dcd0f0613d3f85d4efd1e20220699ffbdbcad889af7ede5ce9febf7a5ef8f5619b2464824529974c400cffaebc0121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff016c9be111000000001976a9145b157a678a10021243307e4bb58f36375aa80e1088ac000000000000000000"
2018-08-13 16:21:24 +00:00
)
2018-10-16 08:58:12 +00:00
def test_one_one_fee_sapling(self, client):
2018-10-16 08:58:12 +00:00
# prevout: e3820602226974b1dd87b7113cc8aea8c63e5ae29293991e7bfa80c126930368:0
# input 1: 3.0 TAZ
inp1 = proto.TxInputType(
address_n=parse_path(
"m/Zcash Testnet/0h/0/0"
), # tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
amount=300000000,
prev_hash=TXHASH_e38206,
prev_index=0,
)
out1 = proto.TxOutputType(
address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z",
amount=300000000 - 1940,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
with client:
client.set_expected_responses(
2018-10-16 08:58:12 +00:00
[
proto.TxRequest(
request_type=proto.RequestType.TXINPUT,
details=proto.TxRequestDetailsType(request_index=0),
),
proto.TxRequest(
request_type=proto.RequestType.TXOUTPUT,
details=proto.TxRequestDetailsType(request_index=0),
),
proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput),
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
proto.TxRequest(
request_type=proto.RequestType.TXINPUT,
details=proto.TxRequestDetailsType(request_index=0),
),
proto.TxRequest(
request_type=proto.RequestType.TXOUTPUT,
details=proto.TxRequestDetailsType(request_index=0),
),
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
]
)
2018-11-02 15:25:51 +00:00
details = proto.SignTx(
2019-01-31 20:07:53 +00:00
version=4,
overwintered=True,
version_group_id=0x892F2085,
branch_id=0x76B809BB,
2018-11-02 15:25:51 +00:00
)
_, serialized_tx = btc.sign_tx(
client,
2018-10-16 08:58:12 +00:00
"Zcash Testnet",
[inp1],
[out1],
2018-11-02 15:25:51 +00:00
details=details,
prev_txes=TX_API,
2018-10-16 08:58:12 +00:00
)
2018-10-17 14:58:25 +00:00
# Accepted by network: tx 0cef132c1d6d67f11cfa48f7fca3209da29cf872ac782354bedb686e61a17a78
2018-10-16 08:58:12 +00:00
assert (
serialized_tx.hex()
2018-10-17 14:58:25 +00:00
== "0400008085202f890168039326c180fa7b1e999392e25a3ec6a8aec83c11b787ddb1746922020682e3000000006b483045022100f28298891f48706697a6f898ac18e39ce2c7cebe547b585d51cc22d80b1b21a602201a807b8a18544832d95d1e3ada82c0617bc6d97d3f24d1fb4801ac396647aa880121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff016c9be111000000001976a9145b157a678a10021243307e4bb58f36375aa80e1088ac00000000000000000000000000000000000000"
2018-10-16 08:58:12 +00:00
)