1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-11 18:20:24 +00:00
trezor-firmware/trezorlib/tests/device_tests/test_msg_getaddress.py

89 lines
4.4 KiB
Python
Raw Normal View History

2017-01-03 18:40:05 +00:00
# This file is part of the TREZOR project.
#
# Copyright (C) 2012-2016 Marek Palatinus <slush@satoshilabs.com>
# Copyright (C) 2012-2016 Pavol Rusnak <stick@satoshilabs.com>
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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 GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
import pytest
from .common import TrezorTest
from ..support import ckd_public as bip32
from trezorlib import messages as proto
2018-04-18 13:53:40 +00:00
from trezorlib.tools import parse_path
2017-06-23 19:31:42 +00:00
class TestMsgGetaddress(TrezorTest):
2014-02-17 00:54:54 +00:00
def test_btc(self):
self.setup_mnemonic_nopin_nopassphrase()
assert self.client.get_address('Bitcoin', []) == '1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK'
assert self.client.get_address('Bitcoin', [1]) == '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb'
assert self.client.get_address('Bitcoin', [0, -1]) == '1JVq66pzRBvqaBRFeU9SPVvg3er4ZDgoMs'
assert self.client.get_address('Bitcoin', [-9, 0]) == '1F4YdQdL9ZQwvcNTuy5mjyQxXkyCfMcP2P'
assert self.client.get_address('Bitcoin', [0, 9999999]) == '1GS8X3yc7ntzwGw9vXwj9wqmBWZkTFewBV'
def test_ltc(self):
2014-02-17 00:54:54 +00:00
self.setup_mnemonic_nopin_nopassphrase()
assert self.client.get_address('Litecoin', []) == 'LYtGrdDeqYUQnTkr5sHT2DKZLG7Hqg7HTK'
assert self.client.get_address('Litecoin', [1]) == 'LKRGNecThFP3Q6c5fosLVA53Z2hUDb1qnE'
assert self.client.get_address('Litecoin', [0, -1]) == 'LcinMK8pVrAtpz7Qpc8jfWzSFsDLgLYfG6'
assert self.client.get_address('Litecoin', [-9, 0]) == 'LZHVtcwAEDf1BR4d67551zUijyLUpDF9EX'
assert self.client.get_address('Litecoin', [0, 9999999]) == 'Laf5nGHSCT94C5dK6fw2RxuXPiw2ZuRR9S'
def test_tbtc(self):
2014-02-17 00:54:54 +00:00
self.setup_mnemonic_nopin_nopassphrase()
assert self.client.get_address('Testnet', [111, 42]) == 'moN6aN6NP1KWgnPSqzrrRPvx2x1UtZJssa'
2014-01-14 13:29:18 +00:00
2018-04-05 15:03:36 +00:00
@pytest.mark.skip_t2
2017-08-12 19:10:12 +00:00
def test_bch(self):
self.setup_mnemonic_allallall()
2018-04-18 13:53:40 +00:00
assert self.client.get_address('Bcash', parse_path("44'/145'/0'/0/0")) == 'bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv'
assert self.client.get_address('Bcash', parse_path("44'/145'/0'/0/1")) == 'bitcoincash:qr23ajjfd9wd73l87j642puf8cad20lfmqdgwvpat4'
assert self.client.get_address('Bcash', parse_path("44'/145'/0'/1/0")) == 'bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw'
2017-08-12 19:10:12 +00:00
2018-04-05 15:03:36 +00:00
@pytest.mark.skip_t2
2017-08-12 19:10:12 +00:00
def test_bch_multisig(self):
self.setup_mnemonic_allallall()
2017-08-13 16:01:43 +00:00
xpubs = []
2018-04-18 13:53:40 +00:00
for n in map(lambda index: self.client.get_public_node(parse_path("44'/145'/" + str(index) + "'")), range(1, 4)):
2017-08-12 19:10:12 +00:00
xpubs.append(n.xpub)
2017-08-13 16:01:43 +00:00
def getmultisig(chain, nr, signatures=[b'', b'', b''], xpubs=xpubs):
return proto.MultisigRedeemScriptType(
pubkeys=list(map(lambda xpub: proto.HDNodePathType(node=bip32.deserialize(xpub), address_n=[chain, nr]), xpubs)),
2017-08-12 19:10:12 +00:00
signatures=signatures,
m=2,
)
2017-08-13 16:01:43 +00:00
for nr in range(1, 4):
2018-04-18 13:53:40 +00:00
assert self.client.get_address('Bcash', parse_path("44'/145'/" + str(nr) + "'/0/0"), show_display=(nr == 1), multisig=getmultisig(0, 0)) == 'bitcoincash:pqguz4nqq64jhr5v3kvpq4dsjrkda75hwy86gq0qzw'
assert self.client.get_address('Bcash', parse_path("44'/145'/" + str(nr) + "'/1/0"), show_display=(nr == 1), multisig=getmultisig(1, 0)) == 'bitcoincash:pp6kcpkhua7789g2vyj0qfkcux3yvje7euhyhltn0a'
2017-08-12 19:10:12 +00:00
2014-01-14 13:29:18 +00:00
def test_public_ckd(self):
2014-02-17 00:54:54 +00:00
self.setup_mnemonic_nopin_nopassphrase()
2014-01-14 13:29:18 +00:00
node = self.client.get_public_node([]).node
node_sub1 = self.client.get_public_node([1]).node
2014-01-14 13:29:18 +00:00
node_sub2 = bip32.public_ckd(node, [1])
assert node_sub1.chain_code == node_sub2.chain_code
assert node_sub1.public_key == node_sub2.public_key
2014-01-14 13:29:18 +00:00
address1 = self.client.get_address('Bitcoin', [1])
address2 = bip32.get_address(node_sub2, 0)
assert address2 == '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb'
assert address1 == address2