added tests for create master & pub keys for HD Wallet(BIP0032)

This commit is contained in:
Alexey Karyabkin 2018-06-04 19:29:59 +04:00
parent f2e4a4c858
commit 1a34eaa43c
3 changed files with 57 additions and 1 deletions

25
tests/bip0032_fixtures.py Normal file
View File

@ -0,0 +1,25 @@
import pytest
@pytest.fixture
def fail_key1():
return b'\x00\x00\x00\x00'
@pytest.fixture
def fail_key2():
return b'\x97\x8bq\xc6\xd8\xfew\xe5\xfa\xad\xdc\xc6\xc5\x91\xbd\xfb'
@pytest.fixture
def good_key():
return b'B\xa8\xe9v>y\xe2\x82\x10\x80\xc2\xa91\x10E\xe0XJ\xe6\xc7\x18\x9eE~\xa0^\xd1\x820\xe7\x18\x0c'
@pytest.fixture
def master_key_hdwallet():
return dict(version=b'\x04\x88\xad\xe4',
key=b"Y\x9e'\xe00or'\xacD\x9c(l\x99\x0fxB\x03\xbd/]|+\xfd\xe89K!\x93\x0bN\x9b",
chain_code=b'B\xa8\xe9v>y\xe2\x82\x10\x80\xc2\xa91\x10E\xe0XJ\xe6\xc7\x18\x9eE~\xa0^\xd1\x820\xe7\x18\x0c',
is_private=True,
depth=0,
child=0)

View File

@ -2,5 +2,5 @@
import pytest
pytest_plugins = ['bip0039_fixtures']
pytest_plugins = ['bip0032_fixtures', 'bip0039_fixtures']

31
tests/test_bip0032.py Normal file
View File

@ -0,0 +1,31 @@
import os
import random
import hashlib
import hmac
from binascii import hexlify, unhexlify
from pybtc.hdwallet import *
def test_create_master_key(mnemonic_256):
passphrase = ' '.join(mnemonic_256)
seed = create_seed(passphrase, 'P@ssw0rd')
assert seed is not None
assert len(seed) == 64
master_key = create_master_key_hdwallet(seed)
assert master_key is not None
assert type(master_key) is dict
assert master_key['is_private']
def test_create_public_key(master_key_hdwallet):
public_key = create_public_key_hdwallet(master_key_hdwallet['key'])
assert public_key is not None
def test_validate_keys(fail_key1, fail_key2, good_key):
assert not validate_keys(fail_key1)
assert not validate_keys(fail_key2)
assert validate_keys(good_key)