-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtests.py
53 lines (45 loc) · 2.58 KB
/
tests.py
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
from binascii import unhexlify
import bip32
import bip32utils.Base58
import pytest
DATA = '''
m/44'/60'/0'/0/0 bb2Ca357e5780141f34500D43E492bEe15531211 02eed2a172ed2c25ffa74d10db6b37987b508c7129113297cba1be7466191211b1 17b95359ef2a332fa917507b5cafa06c3998d0451c7916fded9c923a7f8b866b
m/44'/60'/0'/0/1 Ae9a6d7E0a453344d6778081D34644E1aCE82E37 023eacf3d654494ea7155504020c2cbf6ea98f617780626e1cf86bca5602a064a4 21f188c09a4bbf90904cdaeb8d024baa4b8be0a2980cfd4d7c8648e55e304c3f
m/44'/60'/0'/0/2 E197D3d79e85644f657F60CD6912F30A365b76B8 027f9df9e79e3ffa0c48bda52a3d5874bdee9ebe5b6f7631e3d4dd21cf004e6c9d e785446f88f0c87c1b06fe0731f7ac5759b29f188019960546e65d9cbaccde00
m/44'/0'/0'/0/0 18bkaWvgTST8vJb2LgdBueo6sP4eoF99Ve 02c1aeef761a85c7cb0a5f7a75f7fa77fec505a88281d6000544a15223876c2865 L2t4wu4R5FZv6jEkztwjDwZRsuE7WFtiX7upkiq6nkFPcemdaZdk
m/44'/0'/0'/0/1 1LKKSR2Giwm9FZpZn4LDJo8pFcCsBKpiSC 02d8717f7e7cdc3669b983b707d700121f69b6063cf437039334a5b3babb2b3e3b KwRjx5s8UPKYixtDAuYxWNxNYzZ7M6xwKMq1Dqu3ZAo8c1VEPSJW
m/44'/0'/0'/0/2 1BQannPT4K1AbH33qy4YYZpN8gBkBhFxbb 0395305c01697c8a2ffd17d4df5704d887fc66e00f5ddc51d5db7c32f087491873 Ky3JbpRUcTgyp5q1SDZT9hvkU1VXKSzUwr1wK5nc1YYrudYWqXaQ
'''
DATA = [l.split() for l in DATA.splitlines() if l.strip()]
masterkey = bip32.HDKey.from_mnemonic(
'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when')
@pytest.mark.parametrize('bip32_path,native_address,pubkey,privkey', DATA)
def test(bip32_path, native_address, pubkey, privkey):
try:
privkey = unhexlify(privkey)
except:
privkey = bip32utils.Base58.check_decode(privkey)[1:-1]
pubkey = unhexlify(pubkey)
derived = masterkey.derive_path(bip32_path)
assert derived.bip32_path == bip32_path
assert derived.bip44_address.lower() == native_address.lower()
if "60'" in bip32_path:
assert derived.eth_address.lower() == native_address.lower()
else:
assert derived.btc_address == native_address
assert derived.public_key_bytes == pubkey
assert derived.private_key_bytes == privkey
def test_iter_children():
assert list(masterkey.iter_children(0, 2)) == list(
enumerate([
masterkey.derive_single(0),
masterkey.derive_single(1),
masterkey.derive_single(2)
]))
assert list(masterkey.iter_children(
bip32.hardened(0), bip32.hardened(2))) == list(
enumerate([
masterkey.derive_single(0 | bip32.BIP32_HARDEN),
masterkey.derive_single(1 | bip32.BIP32_HARDEN),
masterkey.derive_single(2 | bip32.BIP32_HARDEN)
], bip32.BIP32_HARDEN))