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
|
2018-05-11 12:53:51 +00:00
|
|
|
from trezorlib.tools import parse_path
|
2018-04-10 09:42:21 +00:00
|
|
|
|
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
|
|
|
|
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(
|
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
|
|
|
|
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
|
|
|
[
|
|
|
|
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,
|
2019-01-31 20:22:51 +00:00
|
|
|
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(
|
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
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,
|
2019-01-31 20:22:51 +00:00
|
|
|
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
|
|
|
)
|