2019-10-13 01:33:16 +02:00
|
|
|
import asyncio
|
|
|
|
from lbry.testcase import CommandTestCase
|
|
|
|
from binascii import unhexlify
|
2019-02-11 00:36:21 +01:00
|
|
|
|
|
|
|
|
2019-10-13 01:33:16 +02:00
|
|
|
class WalletSynchronization(CommandTestCase):
|
|
|
|
SEED = "carbon smart garage balance margin twelve chest sword toast envelope bottom stomach absent"
|
2019-02-11 00:36:21 +01:00
|
|
|
|
2019-10-13 01:33:16 +02:00
|
|
|
async def test_sync(self):
|
|
|
|
daemon = self.daemon
|
|
|
|
daemon2 = await self.add_daemon(
|
|
|
|
seed="chest sword toast envelope bottom stomach absent "
|
|
|
|
"carbon smart garage balance margin twelve"
|
2019-02-11 00:36:21 +01:00
|
|
|
)
|
2019-10-13 01:33:16 +02:00
|
|
|
address = (await daemon2.wallet_manager.default_account.receiving.get_addresses(limit=1, only_usable=True))[0]
|
|
|
|
sendtxid = await self.blockchain.send_to_address(address, 1)
|
|
|
|
await self.confirm_tx(sendtxid, daemon2.ledger)
|
2019-02-11 00:36:21 +01:00
|
|
|
|
2019-10-13 01:33:16 +02:00
|
|
|
# Preferences
|
|
|
|
self.assertFalse(daemon.jsonrpc_preference_get())
|
|
|
|
self.assertFalse(daemon2.jsonrpc_preference_get())
|
2019-02-11 00:36:21 +01:00
|
|
|
|
2019-10-13 01:33:16 +02:00
|
|
|
daemon.jsonrpc_preference_set("one", "1")
|
|
|
|
daemon.jsonrpc_preference_set("conflict", "1")
|
|
|
|
daemon.jsonrpc_preference_set("fruit", '["peach", "apricot"]')
|
|
|
|
await asyncio.sleep(1)
|
|
|
|
daemon2.jsonrpc_preference_set("two", "2")
|
|
|
|
daemon2.jsonrpc_preference_set("conflict", "2")
|
2019-02-11 00:36:21 +01:00
|
|
|
|
2019-10-13 01:33:16 +02:00
|
|
|
self.assertDictEqual(daemon.jsonrpc_preference_get(), {
|
|
|
|
"one": "1", "conflict": "1", "fruit": ["peach", "apricot"]
|
|
|
|
})
|
|
|
|
self.assertDictEqual(daemon2.jsonrpc_preference_get(), {"two": "2", "conflict": "2"})
|
2019-02-11 00:36:21 +01:00
|
|
|
|
2019-10-13 01:33:16 +02:00
|
|
|
self.assertEqual(len((await daemon.jsonrpc_account_list())['lbc_regtest']), 1)
|
2019-02-11 00:36:21 +01:00
|
|
|
|
2019-10-14 06:03:01 +02:00
|
|
|
daemon2.jsonrpc_wallet_encrypt('password')
|
|
|
|
daemon2.jsonrpc_wallet_lock()
|
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
await daemon2.jsonrpc_sync_apply('password')
|
|
|
|
|
|
|
|
daemon2.jsonrpc_wallet_unlock('password')
|
2019-10-13 01:33:16 +02:00
|
|
|
data = await daemon2.jsonrpc_sync_apply('password')
|
|
|
|
await daemon.jsonrpc_sync_apply('password', data=data['data'], blocking=True)
|
2019-03-11 14:52:35 +01:00
|
|
|
|
2019-10-13 01:33:16 +02:00
|
|
|
self.assertEqual(len((await daemon.jsonrpc_account_list())['lbc_regtest']), 2)
|
|
|
|
self.assertDictEqual(
|
|
|
|
# "two" key added and "conflict" value changed to "2"
|
|
|
|
daemon.jsonrpc_preference_get(),
|
|
|
|
{"one": "1", "two": "2", "conflict": "2", "fruit": ["peach", "apricot"]}
|
2019-03-11 14:52:35 +01:00
|
|
|
)
|
|
|
|
|
2019-10-13 01:33:16 +02:00
|
|
|
# Channel Certificate
|
|
|
|
channel = await daemon2.jsonrpc_channel_create('@foo', '0.1')
|
|
|
|
await daemon2.ledger.wait(channel)
|
|
|
|
await self.generate(1)
|
|
|
|
await daemon2.ledger.wait(channel)
|
2019-09-03 15:51:41 +02:00
|
|
|
|
2019-10-13 01:33:16 +02:00
|
|
|
# both daemons will have the channel but only one has the cert so far
|
|
|
|
self.assertEqual(len(await daemon.jsonrpc_channel_list()), 1)
|
|
|
|
self.assertEqual(len(daemon.wallet_manager.default_wallet.accounts[1].channel_keys), 0)
|
|
|
|
self.assertEqual(len(await daemon2.jsonrpc_channel_list()), 1)
|
|
|
|
self.assertEqual(len(daemon2.wallet_manager.default_account.channel_keys), 1)
|
2019-09-03 15:51:41 +02:00
|
|
|
|
2019-10-13 01:33:16 +02:00
|
|
|
data = await daemon2.jsonrpc_sync_apply('password')
|
|
|
|
await daemon.jsonrpc_sync_apply('password', data=data['data'], blocking=True)
|
2019-09-03 15:51:41 +02:00
|
|
|
|
2019-10-13 01:33:16 +02:00
|
|
|
# both daemons have the cert after sync'ing
|
|
|
|
self.assertEqual(
|
|
|
|
daemon2.wallet_manager.default_account.channel_keys,
|
|
|
|
daemon.wallet_manager.default_wallet.accounts[1].channel_keys
|
|
|
|
)
|