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
|
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
from trezorlib import btc, messages as proto
|
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
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2017-05-12 22:59:39 +00:00
|
|
|
|
2019-09-11 12:29:39 +00:00
|
|
|
class TestMsgGetaddressSegwitNative:
|
2019-08-27 14:58:59 +00:00
|
|
|
def test_show_segwit(self, client):
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2018-08-13 16:21:24 +00:00
|
|
|
"Testnet",
|
|
|
|
parse_path("49'/1'/0'/0/0"),
|
|
|
|
True,
|
|
|
|
None,
|
|
|
|
script_type=proto.InputScriptType.SPENDWITNESS,
|
|
|
|
)
|
|
|
|
== "tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2018-08-13 16:21:24 +00:00
|
|
|
"Testnet",
|
|
|
|
parse_path("49'/1'/0'/1/0"),
|
|
|
|
False,
|
|
|
|
None,
|
|
|
|
script_type=proto.InputScriptType.SPENDWITNESS,
|
|
|
|
)
|
|
|
|
== "tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2018-08-13 16:21:24 +00:00
|
|
|
"Testnet",
|
|
|
|
parse_path("44'/1'/0'/0/0"),
|
|
|
|
False,
|
|
|
|
None,
|
|
|
|
script_type=proto.InputScriptType.SPENDWITNESS,
|
|
|
|
)
|
|
|
|
== "tb1q54un3q39sf7e7tlfq99d6ezys7qgc62a6rxllc"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2018-08-13 16:21:24 +00:00
|
|
|
"Testnet",
|
|
|
|
parse_path("44'/1'/0'/0/0"),
|
|
|
|
False,
|
|
|
|
None,
|
|
|
|
script_type=proto.InputScriptType.SPENDADDRESS,
|
|
|
|
)
|
|
|
|
== "mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q"
|
|
|
|
)
|
2019-08-22 16:47:01 +00:00
|
|
|
|
|
|
|
@pytest.mark.altcoin
|
2019-08-27 14:58:59 +00:00
|
|
|
def test_show_segwit_altcoin(self, client):
|
2019-03-15 13:44:06 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2019-03-15 13:44:06 +00:00
|
|
|
"Groestlcoin",
|
|
|
|
parse_path("84'/17'/0'/0/0"),
|
|
|
|
False,
|
|
|
|
None,
|
|
|
|
script_type=proto.InputScriptType.SPENDWITNESS,
|
|
|
|
)
|
|
|
|
== "grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne"
|
|
|
|
)
|
2019-06-08 14:39:12 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2019-06-08 14:39:12 +00:00
|
|
|
"Elements",
|
|
|
|
parse_path("84'/1'/0'/0/0"),
|
|
|
|
False,
|
|
|
|
None,
|
|
|
|
script_type=proto.InputScriptType.SPENDWITNESS,
|
|
|
|
)
|
|
|
|
== "ert1qkvwu9g3k2pdxewfqr7syz89r3gj557l3xp9k2v"
|
|
|
|
)
|
2017-05-12 22:59:39 +00:00
|
|
|
|
2019-10-22 14:32:00 +00:00
|
|
|
@pytest.mark.multisig
|
2019-08-27 14:58:59 +00:00
|
|
|
def test_show_multisig_3(self, client):
|
2018-08-13 16:21:24 +00:00
|
|
|
nodes = [
|
2020-05-13 09:36:03 +00:00
|
|
|
btc.get_public_node(
|
|
|
|
client, parse_path("84'/1'/%d'" % index), coin_name="Testnet"
|
|
|
|
).node
|
2018-08-13 16:21:24 +00:00
|
|
|
for index in range(1, 4)
|
|
|
|
]
|
2017-12-12 15:40:11 +00:00
|
|
|
multisig1 = proto.MultisigRedeemScriptType(
|
2020-10-26 12:32:03 +00:00
|
|
|
nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2
|
2017-05-12 22:59:39 +00:00
|
|
|
)
|
2017-12-12 15:40:11 +00:00
|
|
|
multisig2 = proto.MultisigRedeemScriptType(
|
2020-10-26 12:32:03 +00:00
|
|
|
nodes=nodes, address_n=[0, 1], signatures=[b"", b"", b""], m=2
|
2017-05-12 22:59:39 +00:00
|
|
|
)
|
|
|
|
for i in [1, 2, 3]:
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2018-08-13 16:21:24 +00:00
|
|
|
"Testnet",
|
2020-10-26 12:32:03 +00:00
|
|
|
parse_path("84'/1'/%d'/0/1" % i),
|
2018-08-13 16:21:24 +00:00
|
|
|
False,
|
|
|
|
multisig2,
|
|
|
|
script_type=proto.InputScriptType.SPENDWITNESS,
|
|
|
|
)
|
2020-10-26 12:32:03 +00:00
|
|
|
== "tb1qauuv4e2pwjkr4ws5f8p20hu562jlqpe5h74whxqrwf7pufsgzcms9y8set"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2018-08-13 16:21:24 +00:00
|
|
|
"Testnet",
|
2020-10-26 12:32:03 +00:00
|
|
|
parse_path("84'/1'/%d'/0/0" % i),
|
2018-08-13 16:21:24 +00:00
|
|
|
False,
|
|
|
|
multisig1,
|
|
|
|
script_type=proto.InputScriptType.SPENDWITNESS,
|
|
|
|
)
|
2020-10-26 12:32:03 +00:00
|
|
|
== "tb1qgvn67p4twmpqhs8c39tukmu9geamtf7x0z3flwf9rrw4ff3h6d2qt0czq3"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2020-10-26 15:35:55 +00:00
|
|
|
|
|
|
|
@pytest.mark.multisig
|
|
|
|
@pytest.mark.parametrize("show_display", (True, False))
|
|
|
|
def test_multisig_missing(self, client, 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 = [
|
|
|
|
btc.get_public_node(client, parse_path("84'/0'/%d'" % i)).node
|
|
|
|
for i in range(1, 4)
|
|
|
|
]
|
|
|
|
multisig1 = proto.MultisigRedeemScriptType(
|
|
|
|
nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2
|
|
|
|
)
|
|
|
|
|
|
|
|
# Multisig with per-node suffix specification.
|
|
|
|
node = btc.get_public_node(
|
|
|
|
client, parse_path("84h/0h/0h/0"), coin_name="Bitcoin"
|
|
|
|
).node
|
|
|
|
multisig2 = proto.MultisigRedeemScriptType(
|
|
|
|
pubkeys=[
|
|
|
|
proto.HDNodePathType(node=node, address_n=[1]),
|
|
|
|
proto.HDNodePathType(node=node, address_n=[2]),
|
|
|
|
proto.HDNodePathType(node=node, address_n=[3]),
|
|
|
|
],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
|
|
|
for multisig in (multisig1, multisig2):
|
|
|
|
with pytest.raises(TrezorFailure):
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
parse_path("84'/0'/0'/0/0"),
|
|
|
|
show_display=show_display,
|
|
|
|
multisig=multisig,
|
|
|
|
script_type=proto.InputScriptType.SPENDWITNESS,
|
|
|
|
)
|