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>.
|
2017-01-03 18:40:05 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
import pytest
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
from trezorlib import btc, messages
|
2022-01-31 12:25:30 +00:00
|
|
|
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
2018-08-13 16:21:24 +00:00
|
|
|
from trezorlib.tools import H_, parse_path
|
|
|
|
|
2021-11-29 11:00:01 +00:00
|
|
|
from ... import bip32
|
|
|
|
from ...common import MNEMONIC12
|
|
|
|
from ...tx_cache import TxCache
|
2022-01-24 20:23:58 +00:00
|
|
|
from .signtx import request_finished, request_input, request_meta, request_output
|
2018-07-03 15:26:22 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
B = messages.ButtonRequestType
|
2020-03-03 16:29:02 +00:00
|
|
|
TX_API = TxCache("Testnet")
|
2021-06-24 13:31:49 +00:00
|
|
|
# NOTE: This test case was migrated from Testnet to Bitcoin, because we
|
|
|
|
# disabled testnet for BIP-45 paths. So we are still using the Testnet TxCache
|
|
|
|
# here, but everything else has been changed to Bitcoin mainnet.
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2020-03-26 14:58:44 +00:00
|
|
|
TXHASH_16c6c8 = bytes.fromhex(
|
|
|
|
"16c6c8471b8db7a628f2b2bb86bfeefae1766463ce8692438c7fd3fce3f43ce5"
|
|
|
|
)
|
|
|
|
TXHASH_d80c34 = bytes.fromhex(
|
|
|
|
"d80c34ee14143a8bf61125102b7ef594118a3796cad670fa8ee15080ae155318"
|
|
|
|
)
|
|
|
|
TXHASH_b0946d = bytes.fromhex(
|
|
|
|
"b0946dc27ba308a749b11afecc2018980af18f79e89ad6b080b58220d856f739"
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
pytestmark = [pytest.mark.multisig, pytest.mark.setup_client(mnemonic=MNEMONIC12)]
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
|
|
|
|
NODE_EXT1 = bip32.deserialize(
|
|
|
|
"xpub69qexv5TppjJQtXwSGeGXNtgGWyUzvsHACMt4Rr61Be4CmCf55eFcuXX828aySNuNR7hQYUCvUgZpioNxfs2HTAZWUUSFywhErg7JfTPv3Y"
|
|
|
|
)
|
|
|
|
# m/1 => 02c0d0c5fee952620757c6128dbf327c996cd72ed3358d15d6518a1186099bc15e
|
|
|
|
# m/2 => 0375b9dfaad928ce1a7eed88df7c084e67d99e9ab74332419458a9a45779706801
|
|
|
|
|
|
|
|
NODE_EXT2 = bip32.deserialize(
|
|
|
|
"xpub69qexv5TppjJRiLLK2K1FZNCFcErkXprCo3jabCXMiqX5CFF4LHedwcXvXkTuBL9tFLWVxuGWrdeerXjiWpC1gynTNUaySDsr8SU5xMpj5R"
|
|
|
|
)
|
|
|
|
# m/1 => 0388460dc439f4c8f5bcfc268c36e11b4375cad5c3535c336cfdf8c32c3afad5c1
|
|
|
|
# m/2 => 03a04f945d5a3685729dde697d574076de4bdf38e904f813b22a851548e1110fc0
|
|
|
|
|
|
|
|
NODE_EXT3 = bip32.deserialize(
|
|
|
|
"xpub69qexv5TppjJVYtxFKSBFxcVGyaC8VJDa1RugAYwEDLVUBuaXrVgznvQB44piM8MRerfVf1pNCBK1L1NzhyKd4Ay25BVZX3S8twWfZDxmz7"
|
|
|
|
)
|
|
|
|
# m/1 => 02e0c21e2a7cf00b94c5421725acff97f9826598b91f2340c5ddda730caca7d648
|
|
|
|
# m/2 => 03928301ffb8c0d7a364b794914c716ba3107cc78a6fe581028b0d8638b22e8573
|
|
|
|
|
|
|
|
NODE_INT = bip32.deserialize(
|
|
|
|
"xpub69qexv5TppjJNEK5bfX8vQ6ASXDUQ5PohSajrHgeknHZ4SJipn7edmpRmiiBLLDtPur71mekZFazhgas8rkUMnS7quk5qp64TLLV8ShrxZJ"
|
|
|
|
)
|
|
|
|
# m/1 => 03f91460d79e4e463d7d90cb75254bcd62b515a99a950574c721efdc5f711dff35
|
|
|
|
# m/2 => 038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3
|
|
|
|
|
|
|
|
# ext1 + ext2 + int
|
|
|
|
# redeemscript (2 of 3): 522102c0d0c5fee952620757c6128dbf327c996cd72ed3358d15d6518a1186099bc15e210388460dc439f4c8f5bcfc268c36e11b4375cad5c3535c336cfdf8c32c3afad5c1210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a653ae
|
|
|
|
# multisig address: 2N9W4z9AhAPaHghtqVQPbaTAGHdbrhKeBQw
|
|
|
|
# tx: 16c6c8471b8db7a628f2b2bb86bfeefae1766463ce8692438c7fd3fce3f43ce5
|
|
|
|
# input 0: 0.5 BTC
|
|
|
|
|
|
|
|
# ext1 + int + ext2
|
|
|
|
# redeemscript (2 of 3): 522102c0d0c5fee952620757c6128dbf327c996cd72ed3358d15d6518a1186099bc15e210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6210388460dc439f4c8f5bcfc268c36e11b4375cad5c3535c336cfdf8c32c3afad5c153ae
|
|
|
|
# multisig address: 2NDBG6QXQLtnQ3jRGkrqo53BiCeXfQXLdj4
|
|
|
|
# tx: d80c34ee14143a8bf61125102b7ef594118a3796cad670fa8ee15080ae155318
|
|
|
|
# input 0: 0.345 BTC
|
|
|
|
|
|
|
|
# ext1 + ext3 + int
|
|
|
|
# redeemscript (2 of 3): 522102c0d0c5fee952620757c6128dbf327c996cd72ed3358d15d6518a1186099bc15e2102e0c21e2a7cf00b94c5421725acff97f9826598b91f2340c5ddda730caca7d648210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a653ae
|
|
|
|
# multisig address: 2MvwPWfp2XPU3S1cMwgEMKBPUw38VP5SBE4
|
|
|
|
# tx: b0946dc27ba308a749b11afecc2018980af18f79e89ad6b080b58220d856f739
|
|
|
|
# input 1: 0.555 BTC
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_in1 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT2, NODE_EXT1, NODE_INT],
|
|
|
|
address_n=[0, 0],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_in2 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT1, NODE_EXT2, NODE_INT],
|
|
|
|
address_n=[0, 1],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_in3 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT1, NODE_EXT3, NODE_INT],
|
|
|
|
address_n=[0, 1],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
|
|
|
# 2N9W4z9AhAPaHghtqVQPbaTAGHdbrhKeBQw
|
2021-11-10 21:28:11 +00:00
|
|
|
INP1 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 0, 0],
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=50_000_000,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_16c6c8,
|
|
|
|
prev_index=1,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
multisig=multisig_in1,
|
|
|
|
)
|
|
|
|
|
|
|
|
# 2NDBG6QXQLtnQ3jRGkrqo53BiCeXfQXLdj4
|
2021-11-10 21:28:11 +00:00
|
|
|
INP2 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 0, 1],
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=34_500_000,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_d80c34,
|
|
|
|
prev_index=0,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
multisig=multisig_in2,
|
|
|
|
)
|
|
|
|
|
|
|
|
# 2MvwPWfp2XPU3S1cMwgEMKBPUw38VP5SBE4
|
2021-11-10 21:28:11 +00:00
|
|
|
INP3 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 0, 1],
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=55_500_000,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_b0946d,
|
|
|
|
prev_index=0,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
multisig=multisig_in3,
|
|
|
|
)
|
|
|
|
|
2021-11-29 11:00:01 +00:00
|
|
|
|
2022-10-25 13:08:19 +00:00
|
|
|
def _responses(
|
|
|
|
client: Client,
|
|
|
|
INP1: messages.TxInputType,
|
|
|
|
INP2: messages.TxInputType,
|
|
|
|
change: int = 0,
|
2022-09-22 11:20:58 +00:00
|
|
|
foreign: bool = False,
|
2022-10-25 13:08:19 +00:00
|
|
|
):
|
2023-10-11 22:31:02 +00:00
|
|
|
is_core = client.features.model in ("T", "Safe 3")
|
2021-11-10 21:19:53 +00:00
|
|
|
resp = [
|
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
|
|
|
]
|
2022-09-22 11:20:58 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
if change != 1:
|
2021-11-10 21:28:11 +00:00
|
|
|
resp.append(messages.ButtonRequest(code=B.ConfirmOutput))
|
2023-09-14 15:55:26 +00:00
|
|
|
if is_core:
|
2022-10-25 13:08:19 +00:00
|
|
|
resp.append(messages.ButtonRequest(code=B.ConfirmOutput))
|
2022-09-22 11:20:58 +00:00
|
|
|
elif foreign:
|
|
|
|
resp.append(messages.ButtonRequest(code=B.UnknownDerivationPath))
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
resp.append(request_output(1))
|
2022-09-22 11:20:58 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
if change != 2:
|
2021-11-10 21:28:11 +00:00
|
|
|
resp.append(messages.ButtonRequest(code=B.ConfirmOutput))
|
2023-09-14 15:55:26 +00:00
|
|
|
if is_core:
|
2022-10-25 13:08:19 +00:00
|
|
|
resp.append(messages.ButtonRequest(code=B.ConfirmOutput))
|
2022-09-22 11:20:58 +00:00
|
|
|
elif foreign:
|
|
|
|
resp.append(messages.ButtonRequest(code=B.UnknownDerivationPath))
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
resp += [
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.SignTx),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
|
|
|
request_meta(INP1.prev_hash),
|
|
|
|
request_input(0, INP1.prev_hash),
|
|
|
|
request_output(0, INP1.prev_hash),
|
|
|
|
request_output(1, INP1.prev_hash),
|
|
|
|
request_input(1),
|
|
|
|
request_meta(INP2.prev_hash),
|
|
|
|
request_input(0, INP2.prev_hash),
|
|
|
|
request_output(0, INP2.prev_hash),
|
|
|
|
request_output(1, INP2.prev_hash),
|
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
request_finished(),
|
|
|
|
]
|
|
|
|
return resp
|
|
|
|
|
|
|
|
|
|
|
|
# both outputs are external
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_external_external(client: Client):
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="1F8yBZB2NZhPZvJekhjTwjhQRRvQeTjjXr",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="1H7uXJQTVwXca2BXF2opTrvuZapk8Cm8zY",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
with client:
|
2022-10-25 13:08:19 +00:00
|
|
|
client.set_expected_responses(_responses(client, INP1, INP2))
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
|
|
|
)
|
|
|
|
|
2022-03-11 16:30:13 +00:00
|
|
|
# Transaction does not exist on the blockchain, not using assert_tx_matches()
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
|
|
|
== "0100000002e53cf4e3fcd37f8c439286ce636476e1faeebf86bbb2f228a6b78d1b47c8c61601000000b400473044022064f13801744a6c21b694f62cdb5d834e852f13ecf85ed4d0a56ba279571c24e3022010fab4cb05bdd7b24c8376dda4f62a418548eea6eb483e58675fa06e0d5c642c014c69522103dc07026aacb5918dac4e09f9da8290d0ae22161699636c22cace78082116a7792103e70db185fad69c2971f0107a42930e5d82a9ed3a11b922a96fdfc4124b63e54c2103f3fe007a1e34ac76c1a2528e9149f90f9f93739929797afab6a8e18d682fa71053aeffffffff185315ae8050e18efa70d6ca96378a1194f57e2b102511f68b3a1414ee340cd800000000b4004730440220727b2522268f913acd213c507d7801b146e5b6cef666ad44b769c26d6c762e4d022021c0c2e9e8298dee2a490d956f7ab1b2d3160c1e37a50cc6d19a5e62eb484fc9014c6952210297ad8a5df42f9e362ef37d9a4ddced89d8f7a143690649aa0d0ff049c7daca842103ed1fd93989595d7ad4b488efd05a22c0239482c9a20923f2f214a38e54f6c41a2103f91460d79e4e463d7d90cb75254bcd62b515a99a950574c721efdc5f711dff3553aeffffffff02005a6202000000001976a9149b139230e4fe91c05a37ec334dc8378f3dbe377088ac00639f02000000001976a914b0d05a10926a7925508febdbab9a5bd4cda8c8f688ac00000000"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
|
|
|
|
# first external, second internal
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_external_internal(client: Client):
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="1F8yBZB2NZhPZvJekhjTwjhQRRvQeTjjXr",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/45h/0/1/1"),
|
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
with client:
|
2022-09-22 11:20:58 +00:00
|
|
|
client.set_expected_responses(
|
|
|
|
_responses(client, INP1, INP2, change=2, foreign=True)
|
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
|
|
|
)
|
|
|
|
|
2022-03-11 16:30:13 +00:00
|
|
|
# Transaction does not exist on the blockchain, not using assert_tx_matches()
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
|
|
|
== "0100000002e53cf4e3fcd37f8c439286ce636476e1faeebf86bbb2f228a6b78d1b47c8c61601000000b400473044022064f13801744a6c21b694f62cdb5d834e852f13ecf85ed4d0a56ba279571c24e3022010fab4cb05bdd7b24c8376dda4f62a418548eea6eb483e58675fa06e0d5c642c014c69522103dc07026aacb5918dac4e09f9da8290d0ae22161699636c22cace78082116a7792103e70db185fad69c2971f0107a42930e5d82a9ed3a11b922a96fdfc4124b63e54c2103f3fe007a1e34ac76c1a2528e9149f90f9f93739929797afab6a8e18d682fa71053aeffffffff185315ae8050e18efa70d6ca96378a1194f57e2b102511f68b3a1414ee340cd800000000b4004730440220727b2522268f913acd213c507d7801b146e5b6cef666ad44b769c26d6c762e4d022021c0c2e9e8298dee2a490d956f7ab1b2d3160c1e37a50cc6d19a5e62eb484fc9014c6952210297ad8a5df42f9e362ef37d9a4ddced89d8f7a143690649aa0d0ff049c7daca842103ed1fd93989595d7ad4b488efd05a22c0239482c9a20923f2f214a38e54f6c41a2103f91460d79e4e463d7d90cb75254bcd62b515a99a950574c721efdc5f711dff3553aeffffffff02005a6202000000001976a9149b139230e4fe91c05a37ec334dc8378f3dbe377088ac00639f02000000001976a914b0d05a10926a7925508febdbab9a5bd4cda8c8f688ac00000000"
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
|
|
|
|
# first internal, second external
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_internal_external(client: Client):
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/45h/0/1/0"),
|
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="1H7uXJQTVwXca2BXF2opTrvuZapk8Cm8zY",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
with client:
|
2022-09-22 11:20:58 +00:00
|
|
|
client.set_expected_responses(
|
|
|
|
_responses(client, INP1, INP2, change=1, foreign=True)
|
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
|
|
|
)
|
|
|
|
|
2022-03-11 16:30:13 +00:00
|
|
|
# Transaction does not exist on the blockchain, not using assert_tx_matches()
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
|
|
|
== "0100000002e53cf4e3fcd37f8c439286ce636476e1faeebf86bbb2f228a6b78d1b47c8c61601000000b400473044022064f13801744a6c21b694f62cdb5d834e852f13ecf85ed4d0a56ba279571c24e3022010fab4cb05bdd7b24c8376dda4f62a418548eea6eb483e58675fa06e0d5c642c014c69522103dc07026aacb5918dac4e09f9da8290d0ae22161699636c22cace78082116a7792103e70db185fad69c2971f0107a42930e5d82a9ed3a11b922a96fdfc4124b63e54c2103f3fe007a1e34ac76c1a2528e9149f90f9f93739929797afab6a8e18d682fa71053aeffffffff185315ae8050e18efa70d6ca96378a1194f57e2b102511f68b3a1414ee340cd800000000b4004730440220727b2522268f913acd213c507d7801b146e5b6cef666ad44b769c26d6c762e4d022021c0c2e9e8298dee2a490d956f7ab1b2d3160c1e37a50cc6d19a5e62eb484fc9014c6952210297ad8a5df42f9e362ef37d9a4ddced89d8f7a143690649aa0d0ff049c7daca842103ed1fd93989595d7ad4b488efd05a22c0239482c9a20923f2f214a38e54f6c41a2103f91460d79e4e463d7d90cb75254bcd62b515a99a950574c721efdc5f711dff3553aeffffffff02005a6202000000001976a9149b139230e4fe91c05a37ec334dc8378f3dbe377088ac00639f02000000001976a914b0d05a10926a7925508febdbab9a5bd4cda8c8f688ac00000000"
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
|
|
|
|
# both outputs are external
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_multisig_external_external(client: Client):
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3B23k4kFBRtu49zvpG3Z9xuFzfpHvxBcwt",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3PkXLsY7AUZCrCKGvX8FfP2EawowUBMbcg",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
with client:
|
2022-10-25 13:08:19 +00:00
|
|
|
client.set_expected_responses(_responses(client, INP1, INP2))
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2022-03-11 16:30:13 +00:00
|
|
|
# Transaction does not exist on the blockchain, not using assert_tx_matches()
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
|
|
|
== "0100000002e53cf4e3fcd37f8c439286ce636476e1faeebf86bbb2f228a6b78d1b47c8c61601000000b400473044022059394e0dfcb2d2f4a6108703f801545ca5a820c0ac6a1859d0a3854813de55fa02207b6a57d70b82932ff58163336c461653a2dc82c78ed8157159e5178ac7325390014c69522103dc07026aacb5918dac4e09f9da8290d0ae22161699636c22cace78082116a7792103e70db185fad69c2971f0107a42930e5d82a9ed3a11b922a96fdfc4124b63e54c2103f3fe007a1e34ac76c1a2528e9149f90f9f93739929797afab6a8e18d682fa71053aeffffffff185315ae8050e18efa70d6ca96378a1194f57e2b102511f68b3a1414ee340cd800000000b40047304402205a911685f5b974b2fc4a19d5ce056218773a4d20b5eaae2c2f9594929308182002201e03449f5a8813ec19f408bf1b6f4f334886d6fcf9920e300fd7678ef0724f81014c6952210297ad8a5df42f9e362ef37d9a4ddced89d8f7a143690649aa0d0ff049c7daca842103ed1fd93989595d7ad4b488efd05a22c0239482c9a20923f2f214a38e54f6c41a2103f91460d79e4e463d7d90cb75254bcd62b515a99a950574c721efdc5f711dff3553aeffffffff02005a62020000000017a91466528dd543f94d162c8111d2ec248d25ba9b90948700639f020000000017a914f1fc92c0aed1712911c70a2e09ac15ff0922652f8700000000"
|
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
# inputs match, change matches (first is change)
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_multisig_change_match_first(client: Client):
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_out1 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT2, NODE_EXT1, NODE_INT],
|
|
|
|
address_n=[1, 0],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 1, 0],
|
|
|
|
multisig=multisig_out1,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3PkXLsY7AUZCrCKGvX8FfP2EawowUBMbcg",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
with client:
|
2022-10-25 13:08:19 +00:00
|
|
|
client.set_expected_responses(_responses(client, INP1, INP2, change=1))
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2022-03-11 16:30:13 +00:00
|
|
|
# Transaction does not exist on the blockchain, not using assert_tx_matches()
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
|
|
|
== "0100000002e53cf4e3fcd37f8c439286ce636476e1faeebf86bbb2f228a6b78d1b47c8c61601000000b400473044022059394e0dfcb2d2f4a6108703f801545ca5a820c0ac6a1859d0a3854813de55fa02207b6a57d70b82932ff58163336c461653a2dc82c78ed8157159e5178ac7325390014c69522103dc07026aacb5918dac4e09f9da8290d0ae22161699636c22cace78082116a7792103e70db185fad69c2971f0107a42930e5d82a9ed3a11b922a96fdfc4124b63e54c2103f3fe007a1e34ac76c1a2528e9149f90f9f93739929797afab6a8e18d682fa71053aeffffffff185315ae8050e18efa70d6ca96378a1194f57e2b102511f68b3a1414ee340cd800000000b40047304402205a911685f5b974b2fc4a19d5ce056218773a4d20b5eaae2c2f9594929308182002201e03449f5a8813ec19f408bf1b6f4f334886d6fcf9920e300fd7678ef0724f81014c6952210297ad8a5df42f9e362ef37d9a4ddced89d8f7a143690649aa0d0ff049c7daca842103ed1fd93989595d7ad4b488efd05a22c0239482c9a20923f2f214a38e54f6c41a2103f91460d79e4e463d7d90cb75254bcd62b515a99a950574c721efdc5f711dff3553aeffffffff02005a62020000000017a91466528dd543f94d162c8111d2ec248d25ba9b90948700639f020000000017a914f1fc92c0aed1712911c70a2e09ac15ff0922652f8700000000"
|
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
# inputs match, change matches (second is change)
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_multisig_change_match_second(client: Client):
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_out2 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT1, NODE_EXT2, NODE_INT],
|
|
|
|
address_n=[1, 1],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3B23k4kFBRtu49zvpG3Z9xuFzfpHvxBcwt",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 1, 1],
|
|
|
|
multisig=multisig_out2,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
with client:
|
2022-10-25 13:08:19 +00:00
|
|
|
client.set_expected_responses(_responses(client, INP1, INP2, change=2))
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2022-03-11 16:30:13 +00:00
|
|
|
# Transaction does not exist on the blockchain, not using assert_tx_matches()
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
|
|
|
== "0100000002e53cf4e3fcd37f8c439286ce636476e1faeebf86bbb2f228a6b78d1b47c8c61601000000b400473044022059394e0dfcb2d2f4a6108703f801545ca5a820c0ac6a1859d0a3854813de55fa02207b6a57d70b82932ff58163336c461653a2dc82c78ed8157159e5178ac7325390014c69522103dc07026aacb5918dac4e09f9da8290d0ae22161699636c22cace78082116a7792103e70db185fad69c2971f0107a42930e5d82a9ed3a11b922a96fdfc4124b63e54c2103f3fe007a1e34ac76c1a2528e9149f90f9f93739929797afab6a8e18d682fa71053aeffffffff185315ae8050e18efa70d6ca96378a1194f57e2b102511f68b3a1414ee340cd800000000b40047304402205a911685f5b974b2fc4a19d5ce056218773a4d20b5eaae2c2f9594929308182002201e03449f5a8813ec19f408bf1b6f4f334886d6fcf9920e300fd7678ef0724f81014c6952210297ad8a5df42f9e362ef37d9a4ddced89d8f7a143690649aa0d0ff049c7daca842103ed1fd93989595d7ad4b488efd05a22c0239482c9a20923f2f214a38e54f6c41a2103f91460d79e4e463d7d90cb75254bcd62b515a99a950574c721efdc5f711dff3553aeffffffff02005a62020000000017a91466528dd543f94d162c8111d2ec248d25ba9b90948700639f020000000017a914f1fc92c0aed1712911c70a2e09ac15ff0922652f8700000000"
|
|
|
|
)
|
2017-06-23 19:31:42 +00:00
|
|
|
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
# inputs match, change mismatches (second tries to be change but isn't)
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_multisig_mismatch_change(client: Client):
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_out2 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT1, NODE_INT, NODE_EXT3],
|
|
|
|
address_n=[1, 0],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3B23k4kFBRtu49zvpG3Z9xuFzfpHvxBcwt",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 1, 0],
|
|
|
|
multisig=multisig_out2,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
with client:
|
2022-10-25 13:08:19 +00:00
|
|
|
client.set_expected_responses(_responses(client, INP1, INP2))
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
|
|
|
|
2022-03-11 16:30:13 +00:00
|
|
|
# Transaction does not exist on the blockchain, not using assert_tx_matches()
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
|
|
|
== "0100000002e53cf4e3fcd37f8c439286ce636476e1faeebf86bbb2f228a6b78d1b47c8c61601000000b40047304402207f9992cc0230527faf54ec6bd233307db82bc8fac039dcee418bc6feb4e96a3a02206bb4cb157ad27c123277328a877572563a45d70b844d9ab07cc42238112f8c2a014c69522103dc07026aacb5918dac4e09f9da8290d0ae22161699636c22cace78082116a7792103e70db185fad69c2971f0107a42930e5d82a9ed3a11b922a96fdfc4124b63e54c2103f3fe007a1e34ac76c1a2528e9149f90f9f93739929797afab6a8e18d682fa71053aeffffffff185315ae8050e18efa70d6ca96378a1194f57e2b102511f68b3a1414ee340cd800000000b400473044022078a41bfa87d72d6ba810d84bf568b5a29acf8b851ba6c3a8dbff079b34a7feb0022037b770c776db0b6c883c38a684a121b90a59ed1958774cbf64de70e53e29639f014c6952210297ad8a5df42f9e362ef37d9a4ddced89d8f7a143690649aa0d0ff049c7daca842103ed1fd93989595d7ad4b488efd05a22c0239482c9a20923f2f214a38e54f6c41a2103f91460d79e4e463d7d90cb75254bcd62b515a99a950574c721efdc5f711dff3553aeffffffff02005a62020000000017a91466528dd543f94d162c8111d2ec248d25ba9b90948700639f020000000017a914e6a3e2fbadb7f559f8d20c46aceae78c96fcf1d18700000000"
|
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
# inputs mismatch, change matches with first input
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_multisig_mismatch_inputs(client: Client):
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_out1 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT2, NODE_EXT1, NODE_INT],
|
|
|
|
address_n=[1, 0],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 1, 0],
|
|
|
|
multisig=multisig_out1,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3PkXLsY7AUZCrCKGvX8FfP2EawowUBMbcg",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=65_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
with client:
|
2022-10-25 13:08:19 +00:00
|
|
|
client.set_expected_responses(_responses(client, INP1, INP3))
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP3],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
|
2022-03-11 16:30:13 +00:00
|
|
|
# Transaction does not exist on the blockchain, not using assert_tx_matches()
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
|
|
|
== "0100000002e53cf4e3fcd37f8c439286ce636476e1faeebf86bbb2f228a6b78d1b47c8c61601000000b500483045022100d907b9339951c96ef4515ef7aff8b3c28c4c8c5875d7421aa1de9f3a94e3508302205cdc311a6c91dfbb74f1a9a940a994a65dbfb0cf6dedcaaaeee839e0b8fd016d014c69522103dc07026aacb5918dac4e09f9da8290d0ae22161699636c22cace78082116a7792103e70db185fad69c2971f0107a42930e5d82a9ed3a11b922a96fdfc4124b63e54c2103f3fe007a1e34ac76c1a2528e9149f90f9f93739929797afab6a8e18d682fa71053aeffffffff39f756d82082b580b0d69ae8798ff10a981820ccfe1ab149a708a37bc26d94b000000000b500483045022100fdad4a47d15f47cc364fe0cbed11b1ced1f9ef210bc1bd413ec4384f630c63720220752e4f09ea4e5e6623f5ebe89b3983ec6e5702f63f9bce696f10b2d594d23532014c6952210297ad8a5df42f9e362ef37d9a4ddced89d8f7a143690649aa0d0ff049c7daca842103b6321a1194e5cc47b6b7edc3f67a096e6f71ccb72440f84f390b6e98df0ea8ec2103f91460d79e4e463d7d90cb75254bcd62b515a99a950574c721efdc5f711dff3553aeffffffff02005a62020000000017a91466528dd543f94d162c8111d2ec248d25ba9b90948740d2df030000000017a914f1fc92c0aed1712911c70a2e09ac15ff0922652f8700000000"
|
|
|
|
)
|