forked from keepkey/python-keepkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_msg_getaddress.py
More file actions
94 lines (79 loc) · 5 KB
/
Copy pathtest_msg_getaddress.py
File metadata and controls
94 lines (79 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# This file is part of the TREZOR project.
#
# Copyright (C) 2012-2016 Marek Palatinus <[email protected]>
# Copyright (C) 2012-2016 Pavol Rusnak <[email protected]>
#
# 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/>.
#
# The script has been modified for KeepKey Device.
import unittest
import binascii
import common
import keepkeylib.ckd_public as bip32
import keepkeylib.types_pb2 as proto_types
class TestMsgGetaddress(common.KeepKeyTest):
def test_btc(self):
self.setup_mnemonic_nopin_nopassphrase()
self.assertEqual(self.client.get_address('Bitcoin', []), '1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK')
self.assertEqual(self.client.get_address('Bitcoin', [1]), '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb')
self.assertEqual(self.client.get_address('Bitcoin', [0, -1]), '1JVq66pzRBvqaBRFeU9SPVvg3er4ZDgoMs')
self.assertEqual(self.client.get_address('Bitcoin', [-9, 0]), '1F4YdQdL9ZQwvcNTuy5mjyQxXkyCfMcP2P')
self.assertEqual(self.client.get_address('Bitcoin', [0, 9999999]), '1GS8X3yc7ntzwGw9vXwj9wqmBWZkTFewBV')
def test_ltc(self):
self.requires_fullFeature()
self.setup_mnemonic_nopin_nopassphrase()
self.assertEqual(self.client.get_address('Litecoin', []), 'LYtGrdDeqYUQnTkr5sHT2DKZLG7Hqg7HTK')
self.assertEqual(self.client.get_address('Litecoin', [1]), 'LKRGNecThFP3Q6c5fosLVA53Z2hUDb1qnE')
self.assertEqual(self.client.get_address('Litecoin', [0, -1]), 'LcinMK8pVrAtpz7Qpc8jfWzSFsDLgLYfG6')
self.assertEqual(self.client.get_address('Litecoin', [-9, 0]), 'LZHVtcwAEDf1BR4d67551zUijyLUpDF9EX')
self.assertEqual(self.client.get_address('Litecoin', [0, 9999999]), 'Laf5nGHSCT94C5dK6fw2RxuXPiw2ZuRR9S')
def test_grs(self):
self.requires_fullFeature()
self.setup_mnemonic_allallall()
self.assertEqual(self.client.get_address('Groestlcoin', [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 0, 0]), 'Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM')
self.assertEqual(self.client.get_address('Groestlcoin', [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 0]), 'FmRaqvVBRrAp2Umfqx9V1ectZy8gw54QDN')
self.assertEqual(self.client.get_address('Groestlcoin', [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 1]), 'Fmhtxeh7YdCBkyQF7AQG4QnY8y3rJg89di')
def test_tgrs(self):
self.requires_fullFeature()
self.setup_mnemonic_allallall()
self.assertEqual(self.client.get_address('GRS Testnet', [44 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0]), 'mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y')
self.assertEqual(self.client.get_address('GRS Testnet', [44 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0]), 'mm6kLYbGEL1tGe4ZA8xacfgRPdW1LMq8cN')
self.assertEqual(self.client.get_address('GRS Testnet', [44 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 1]), 'mjXZwmEi1z1MzveZrKUAo4DBgbdq6ZhGD6')
def test_ltc_m_address(self):
self.requires_fullFeature()
# generate a 1 of 1 multisig and make sure we get an M address
self.setup_mnemonic_nopin_nopassphrase()
node = bip32.deserialize('xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy')
multisig = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=node, address_n=[])],
signatures=[b''],
m=1,
)
self.assertEqual(self.client.get_address('Litecoin', [], multisig=multisig), 'MBFFn5LyWatMVt2aoXbLkFJHRsnNJcaxba')
def test_tbtc(self):
self.setup_mnemonic_nopin_nopassphrase()
self.assertEqual(self.client.get_address('Testnet', [111, 42]), 'moN6aN6NP1KWgnPSqzrrRPvx2x1UtZJssa')
def test_public_ckd(self):
self.setup_mnemonic_nopin_nopassphrase()
node = self.client.get_public_node([]).node
node_sub1 = self.client.get_public_node([1]).node
node_sub2 = bip32.public_ckd(node, [1])
self.assertEqual(binascii.hexlify(node_sub1.chain_code), binascii.hexlify(node_sub2.chain_code))
self.assertEqual(binascii.hexlify(node_sub1.public_key), binascii.hexlify(node_sub2.public_key))
address1 = self.client.get_address('Bitcoin', [1])
address2 = bip32.get_address(node_sub2, 0)
self.assertEqual(address2, '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb')
self.assertEqual(address1, address2)
if __name__ == '__main__':
unittest.main()