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
|
|
|
|
|
2020-03-04 14:12:30 +00:00
|
|
|
from trezorlib import btc, messages, tools
|
2018-08-13 16:21:24 +00:00
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
VECTORS = ( # path, script_type, address
|
|
|
|
(
|
|
|
|
"m/44h/0h/12h/0/0",
|
|
|
|
messages.InputScriptType.SPENDADDRESS,
|
|
|
|
"1FM6Kz3oT3GoGv65jNpU8AFFun8nHAXrPk",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"m/49h/0h/12h/0/0",
|
|
|
|
messages.InputScriptType.SPENDP2SHWITNESS,
|
|
|
|
"3HfEUkuwmtZ87XzowkiD5nMp5Q3hqKXZ2i",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"m/84h/0h/12h/0/0",
|
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
|
|
|
"bc1qduvap743hcl7twn8u6f9l0u8y7x83965xy0raj",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("path, script_type, address", VECTORS)
|
|
|
|
def test_show(client, path, script_type, address):
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
tools.parse_path(path),
|
|
|
|
script_type=script_type,
|
|
|
|
show_display=True,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2020-05-13 09:36:03 +00:00
|
|
|
== address
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.multisig
|
|
|
|
def test_show_multisig_3(client):
|
|
|
|
node = btc.get_public_node(
|
2020-10-26 12:32:03 +00:00
|
|
|
client, tools.parse_path("45h/0/0"), coin_name="Bitcoin"
|
2020-05-13 09:36:03 +00:00
|
|
|
).node
|
|
|
|
multisig = 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 i in [1, 2, 3]:
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
2020-05-13 09:36:03 +00:00
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
2020-10-26 12:32:03 +00:00
|
|
|
tools.parse_path(f"45h/0/0/{i}"),
|
2020-05-13 09:36:03 +00:00
|
|
|
show_display=True,
|
|
|
|
multisig=multisig,
|
|
|
|
)
|
2020-10-26 12:32:03 +00:00
|
|
|
== "35Q3tgZZfr9GhVpaqz7fbDK8WXV1V1KxfD"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-10 14:42:38 +00:00
|
|
|
|
2014-12-10 17:03:54 +00:00
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
@pytest.mark.skip_t1
|
|
|
|
@pytest.mark.multisig
|
|
|
|
def test_show_multisig_xpubs(client):
|
|
|
|
nodes = [
|
|
|
|
btc.get_public_node(
|
2020-10-26 12:32:03 +00:00
|
|
|
client, tools.parse_path(f"48h/0h/{i}h/0h"), coin_name="Bitcoin"
|
2020-05-13 09:36:03 +00:00
|
|
|
)
|
|
|
|
for i in range(3)
|
|
|
|
]
|
|
|
|
multisig = messages.MultisigRedeemScriptType(
|
|
|
|
nodes=[n.node for n in nodes],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
address_n=[0, 0],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
|
|
|
xpubs = [[n.xpub[i * 16 : (i + 1) * 16] for i in range(5)] for n in nodes]
|
|
|
|
|
|
|
|
for i in range(3):
|
|
|
|
|
|
|
|
def input_flow():
|
|
|
|
yield # show address
|
|
|
|
assert client.debug.wait_layout().lines == [
|
|
|
|
"Multisig 2 of 3",
|
2020-10-26 12:32:03 +00:00
|
|
|
"33TU5DyVi2kFSGQUf",
|
|
|
|
"mZxNHgPDPqruwdesY",
|
2020-05-13 09:36:03 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
client.debug.press_no()
|
|
|
|
yield # show QR code
|
|
|
|
assert client.debug.wait_layout().text.startswith("Qr")
|
|
|
|
|
|
|
|
client.debug.press_no()
|
|
|
|
yield # show XPUB#1
|
|
|
|
lines = client.debug.wait_layout().lines
|
|
|
|
assert lines[0] == "XPUB #1 " + ("(yours)" if i == 0 else "(others)")
|
|
|
|
assert lines[1:] == xpubs[0]
|
|
|
|
# just for UI test
|
|
|
|
client.debug.swipe_up()
|
2020-05-25 10:50:30 +00:00
|
|
|
client.debug.wait_layout()
|
2020-05-13 09:36:03 +00:00
|
|
|
|
|
|
|
client.debug.press_no()
|
|
|
|
yield # show XPUB#2
|
|
|
|
lines = client.debug.wait_layout().lines
|
|
|
|
assert lines[0] == "XPUB #2 " + ("(yours)" if i == 1 else "(others)")
|
|
|
|
assert lines[1:] == xpubs[1]
|
|
|
|
# just for UI test
|
|
|
|
client.debug.swipe_up()
|
2020-05-25 10:50:30 +00:00
|
|
|
client.debug.wait_layout()
|
2020-05-13 09:36:03 +00:00
|
|
|
|
|
|
|
client.debug.press_no()
|
|
|
|
yield # show XPUB#3
|
|
|
|
lines = client.debug.wait_layout().lines
|
|
|
|
assert lines[0] == "XPUB #3 " + ("(yours)" if i == 2 else "(others)")
|
|
|
|
assert lines[1:] == xpubs[2]
|
|
|
|
# just for UI test
|
|
|
|
client.debug.swipe_up()
|
2020-05-25 10:50:30 +00:00
|
|
|
client.debug.wait_layout()
|
2020-05-13 09:36:03 +00:00
|
|
|
|
|
|
|
client.debug.press_yes()
|
|
|
|
|
|
|
|
with client:
|
2020-07-28 12:40:54 +00:00
|
|
|
client.watch_layout()
|
2020-05-13 09:36:03 +00:00
|
|
|
client.set_input_flow(input_flow)
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
2020-10-26 12:32:03 +00:00
|
|
|
tools.parse_path(f"48h/0h/{i}h/0h/0/0"),
|
2020-05-13 09:36:03 +00:00
|
|
|
show_display=True,
|
|
|
|
multisig=multisig,
|
|
|
|
script_type=messages.InputScriptType.SPENDMULTISIG,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-10 18:53:24 +00:00
|
|
|
|
2020-02-20 11:47:29 +00:00
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
@pytest.mark.multisig
|
|
|
|
def test_show_multisig_15(client):
|
|
|
|
node = btc.get_public_node(
|
2020-10-26 12:32:03 +00:00
|
|
|
client, tools.parse_path("45h/0/0"), coin_name="Bitcoin"
|
2020-05-13 09:36:03 +00:00
|
|
|
).node
|
2014-12-12 21:31:40 +00:00
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
pubs = [messages.HDNodePathType(node=node, address_n=[x]) for x in range(15)]
|
2014-12-12 21:31:40 +00:00
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
multisig = messages.MultisigRedeemScriptType(
|
|
|
|
pubkeys=pubs, signatures=[b""] * 15, m=15
|
|
|
|
)
|
2014-12-10 18:53:24 +00:00
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
for i in range(15):
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
2020-10-26 12:32:03 +00:00
|
|
|
tools.parse_path(f"45h/0/0/{i}"),
|
2020-05-13 09:36:03 +00:00
|
|
|
show_display=True,
|
|
|
|
multisig=multisig,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2020-10-26 12:32:03 +00:00
|
|
|
== "3GG78bp1hA3mu9xv1vZLXiENmeabmi7WKQ"
|
2020-05-13 09:36:03 +00:00
|
|
|
)
|