-
-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# 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 <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||
|
||
import pytest | ||
|
||
from trezorlib import btc, messages as proto | ||
from trezorlib.exceptions import TrezorFailure | ||
from trezorlib.tools import parse_path | ||
|
||
from ..tx_cache import TxCache | ||
|
||
TX_CACHE_MAINNET = TxCache("Bitcoin") | ||
TX_CACHE_BCASH = TxCache("Bcash") | ||
|
||
TXHASH_8cc1f4 = bytes.fromhex( | ||
"8cc1f4adf7224ce855cf535a5104594a0004cb3b640d6714fdb00b9128832dd5" | ||
) | ||
TXHASH_d5f65e = bytes.fromhex( | ||
"d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" | ||
) | ||
|
||
|
||
class TestMsgSigntxInvalidPath: | ||
|
||
# Adapted from TestMsgSigntx.test_one_one_fee, | ||
# only changed the coin from Bitcoin to Litecoin. | ||
# Litecoin does not have strong replay protection using SIGHASH_FORKID, | ||
# spending from Bitcoin path should fail. | ||
@pytest.mark.altcoin | ||
def test_invalid_path_fail(self, client): | ||
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 | ||
# input 0: 0.0039 BTC | ||
|
||
inp1 = proto.TxInputType( | ||
address_n=parse_path("44h/0h/0h/0/0"), | ||
# amount=390000, | ||
prev_hash=TXHASH_d5f65e, | ||
prev_index=0, | ||
) | ||
|
||
# address is converted from 1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1 by changing the version | ||
out1 = proto.TxOutputType( | ||
address="LfWz9wLHmqU9HoDkMg9NqbRosrHvEixeVZ", | ||
amount=390000 - 10000, | ||
script_type=proto.OutputScriptType.PAYTOADDRESS, | ||
) | ||
|
||
with pytest.raises(TrezorFailure) as exc: | ||
btc.sign_tx(client, "Litecoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET) | ||
|
||
if client.features.model == "1": | ||
assert exc.value.code == proto.FailureType.ProcessError | ||
assert exc.value.message.endswith("Failed to compile input") | ||
else: | ||
assert exc.value.code == proto.FailureType.DataError | ||
assert exc.value.message.endswith("Forbidden key path") | ||
|
||
# Adapted from TestMsgSigntx.test_one_one_fee, | ||
# only changed the coin from Bitcoin to Bcash. | ||
# Bcash does have strong replay protection using SIGHASH_FORKID, | ||
# spending from Bitcoin path should work. | ||
@pytest.mark.altcoin | ||
def test_invalid_path_pass_forkid(self, client): | ||
# tx: 8cc1f4adf7224ce855cf535a5104594a0004cb3b640d6714fdb00b9128832dd5 | ||
# input 0: 0.0039 BTC | ||
|
||
inp1 = proto.TxInputType( | ||
address_n=parse_path("44h/0h/0h/0/0"), | ||
amount=390000, | ||
prev_hash=TXHASH_8cc1f4, | ||
prev_index=0, | ||
) | ||
|
||
# address is converted from 1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1 to cashaddr format | ||
out1 = proto.TxOutputType( | ||
address="bitcoincash:qr0fk25d5zygyn50u5w7h6jkvctas52n0qxff9ja6r", | ||
amount=390000 - 10000, | ||
script_type=proto.OutputScriptType.PAYTOADDRESS, | ||
) | ||
|
||
btc.sign_tx(client, "Bcash", [inp1], [out1], prev_txes=TX_CACHE_BCASH) |
18 changes: 18 additions & 0 deletions
18
tests/txcache/bcash/8cc1f4adf7224ce855cf535a5104594a0004cb3b640d6714fdb00b9128832dd5.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"bin_outputs": [ | ||
{ | ||
"amount": 390000, | ||
"script_pubkey": "a9147f844bdb0b8fd54b64e3d16c85dc1170f1ff97c187" | ||
} | ||
], | ||
"inputs": [ | ||
{ | ||
"prev_hash": "54aa5680dea781f45ebb536e53dffc526d68c0eb5c00547e323b2c32382dfba3", | ||
"prev_index": 1, | ||
"script_sig": "4830450221009e020b0390ccad533b73b552f8a99a9d827212c558e4f755503674d07c92ad4502202d606f7316990e0461c51d4add25054f19c697aa3e3c2ced4d568f0b2c57e62f0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43d", | ||
"sequence": 4294967295 | ||
} | ||
], | ||
"lock_time": 0, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters