1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-30 03:18:20 +00:00
trezor-firmware/tests/device_tests/bitcoin/test_getaddress_segwit.py

207 lines
6.4 KiB
Python
Raw Normal View History

# This file is part of the Trezor project.
#
2019-05-29 16:44:09 +00:00
# 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
2024-11-15 16:31:22 +00:00
from trezorlib.debuglink import SessionDebugWrapper as Session
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
from ...common import is_core
from ...input_flows import InputFlowConfirmAllWarnings
2017-06-23 19:31:42 +00:00
2024-11-15 16:31:22 +00:00
def test_show_segwit(session: Session):
assert (
btc.get_address(
2024-11-15 16:31:22 +00:00
session,
"Testnet",
parse_path("m/49h/1h/0h/1/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
2018-08-13 16:21:24 +00:00
)
== "2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX"
)
assert (
btc.get_address(
2024-11-15 16:31:22 +00:00
session,
"Testnet",
parse_path("m/49h/1h/0h/0/0"),
False,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
2018-08-13 16:21:24 +00:00
)
== "2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp"
)
assert (
btc.get_address(
2024-11-15 16:31:22 +00:00
session,
"Testnet",
parse_path("m/44h/1h/0h/0/0"),
False,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
2018-08-13 16:21:24 +00:00
)
== "2N6UeBoqYEEnybg4cReFYDammpsyDw8R2Mc"
)
assert (
btc.get_address(
2024-11-15 16:31:22 +00:00
session,
"Testnet",
parse_path("m/44h/1h/0h/0/0"),
False,
None,
script_type=messages.InputScriptType.SPENDADDRESS,
2018-08-13 16:21:24 +00:00
)
== "mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q"
)
@pytest.mark.altcoin
2024-11-15 16:31:22 +00:00
def test_show_segwit_altcoin(session: Session):
with session.client as client:
if is_core(session):
IF = InputFlowConfirmAllWarnings(client)
client.set_input_flow(IF.get())
assert (
btc.get_address(
2024-11-15 16:31:22 +00:00
session,
"Groestlcoin Testnet",
parse_path("m/49h/1h/0h/1/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
== "2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7"
)
assert (
btc.get_address(
2024-11-15 16:31:22 +00:00
session,
"Groestlcoin Testnet",
parse_path("m/49h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
== "2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e"
)
assert (
btc.get_address(
2024-11-15 16:31:22 +00:00
session,
"Groestlcoin Testnet",
parse_path("m/44h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
== "2N6UeBoqYEEnybg4cReFYDammpsyDzLXvCT"
)
assert (
btc.get_address(
2024-11-15 16:31:22 +00:00
session,
"Groestlcoin Testnet",
parse_path("m/44h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDADDRESS,
)
== "mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y"
)
assert (
btc.get_address(
2024-11-15 16:31:22 +00:00
session,
"Elements",
parse_path("m/49h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
== "XNW67ZQA9K3AuXPBWvJH4zN2y5QBDTwy2Z"
2019-03-15 13:44:06 +00:00
)
@pytest.mark.multisig
2024-11-15 16:31:22 +00:00
def test_show_multisig_3(session: Session):
nodes = [
btc.get_public_node(
2024-11-15 16:31:22 +00:00
session, parse_path(f"m/49h/1h/{i}h"), coin_name="Testnet"
).node
for i in range(1, 4)
]
multisig1 = messages.MultisigRedeemScriptType(
nodes=nodes, address_n=[0, 7], signatures=[b"", b"", b""], m=2
)
# multisig2 = messages.MultisigRedeemScriptType(
# pubkeys=map(lambda n: messages.HDNodePathType(node=bip32.deserialize(n.xpub), address_n=[2, 1]), nodes),
# signatures=[b'', b'', b''],
# m=2,
# )
for i in [1, 2, 3]:
assert (
btc.get_address(
2024-11-15 16:31:22 +00:00
session,
"Testnet",
parse_path(f"m/49h/1h/{i}h/0/7"),
False,
multisig1,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
== "2MwuUwUzPG17wiKQpfXmzfxJEoe7RXZDRad"
)
@pytest.mark.multisig
@pytest.mark.parametrize("show_display", (True, False))
2024-11-15 16:31:22 +00:00
def test_multisig_missing(session: Session, show_display):
# 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 = [
2024-11-15 16:31:22 +00:00
btc.get_public_node(session, parse_path(f"m/49h/0h/{i}h")).node
for i in range(1, 4)
]
multisig1 = messages.MultisigRedeemScriptType(
nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2
)
# Multisig with per-node suffix specification.
node = btc.get_public_node(
2024-11-15 16:31:22 +00:00
session, parse_path("m/49h/0h/0h/0"), coin_name="Bitcoin"
).node
multisig2 = messages.MultisigRedeemScriptType(
pubkeys=[
messages.HDNodePathType(node=node, address_n=[1]),
messages.HDNodePathType(node=node, address_n=[2]),
messages.HDNodePathType(node=node, address_n=[3]),
],
signatures=[b"", b"", b""],
m=2,
)
for multisig in (multisig1, multisig2):
with pytest.raises(TrezorFailure):
btc.get_address(
2024-11-15 16:31:22 +00:00
session,
"Bitcoin",
parse_path("m/49h/0h/0h/0/0"),
show_display=show_display,
multisig=multisig,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)