2018-06-21 14:28:34 +00:00
|
|
|
# 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
|
2018-06-21 14:28:34 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2018-06-21 14:28:34 +00:00
|
|
|
# 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-04-10 09:42:21 +00:00
|
|
|
|
2018-11-02 16:12:41 +00:00
|
|
|
from trezorlib import btc, messages as proto
|
2020-03-27 09:31:29 +00:00
|
|
|
from trezorlib.exceptions import TrezorFailure
|
2018-05-11 12:53:51 +00:00
|
|
|
from trezorlib.tools import parse_path
|
2018-04-10 09:42:21 +00:00
|
|
|
|
2020-03-03 16:29:02 +00:00
|
|
|
from ..tx_cache import TxCache
|
2020-03-26 15:07:04 +00:00
|
|
|
from .signtx import (
|
|
|
|
request_extra_data,
|
|
|
|
request_finished,
|
|
|
|
request_input,
|
|
|
|
request_meta,
|
|
|
|
request_output,
|
|
|
|
)
|
2016-10-21 13:24:30 +00:00
|
|
|
|
2020-03-26 14:58:44 +00:00
|
|
|
B = proto.ButtonRequestType
|
2020-03-03 16:29:02 +00:00
|
|
|
TX_API = TxCache("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
|
|
|
|
2020-06-22 13:52:26 +00:00
|
|
|
TXHASH_v1 = bytes.fromhex(
|
|
|
|
"fb91ae741b120125b6d5c33a62f50a201b6ffd1cdc470c378c1ac8c654808246"
|
|
|
|
)
|
|
|
|
TXHASH_v2 = bytes.fromhex(
|
|
|
|
"03d30e19959d46d62ac796b8b23497b8c5700c59c4c75e1dbce7b8de49e242ef"
|
|
|
|
)
|
|
|
|
TXHASH_v3 = bytes.fromhex(
|
|
|
|
"f9418829d18140815f961c3f968b08700c283b616f3cb0f43413ae89e68ab76c"
|
|
|
|
)
|
|
|
|
TXHASH_v4 = bytes.fromhex(
|
|
|
|
"5d8de67264b08eecc8e3bee19a11a7f54a2bce1dc4f2a699538e372ae92e9c0f"
|
|
|
|
)
|
|
|
|
|
2017-07-28 13:24:18 +00:00
|
|
|
|
2019-08-22 16:47:01 +00:00
|
|
|
@pytest.mark.altcoin
|
device_tests: allow custom runxfail
We can now selectively runxfail certain tests. This is useful for
accepting PRs into trezor-core:
1. trezor-core is going to get a pytest.ini that sets xfail_strict.
That means that if an `xfail`ed test actually passes, that will
break the test suite. So it will be visible when we implement
a feature for which tests exist.
2. To allow PRs to pass the test suite without touching python-trezor
directly, we add a new pytest.ini option: run_xfail.
This adds a list of markers which will ignore `xfail`.
So:
2.1 First, the python-trezor PR marks the tests with the name
of the feature. This commit already does that: Lisk tests
are marked `@pytest.mark.lisk`, NEMs are `@pytest.mark.nem`,
etc.
The tests will be also marked with `xfail`, because the
feature is not in core yet.
2.2 Then, the trezor-core PR implements the feature, which makes
the `xfail`ed tests pass. That breaks the test suite.
2.3 To fix the test suite, the core PR also adds a `run_xfail`
to `pytest.ini`: `run_xfail = lisk`.
(it can take a list: `run_xfail = lisk nem stellar`)
That will make the test suite behave as if the tests are not
`xfail`ed. If the feature is implemented correctly, the tests
will pass.
2.4 When the PR is accepted to core, the next step should be
a PR to python-trezor that removes the `xfail`s. After that,
we should also remove the `run_xfail` option, just to be tidy.
2018-05-21 15:44:02 +00:00
|
|
|
@pytest.mark.zcash
|
2019-09-11 12:29:39 +00:00
|
|
|
class TestMsgSigntxZcash:
|
2019-08-27 14:58:59 +00:00
|
|
|
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
|
|
|
|
2017-12-12 15:40:11 +00:00
|
|
|
inp1 = proto.TxInputType(
|
2020-03-04 12:38:33 +00:00
|
|
|
# tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
|
|
|
|
address_n=parse_path("m/44h/1h/0h/0/0"),
|
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
|
|
|
|
2017-12-12 15:40:11 +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,
|
2017-12-12 15:40:11 +00:00
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
2016-10-21 13:24:30 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
2018-08-13 16:21:24 +00:00
|
|
|
[
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_aaf51e),
|
|
|
|
request_input(0, TXHASH_aaf51e),
|
|
|
|
request_output(0, TXHASH_aaf51e),
|
|
|
|
request_output(1, TXHASH_aaf51e),
|
|
|
|
request_extra_data(0, 1, TXHASH_aaf51e),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_output(0),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
|
|
|
request_finished(),
|
2018-08-13 16:21:24 +00:00
|
|
|
]
|
|
|
|
)
|
2016-10-21 13:24:30 +00:00
|
|
|
|
2018-11-02 15:25:51 +00:00
|
|
|
details = proto.SignTx(
|
2020-03-12 14:30:21 +00:00
|
|
|
version=3, version_group_id=0x03C48270, branch_id=0x5BA81B19,
|
2018-11-02 15:25:51 +00:00
|
|
|
)
|
|
|
|
_, serialized_tx = btc.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
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
|
|
|
|
2018-06-15 08:34:49 +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
|
|
|
|
2019-08-27 14:58:59 +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(
|
2020-03-04 12:38:33 +00:00
|
|
|
# tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
|
|
|
|
address_n=parse_path("m/44h/1h/0h/0/0"),
|
2018-10-16 08:58:12 +00:00
|
|
|
amount=300000000,
|
|
|
|
prev_hash=TXHASH_e38206,
|
|
|
|
prev_index=0,
|
|
|
|
)
|
|
|
|
|
|
|
|
out1 = proto.TxOutputType(
|
|
|
|
address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z",
|
|
|
|
amount=300000000 - 1940,
|
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
2018-10-16 08:58:12 +00:00
|
|
|
[
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_e38206),
|
|
|
|
request_input(0, TXHASH_e38206),
|
|
|
|
request_input(1, TXHASH_e38206),
|
|
|
|
request_output(0, TXHASH_e38206),
|
|
|
|
request_output(1, TXHASH_e38206),
|
|
|
|
request_extra_data(0, 1, TXHASH_e38206),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_output(0),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
|
|
|
request_finished(),
|
2018-10-16 08:58:12 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2018-11-02 15:25:51 +00:00
|
|
|
details = proto.SignTx(
|
2020-03-12 14:30:21 +00:00
|
|
|
version=4, version_group_id=0x892F2085, branch_id=0x76B809BB,
|
2018-11-02 15:25:51 +00:00
|
|
|
)
|
|
|
|
_, serialized_tx = btc.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
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
|
|
|
)
|
2020-03-27 09:31:29 +00:00
|
|
|
|
2020-06-22 11:04:46 +00:00
|
|
|
@pytest.mark.skip_ui
|
|
|
|
def test_version_group_id_missing(self, client):
|
|
|
|
inp1 = proto.TxInputType(
|
|
|
|
# tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
|
|
|
|
address_n=parse_path("m/44h/1h/0h/0/0"),
|
|
|
|
amount=300000000,
|
|
|
|
prev_hash=TXHASH_e38206,
|
|
|
|
prev_index=0,
|
|
|
|
)
|
|
|
|
out1 = proto.TxOutputType(
|
|
|
|
address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z",
|
|
|
|
amount=300000000 - 1940,
|
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
2020-03-27 09:31:29 +00:00
|
|
|
|
2020-06-22 11:04:46 +00:00
|
|
|
details = proto.SignTx(version=4)
|
|
|
|
with pytest.raises(TrezorFailure, match="Version group ID must be set."):
|
|
|
|
btc.sign_tx(
|
|
|
|
client,
|
|
|
|
"Zcash Testnet",
|
|
|
|
[inp1],
|
|
|
|
[out1],
|
|
|
|
details=details,
|
|
|
|
prev_txes=TX_API,
|
|
|
|
)
|
2020-06-22 13:52:26 +00:00
|
|
|
|
|
|
|
def test_spend_old_versions(self, client):
|
|
|
|
# inputs are NOT OWNED by this seed
|
|
|
|
input_v1 = proto.TxInputType(
|
|
|
|
address_n=parse_path("m/44h/1h/0h/0/0"),
|
|
|
|
amount=123000000,
|
|
|
|
prev_hash=TXHASH_v1,
|
|
|
|
prev_index=0,
|
|
|
|
)
|
|
|
|
input_v2 = proto.TxInputType(
|
|
|
|
address_n=parse_path("m/44h/1h/0h/0/1"),
|
|
|
|
amount=49990000,
|
|
|
|
prev_hash=TXHASH_v2,
|
|
|
|
prev_index=0,
|
|
|
|
)
|
|
|
|
input_v3 = proto.TxInputType(
|
|
|
|
address_n=parse_path("m/44h/1h/0h/0/2"),
|
|
|
|
amount=300000000,
|
|
|
|
prev_hash=TXHASH_v3,
|
|
|
|
prev_index=1,
|
|
|
|
)
|
|
|
|
input_v4 = proto.TxInputType(
|
|
|
|
address_n=parse_path("m/44h/1h/0h/0/3"),
|
|
|
|
amount=100000,
|
|
|
|
prev_hash=TXHASH_v4,
|
|
|
|
prev_index=0,
|
|
|
|
)
|
|
|
|
|
|
|
|
inputs = [input_v1, input_v2, input_v3, input_v4]
|
|
|
|
|
|
|
|
for i, txi in enumerate(inputs, 1):
|
|
|
|
txdata = TX_API[txi.prev_hash]
|
|
|
|
assert txdata.version == i
|
|
|
|
|
|
|
|
output = proto.TxOutputType(
|
|
|
|
address="tmNvfeKR5PkcQazLEqddTskFr6Ev9tsovfQ",
|
|
|
|
amount=sum(txi.amount for txi in inputs),
|
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
|
|
|
|
|
|
|
details = proto.SignTx(
|
|
|
|
version=4, version_group_id=0x892F2085, branch_id=0x76B809BB,
|
|
|
|
)
|
|
|
|
|
|
|
|
with client:
|
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client,
|
|
|
|
"Zcash Testnet",
|
|
|
|
inputs,
|
|
|
|
[output],
|
|
|
|
details=details,
|
|
|
|
prev_txes=TX_API,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
|
|
|
== "0400008085202f890446828054c6c81a8c370c47dc1cfd6f1b200af5623ac3d5b62501121b74ae91fb000000006b483045022100d40e85efbadd378fc603dc8b11c70774086de631fe5b1418ac2b95a478f86507022072e999d8ddd75a0b33bd2adcc88e7234e6251b9e73c9223e7c59e0d1f8d1ff220121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffffef42e249deb8e7bc1d5ec7c4590c70c5b89734b2b896c72ad6469d95190ed303000000006b483045022100917d96445d64c80f9569cb9ca45c04c9b6d7b0fda6b9fd0b1d311837366c699202202cd6140489cf38b5d97ed271ba28603f4693c2a36113cc6ec423301f077c5a8e01210294e3e5e77e22eea0e4c0d30d89beb4db7f69b4bf1ae709e411d6a06618b8f852ffffffff6cb78ae689ae1334f4b03c6f613b280c70088b963f1c965f814081d1298841f9010000006a473044022058768c74c9b1698070636388d7d2ae8223748f13b0a5f402716e4d49fc5bc5f30220658d1e6095dcfbe66669b4141d23af28c9ed5bae73480889429b41742be85f32012103f5008445568548bd745a3dedccc6048969436bf1a49411f60938ff1938941f14ffffffff0f9c2ee92a378e5399a6f2c41dce2b4af5a7119ae1bee3c8ec8eb06472e68d5d000000006b483045022100e64853d86bed039c4edce4abaf80d41486cd21c63bec79c0308ea05a351663e302206732aa22a5dee7bd7f3cc8268faebe31a08abadb4b7e3a4257509bc7baa052b60121029ad0b9519779c540b34fa8d11d24d14a5475546bfa28c7de50573d22a503ce21ffffffff01d0c7321c000000001976a91490ede9de4bed6e39008375eace793949de9a533288ac00000000000000000000000000000000000000"
|
|
|
|
)
|