2018-04-30 09:04:52 +02:00
|
|
|
from twisted.trial import unittest
|
|
|
|
|
2018-05-26 05:26:07 +02:00
|
|
|
from lbrynet.wallet import LBC
|
|
|
|
from lbrynet.wallet.manager import LbryWalletManager
|
|
|
|
from torba.wallet import Account
|
2018-04-30 09:04:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestAccount(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
2018-05-26 05:26:07 +02:00
|
|
|
ledger = LbryWalletManager().get_or_create_ledger(LBC.get_id())
|
|
|
|
self.coin = LBC(ledger)
|
2018-04-30 09:04:52 +02:00
|
|
|
|
|
|
|
def test_generate_account(self):
|
2018-05-26 05:26:07 +02:00
|
|
|
account = Account.generate(self.coin, u'lbryum')
|
2018-04-30 09:04:52 +02:00
|
|
|
self.assertEqual(account.coin, self.coin)
|
|
|
|
self.assertIsNotNone(account.seed)
|
|
|
|
self.assertEqual(account.public_key.coin, self.coin)
|
|
|
|
self.assertEqual(account.private_key.public_key, account.public_key)
|
|
|
|
|
|
|
|
self.assertEqual(len(account.receiving_keys.child_keys), 0)
|
|
|
|
self.assertEqual(len(account.receiving_keys.addresses), 0)
|
|
|
|
self.assertEqual(len(account.change_keys.child_keys), 0)
|
|
|
|
self.assertEqual(len(account.change_keys.addresses), 0)
|
|
|
|
|
|
|
|
account.ensure_enough_addresses()
|
|
|
|
self.assertEqual(len(account.receiving_keys.child_keys), 20)
|
|
|
|
self.assertEqual(len(account.receiving_keys.addresses), 20)
|
|
|
|
self.assertEqual(len(account.change_keys.child_keys), 6)
|
|
|
|
self.assertEqual(len(account.change_keys.addresses), 6)
|
|
|
|
|
|
|
|
def test_generate_account_from_seed(self):
|
|
|
|
account = Account.from_seed(
|
|
|
|
self.coin,
|
2018-05-26 05:26:07 +02:00
|
|
|
u"carbon smart garage balance margin twelve chest sword toast envelope bottom stomach ab"
|
|
|
|
u"sent",
|
|
|
|
u"lbryum"
|
2018-04-30 09:04:52 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
account.private_key.extended_key_string(),
|
2018-06-12 17:53:29 +02:00
|
|
|
b'LprvXPsFZUGgrX1X9HiyxABZSf6hWJK7kHv4zGZRyyiHbBq5Wu94cE1DMvttnpLYReTPNW4eYwX9dWMvTz3PrB'
|
|
|
|
b'wwbRafEeA1ZXL69U2egM4QJdq'
|
2018-04-30 09:04:52 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
account.public_key.extended_key_string(),
|
2018-06-12 17:53:29 +02:00
|
|
|
b'Lpub2hkYkGHXktBhLpwUhKKogyuJ1M7Gt9EkjFTVKyDqZiZpWdhLuCoT1eKDfXfysMFfG4SzfXXcA2SsHzrjHK'
|
|
|
|
b'Ea5aoCNRBAhjT5NPLV6hXtvEi'
|
2018-04-30 09:04:52 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
account.receiving_keys.generate_next_address(),
|
2018-06-12 17:53:29 +02:00
|
|
|
b'bCqJrLHdoiRqEZ1whFZ3WHNb33bP34SuGx'
|
2018-04-30 09:04:52 +02:00
|
|
|
)
|
2018-06-12 17:53:29 +02:00
|
|
|
private_key = account.get_private_key_for_address(b'bCqJrLHdoiRqEZ1whFZ3WHNb33bP34SuGx')
|
2018-04-30 09:04:52 +02:00
|
|
|
self.assertEqual(
|
|
|
|
private_key.extended_key_string(),
|
2018-06-12 17:53:29 +02:00
|
|
|
b'LprvXTnmVLXGKvRGo2ihBE6LJ771G3VVpAx2zhTJvjnx5P3h6iZ4VJX8PvwTcgzJZ1hqXX61Wpn4pQoP6n2wgp'
|
|
|
|
b'S8xjzCM6H2uGzCXuAMy5H9vtA'
|
2018-04-30 09:04:52 +02:00
|
|
|
)
|
2018-06-12 17:53:29 +02:00
|
|
|
self.assertIsNone(account.get_private_key_for_address(b'BcQjRlhDOIrQez1WHfz3whnB33Bp34sUgX'))
|
2018-04-30 09:04:52 +02:00
|
|
|
|
|
|
|
def test_load_and_save_account(self):
|
|
|
|
account_data = {
|
|
|
|
'seed':
|
|
|
|
"carbon smart garage balance margin twelve chest sword toast envelope bottom stomac"
|
|
|
|
"h absent",
|
|
|
|
'encrypted': False,
|
|
|
|
'private_key':
|
|
|
|
'LprvXPsFZUGgrX1X9HiyxABZSf6hWJK7kHv4zGZRyyiHbBq5Wu94cE1DMvttnpLYReTPNW4eYwX9dWMvTz3PrB'
|
|
|
|
'wwbRafEeA1ZXL69U2egM4QJdq',
|
|
|
|
'public_key':
|
|
|
|
'Lpub2hkYkGHXktBhLpwUhKKogyuJ1M7Gt9EkjFTVKyDqZiZpWdhLuCoT1eKDfXfysMFfG4SzfXXcA2SsHzrjHK'
|
|
|
|
'Ea5aoCNRBAhjT5NPLV6hXtvEi',
|
|
|
|
'receiving_gap': 10,
|
|
|
|
'receiving_keys': [
|
|
|
|
'02c68e2d1cf85404c86244ffa279f4c5cd00331e996d30a86d6e46480e3a9220f4',
|
|
|
|
'03c5a997d0549875d23b8e4bbc7b4d316d962587483f3a2e62ddd90a21043c4941'
|
|
|
|
],
|
|
|
|
'change_gap': 10,
|
|
|
|
'change_keys': [
|
|
|
|
'021460e8d728eee325d0d43128572b2e2bacdc027e420451df100cf9f2154ea5ab'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
account = Account.from_dict(self.coin, account_data)
|
|
|
|
|
|
|
|
self.assertEqual(len(account.receiving_keys.addresses), 2)
|
|
|
|
self.assertEqual(
|
|
|
|
account.receiving_keys.addresses[0],
|
2018-06-12 17:53:29 +02:00
|
|
|
b'bCqJrLHdoiRqEZ1whFZ3WHNb33bP34SuGx'
|
2018-04-30 09:04:52 +02:00
|
|
|
)
|
|
|
|
self.assertEqual(len(account.change_keys.addresses), 1)
|
|
|
|
self.assertEqual(
|
|
|
|
account.change_keys.addresses[0],
|
2018-06-12 17:53:29 +02:00
|
|
|
b'bFpHENtqugKKHDshKFq2Mnb59Y2bx4vKgL'
|
2018-04-30 09:04:52 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
account_data['coin'] = 'lbc_mainnet'
|
|
|
|
self.assertDictEqual(account_data, account.to_dict())
|