diff --git a/lbry/lbry/testcase.py b/lbry/lbry/testcase.py index 9b3a77ba5..3fe28e076 100644 --- a/lbry/lbry/testcase.py +++ b/lbry/lbry/testcase.py @@ -11,6 +11,7 @@ import lbry.wallet from lbry.conf import Config from lbry.extras.daemon.Daemon import Daemon, jsonrpc_dumps_pretty from lbry.wallet import LbryWalletManager +from lbry.wallet.account import Account from lbry.extras.daemon.Components import Component, WalletComponent from lbry.extras.daemon.Components import ( DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, @@ -63,6 +64,8 @@ class CommandTestCase(IntegrationTestCase): VERBOSITY = logging.WARN blob_lru_cache_size = 0 + account: Account + async def asyncSetUp(self): await super().asyncSetUp() diff --git a/lbry/lbry/wallet/account.py b/lbry/lbry/wallet/account.py index da92358bd..f29233ba5 100644 --- a/lbry/lbry/wallet/account.py +++ b/lbry/lbry/wallet/account.py @@ -53,6 +53,10 @@ class Account(BaseAccount): return channel_keys = {} for private_key_pem in self.channel_keys.values(): + if not isinstance(private_key_pem, str): + continue + if "-----BEGIN EC PRIVATE KEY-----" not in private_key_pem: + continue private_key = ecdsa.SigningKey.from_pem(private_key_pem, hashfunc=sha256) public_key_der = private_key.get_verifying_key().to_der() channel_keys[self.ledger.public_key_to_address(public_key_der)] = private_key_pem diff --git a/lbry/tests/integration/test_account_commands.py b/lbry/tests/integration/test_account_commands.py index 999fdc352..25dccf923 100644 --- a/lbry/tests/integration/test_account_commands.py +++ b/lbry/tests/integration/test_account_commands.py @@ -54,3 +54,14 @@ class AccountManagement(CommandTestCase): # list specific account response = await self.daemon.jsonrpc_account_list(account_id, include_claims=True) self.assertEqual(response['name'], 'recreated account') + + async def test_wallet_migration(self): + # null certificates should get deleted + await self.channel_create('@foo1') + await self.channel_create('@foo2') + await self.channel_create('@foo3') + keys = list(self.account.channel_keys.keys()) + self.account.channel_keys[keys[0]] = None + self.account.channel_keys[keys[1]] = "some invalid junk" + await self.account.maybe_migrate_certificates() + self.assertEqual(list(self.account.channel_keys.keys()), [keys[2]])