2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2017-12-19 18:24:18 +00:00
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2017-12-19 18:24:18 +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-12-19 18:24:18 +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-12-19 18:24:18 +00:00
|
|
|
|
2019-08-22 16:55:20 +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
|
2020-10-26 15:35:55 +00:00
|
|
|
from trezorlib.exceptions import TrezorFailure
|
2018-04-18 13:53:40 +00:00
|
|
|
from trezorlib.tools import parse_path
|
2018-08-13 16:21:24 +00:00
|
|
|
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_show_segwit(client: Client):
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path("m/49h/1h/0h/1/0"),
|
2021-11-10 21:19:53 +00:00
|
|
|
True,
|
|
|
|
None,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
== "2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path("m/49h/1h/0h/0/0"),
|
2021-11-10 21:19:53 +00:00
|
|
|
False,
|
|
|
|
None,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
== "2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path("m/44h/1h/0h/0/0"),
|
2021-11-10 21:19:53 +00:00
|
|
|
False,
|
|
|
|
None,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
== "2N6UeBoqYEEnybg4cReFYDammpsyDw8R2Mc"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path("m/44h/1h/0h/0/0"),
|
2021-11-10 21:19:53 +00:00
|
|
|
False,
|
|
|
|
None,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDADDRESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
== "mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q"
|
|
|
|
)
|
2019-08-22 16:47:01 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
|
|
|
|
@pytest.mark.altcoin
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_show_segwit_altcoin(client: Client):
|
2021-12-20 14:52:33 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Groestlcoin Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path("m/49h/1h/0h/1/0"),
|
2021-12-20 14:52:33 +00:00
|
|
|
True,
|
|
|
|
None,
|
|
|
|
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
|
|
|
|
)
|
|
|
|
== "2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7"
|
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Groestlcoin Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path("m/49h/1h/0h/0/0"),
|
2021-12-21 15:29:07 +00:00
|
|
|
True,
|
2021-11-10 21:19:53 +00:00
|
|
|
None,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
|
|
|
== "2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e"
|
|
|
|
)
|
2021-12-20 14:52:33 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Groestlcoin Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path("m/44h/1h/0h/0/0"),
|
2021-12-21 15:29:07 +00:00
|
|
|
True,
|
2021-12-20 14:52:33 +00:00
|
|
|
None,
|
|
|
|
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
|
|
|
|
)
|
|
|
|
== "2N6UeBoqYEEnybg4cReFYDammpsyDzLXvCT"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Groestlcoin Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path("m/44h/1h/0h/0/0"),
|
2021-12-21 15:29:07 +00:00
|
|
|
True,
|
2021-12-20 14:52:33 +00:00
|
|
|
None,
|
|
|
|
script_type=messages.InputScriptType.SPENDADDRESS,
|
|
|
|
)
|
|
|
|
== "mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y"
|
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Elements",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path("m/49h/1h/0h/0/0"),
|
2021-12-21 15:29:07 +00:00
|
|
|
True,
|
2021-11-10 21:19:53 +00:00
|
|
|
None,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
|
2019-03-15 13:44:06 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
== "XNW67ZQA9K3AuXPBWvJH4zN2y5QBDTwy2Z"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.multisig
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_show_multisig_3(client: Client):
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes = [
|
|
|
|
btc.get_public_node(
|
2022-01-31 12:25:30 +00:00
|
|
|
client, parse_path(f"m/49h/1h/{i}h"), coin_name="Testnet"
|
2021-11-10 21:19:53 +00:00
|
|
|
).node
|
|
|
|
for i in range(1, 4)
|
|
|
|
]
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig1 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=nodes, address_n=[0, 7], signatures=[b"", b"", b""], m=2
|
|
|
|
)
|
2021-11-10 21:28:11 +00:00
|
|
|
# multisig2 = messages.MultisigRedeemScriptType(
|
|
|
|
# pubkeys=map(lambda n: messages.HDNodePathType(node=bip32.deserialize(n.xpub), address_n=[2, 1]), nodes),
|
2021-11-10 21:19:53 +00:00
|
|
|
# signatures=[b'', b'', b''],
|
|
|
|
# m=2,
|
|
|
|
# )
|
|
|
|
for i in [1, 2, 3]:
|
2019-06-08 14:39:12 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2021-11-10 21:19:53 +00:00
|
|
|
"Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path(f"m/49h/1h/{i}h/0/7"),
|
2019-06-08 14:39:12 +00:00
|
|
|
False,
|
2021-11-10 21:19:53 +00:00
|
|
|
multisig1,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
|
2019-06-08 14:39:12 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
== "2MwuUwUzPG17wiKQpfXmzfxJEoe7RXZDRad"
|
2019-06-08 14:39:12 +00:00
|
|
|
)
|
2017-05-12 22:59:39 +00:00
|
|
|
|
2020-10-26 15:35:55 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
@pytest.mark.multisig
|
|
|
|
@pytest.mark.parametrize("show_display", (True, False))
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_multisig_missing(client: Client, show_display):
|
2021-11-10 21:19:53 +00:00
|
|
|
# Multisig with global suffix specification.
|
|
|
|
# Use account numbers 1, 2 and 3 to create a valid multisig,
|
|
|
|
# but not containing the keys from account 0 used below.
|
|
|
|
nodes = [
|
2022-01-31 12:25:30 +00:00
|
|
|
btc.get_public_node(client, parse_path(f"m/49h/0h/{i}h")).node
|
2021-11-10 21:19:53 +00:00
|
|
|
for i in range(1, 4)
|
|
|
|
]
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig1 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2
|
|
|
|
)
|
2020-10-26 15:35:55 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
# Multisig with per-node suffix specification.
|
|
|
|
node = btc.get_public_node(
|
2022-01-31 12:25:30 +00:00
|
|
|
client, parse_path("m/49h/0h/0h/0"), coin_name="Bitcoin"
|
2021-11-10 21:19:53 +00:00
|
|
|
).node
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig2 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
pubkeys=[
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.HDNodePathType(node=node, address_n=[1]),
|
|
|
|
messages.HDNodePathType(node=node, address_n=[2]),
|
|
|
|
messages.HDNodePathType(node=node, address_n=[3]),
|
2021-11-10 21:19:53 +00:00
|
|
|
],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
2020-10-26 15:35:55 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
for multisig in (multisig1, multisig2):
|
|
|
|
with pytest.raises(TrezorFailure):
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path("m/49h/0h/0h/0/0"),
|
2021-11-10 21:19:53 +00:00
|
|
|
show_display=show_display,
|
|
|
|
multisig=multisig,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|