2017-10-16 05:11:05 +02:00
|
|
|
import shutil
|
|
|
|
|
import tempfile
|
2019-05-13 19:21:26 +02:00
|
|
|
import os
|
2020-02-05 15:13:37 +01:00
|
|
|
import json
|
2020-09-03 18:04:27 +02:00
|
|
|
from typing import Optional
|
2021-03-09 17:52:36 +01:00
|
|
|
import asyncio
|
2023-08-30 18:35:56 +00:00
|
|
|
import inspect
|
2017-10-16 05:11:05 +02:00
|
|
|
|
tests: maybe fix tearDown() issue in test_storage_upgrade.py
from travis logs:
--- Logging error ---
Traceback (most recent call last):
File "/opt/python/3.7.6/lib/python3.7/logging/__init__.py", line 1028, in emit
stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
File "/opt/python/3.7.6/lib/python3.7/threading.py", line 890, in _bootstrap
self._bootstrap_inner()
File "/opt/python/3.7.6/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/home/travis/build/spesmilo/electrum/electrum/plugin.py", line 213, in run
self.run_jobs()
File "/home/travis/build/spesmilo/electrum/electrum/util.py", line 359, in on_stop
self.logger.info("stopped")
Message: 'stopped'
2021-03-10 20:16:25 +01:00
|
|
|
import electrum
|
2023-08-18 15:13:33 +02:00
|
|
|
from electrum.wallet_db import WalletDBUpgrader, WalletDB, WalletRequiresUpgrade, WalletRequiresSplit
|
2018-07-11 17:38:47 +02:00
|
|
|
from electrum.wallet import Wallet
|
2019-03-01 19:46:23 +01:00
|
|
|
from electrum import constants
|
2021-03-09 17:52:36 +01:00
|
|
|
from electrum import util
|
2023-08-24 18:21:23 +00:00
|
|
|
from electrum.plugin import Plugins
|
|
|
|
|
from electrum.simple_config import SimpleConfig
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2022-10-31 18:44:38 +00:00
|
|
|
from . import as_testnet
|
2018-07-11 17:38:47 +02:00
|
|
|
from .test_wallet import WalletTestCase
|
2017-10-14 03:29:08 +02:00
|
|
|
|
|
|
|
|
|
2023-08-30 18:35:56 +00:00
|
|
|
WALLET_FILES_DIR = os.path.join(os.path.dirname(__file__), "test_storage_upgrade")
|
|
|
|
|
|
|
|
|
|
|
2017-10-16 04:37:01 +02:00
|
|
|
# TODO add other wallet types: 2fa, xpub-only
|
|
|
|
|
# TODO hw wallet with client version 2.6.x (single-, and multiacc)
|
2017-10-14 03:29:08 +02:00
|
|
|
class TestStorageUpgrade(WalletTestCase):
|
|
|
|
|
|
2023-08-30 18:35:56 +00:00
|
|
|
def _get_wallet_str(self):
|
|
|
|
|
test_method_name = inspect.stack()[1][3]
|
|
|
|
|
assert isinstance(test_method_name, str)
|
|
|
|
|
assert test_method_name.startswith("test_upgrade_from_")
|
|
|
|
|
fname = test_method_name[len("test_upgrade_from_"):]
|
|
|
|
|
test_vector_file = os.path.join(WALLET_FILES_DIR, fname)
|
|
|
|
|
with open(test_vector_file, "r") as f:
|
|
|
|
|
wallet_str = f.read()
|
|
|
|
|
return wallet_str
|
|
|
|
|
|
|
|
|
|
|
2019-03-01 21:02:10 +01:00
|
|
|
##########
|
|
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_1_9_8_seeded(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
"""note: this wallet file is not valid json: it tests the ast.literal_eval()
|
|
|
|
|
fallback in wallet_db.load_data()
|
|
|
|
|
"""
|
|
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2017-10-16 04:37:01 +02:00
|
|
|
# TODO pre-2.0 mixed wallets are not split currently
|
2023-02-18 10:01:21 +00:00
|
|
|
#async def test_upgrade_from_client_1_9_8_mixed(self):
|
2017-10-16 04:37:01 +02:00
|
|
|
# wallet_str = "{'addr_history':{'15V7MsQK2vjF5aEXLVG11qi2eZPZsXdnYc':[],'177hEYTccmuYH8u68pYfaLteTxwJrVgvJj':[],'1DjtUCcQwwzA3GSPA7Kd79PMnri7tLDPYC':[],'1PGEgaPG1XJqmuSj68GouotWeYkCtwo4wm':[],'1PAgpPxnL42Hp3cWxmSfdChPqqGiM8g7zj':[],'1DgrwN2JCDZ6uPMSvSz8dPeUtaxLxWM2kf':[],'1H3mPXHFzA8UbvhQVabcDjYw3CPb3djvxs':[],'1HocPduHmQUJerpdaLG8DnmxvnDCVQwWsa':[]},'accounts_expanded':{},'master_public_key':'756d1fe6ded28d43d4fea902a9695feb785447514d6e6c3bdf369f7c3432fdde4409e4efbffbcf10084d57c5a98d1f34d20ac1f133bdb64fa02abf4f7bde1dfb','use_encryption':False,'seed':'2605aafe50a45bdf2eb155302437e678','accounts':{0:{0:['1DjtUCcQwwzA3GSPA7Kd79PMnri7tLDPYC','1PAgpPxnL42Hp3cWxmSfdChPqqGiM8g7zj','177hEYTccmuYH8u68pYfaLteTxwJrVgvJj','1PGEgaPG1XJqmuSj68GouotWeYkCtwo4wm','15V7MsQK2vjF5aEXLVG11qi2eZPZsXdnYc'],1:['1H3mPXHFzA8UbvhQVabcDjYw3CPb3djvxs','1HocPduHmQUJerpdaLG8DnmxvnDCVQwWsa','1DgrwN2JCDZ6uPMSvSz8dPeUtaxLxWM2kf'],'mpk':'756d1fe6ded28d43d4fea902a9695feb785447514d6e6c3bdf369f7c3432fdde4409e4efbffbcf10084d57c5a98d1f34d20ac1f133bdb64fa02abf4f7bde1dfb'}},'imported_keys':{'15CyDgLffJsJgQrhcyooFH4gnVDG82pUrA':'5JyVyXU1LiRXATvRTQvR9Kp8Rx1X84j2x49iGkjSsXipydtByUq','1Exet2BhHsFxKTwhnfdsBMkPYLGvobxuW6':'L3Gi6EQLvYw8gEEUckmqawkevfj9s8hxoQDFveQJGZHTfyWnbk1U','1364Js2VG66BwRdkaoxAaFtdPb1eQgn8Dr':'L2sED74axVXC4H8szBJ4rQJrkfem7UMc6usLCPUoEWxDCFGUaGUM'},'seed_version':4}"
|
2023-02-18 10:01:21 +00:00
|
|
|
# await self._upgrade_storage(wallet_str, accounts=2)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_0_4_seeded(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_0_4_importedkeys(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_0_4_watchaddresses(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_0_4_trezor_singleacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_0_4_trezor_multiacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str, accounts=2)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_0_4_multisig(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_1_1_seeded(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_1_1_importedkeys(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_1_1_watchaddresses(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_1_1_trezor_singleacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_1_1_trezor_multiacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str, accounts=2)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_1_1_multisig(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_2_0_seeded(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_2_0_importedkeys(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_2_0_watchaddresses(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_2_0_trezor_singleacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_2_0_trezor_multiacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str, accounts=2)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_2_0_multisig(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_3_2_seeded(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_3_2_importedkeys(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_3_2_watchaddresses(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_3_2_trezor_singleacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_3_2_trezor_multiacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str, accounts=2)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_3_2_multisig(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_4_3_seeded(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_4_3_importedkeys(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_4_3_watchaddresses(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_4_3_trezor_singleacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_4_3_trezor_multiacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str, accounts=2)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_4_3_multisig(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_5_4_seeded(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_5_4_importedkeys(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_5_4_watchaddresses(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_5_4_trezor_singleacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_5_4_trezor_multiacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str, accounts=2)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_5_4_multisig(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_6_4_seeded(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_6_4_importedkeys(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_6_4_watchaddresses(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_6_4_multisig(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_7_18_seeded(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_7_18_importedkeys(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_7_18_watchaddresses(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_7_18_trezor_singleacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_7_18_multisig(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2017-11-02 09:49:11 +01:00
|
|
|
# seed_version 13 is ambiguous
|
|
|
|
|
# client 2.7.18 created wallets with an earlier "v13" structure
|
|
|
|
|
# client 2.8.3 created wallets with a later "v13" structure
|
|
|
|
|
# client 2.8.3 did not do a proper clean-slate upgrade
|
|
|
|
|
# the wallet here was created in 2.7.18 with a couple privkeys imported
|
|
|
|
|
# then opened in 2.8.3, after which a few other new privkeys were imported
|
|
|
|
|
# it's in some sense in an "inconsistent" state
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_8_3_importedkeys_flawed_previous_upgrade_from_2_7_18(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-11-02 09:49:11 +01:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_8_3_seeded(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_8_3_importedkeys(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_8_3_watchaddresses(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_8_3_trezor_singleacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_8_3_multisig(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_9_3_seeded(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2022-10-31 18:44:38 +00:00
|
|
|
@as_testnet
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_9_3_old_seeded_with_realistic_history(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2019-03-01 19:46:23 +01:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_9_3_importedkeys(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_9_3_watchaddresses(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_9_3_trezor_singleacc(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_9_3_multisig(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2017-10-16 04:37:01 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_3_2_3_ledger_standard_keystore_changes(self):
|
2020-09-03 18:04:27 +02:00
|
|
|
# see #6066
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
db = await self._upgrade_storage(wallet_str)
|
2023-06-23 17:36:34 +02:00
|
|
|
wallet = Wallet(db, config=self.config)
|
2020-09-03 18:04:27 +02:00
|
|
|
ks = wallet.keystore
|
|
|
|
|
# to simulate ks.opportunistically_fill_in_missing_info_from_device():
|
|
|
|
|
ks._root_fingerprint = "deadbeef"
|
|
|
|
|
ks.is_requesting_to_be_rewritten_to_wallet_file = True
|
2023-02-18 10:01:21 +00:00
|
|
|
await wallet.stop()
|
2020-09-03 18:04:27 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_2_9_3_importedkeys_keystore_changes(self):
|
2020-09-03 18:04:27 +02:00
|
|
|
# see #6401
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
db = await self._upgrade_storage(wallet_str)
|
2023-06-23 17:36:34 +02:00
|
|
|
wallet = Wallet(db, config=self.config)
|
2020-09-03 18:04:27 +02:00
|
|
|
wallet.import_private_keys(
|
|
|
|
|
["p2wpkh:L1cgMEnShp73r9iCukoPE3MogLeueNYRD9JVsfT1zVHyPBR3KqBY"],
|
|
|
|
|
password=None
|
|
|
|
|
)
|
2023-02-18 10:01:21 +00:00
|
|
|
await wallet.stop()
|
2020-09-03 18:04:27 +02:00
|
|
|
|
2022-10-31 18:44:38 +00:00
|
|
|
@as_testnet
|
2023-02-18 10:01:21 +00:00
|
|
|
async def test_upgrade_from_client_3_3_8_xpub_with_realistic_history(self):
|
2023-08-30 18:35:56 +00:00
|
|
|
wallet_str = self._get_wallet_str()
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._upgrade_storage(wallet_str)
|
2020-07-08 00:57:23 +02:00
|
|
|
|
2024-02-26 18:54:21 +00:00
|
|
|
@as_testnet
|
|
|
|
|
async def test_upgrade_from_client_4_5_2_9dk_with_ln(self):
|
|
|
|
|
# This is a realistic testnet wallet, from the "9dk" seed, including some lightning sends/receives,
|
|
|
|
|
# some labels, frozen addresses, saved local txs, invoices/requests, etc. The file also has partial writes.
|
|
|
|
|
# Also, regression test for #8913
|
|
|
|
|
wallet_str = self._get_wallet_str()
|
|
|
|
|
await self._upgrade_storage(wallet_str)
|
|
|
|
|
|
2017-10-16 04:37:01 +02:00
|
|
|
##########
|
|
|
|
|
|
tests: maybe fix tearDown() issue in test_storage_upgrade.py
from travis logs:
--- Logging error ---
Traceback (most recent call last):
File "/opt/python/3.7.6/lib/python3.7/logging/__init__.py", line 1028, in emit
stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
File "/opt/python/3.7.6/lib/python3.7/threading.py", line 890, in _bootstrap
self._bootstrap_inner()
File "/opt/python/3.7.6/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/home/travis/build/spesmilo/electrum/electrum/plugin.py", line 213, in run
self.run_jobs()
File "/home/travis/build/spesmilo/electrum/electrum/util.py", line 359, in on_stop
self.logger.info("stopped")
Message: 'stopped'
2021-03-10 20:16:25 +01:00
|
|
|
plugins: 'electrum.plugin.Plugins'
|
|
|
|
|
|
2023-08-24 18:21:23 +00:00
|
|
|
def setUp(self):
|
|
|
|
|
super().setUp()
|
2017-10-16 05:23:51 +02:00
|
|
|
gui_name = 'cmdline'
|
2017-10-16 04:37:01 +02:00
|
|
|
# TODO it's probably wasteful to load all plugins... only need Trezor
|
2023-09-06 14:10:11 +00:00
|
|
|
self.plugins = Plugins(self.config, gui_name)
|
2023-08-24 18:21:23 +00:00
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
|
self.plugins.stop()
|
|
|
|
|
self.plugins.stopped_event.wait()
|
2023-09-06 14:05:45 +00:00
|
|
|
super().tearDown()
|
2017-10-16 05:11:05 +02:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def _upgrade_storage(self, wallet_json, accounts=1) -> Optional[WalletDB]:
|
2017-10-14 03:29:08 +02:00
|
|
|
if accounts == 1:
|
2019-05-13 19:21:26 +02:00
|
|
|
# test manual upgrades
|
2023-08-18 15:13:33 +02:00
|
|
|
try:
|
|
|
|
|
db = self._load_db_from_json_string(
|
|
|
|
|
wallet_json=wallet_json,
|
2023-09-22 11:49:53 +02:00
|
|
|
upgrade=False)
|
2023-08-18 15:13:33 +02:00
|
|
|
except WalletRequiresUpgrade:
|
|
|
|
|
db = self._load_db_from_json_string(
|
|
|
|
|
wallet_json=wallet_json,
|
2023-09-22 11:49:53 +02:00
|
|
|
upgrade=True)
|
2023-02-18 10:01:21 +00:00
|
|
|
await self._sanity_check_upgraded_db(db)
|
2023-08-18 15:13:33 +02:00
|
|
|
return db
|
2017-10-14 03:29:08 +02:00
|
|
|
else:
|
2023-08-18 15:13:33 +02:00
|
|
|
try:
|
|
|
|
|
db = self._load_db_from_json_string(
|
|
|
|
|
wallet_json=wallet_json,
|
2023-09-22 11:49:53 +02:00
|
|
|
upgrade=False)
|
2023-08-18 15:13:33 +02:00
|
|
|
except WalletRequiresSplit as e:
|
|
|
|
|
split_data = e._split_data
|
|
|
|
|
self.assertEqual(accounts, len(split_data))
|
|
|
|
|
for item in split_data:
|
|
|
|
|
data = json.dumps(item)
|
2023-09-22 11:49:53 +02:00
|
|
|
new_db = WalletDB(data, storage=None, upgrade=True)
|
2023-08-18 15:13:33 +02:00
|
|
|
await self._sanity_check_upgraded_db(new_db)
|
2020-02-05 15:13:37 +01:00
|
|
|
|
2023-02-18 10:01:21 +00:00
|
|
|
async def _sanity_check_upgraded_db(self, db):
|
2023-06-23 17:36:34 +02:00
|
|
|
wallet = Wallet(db, config=self.config)
|
2023-02-18 10:01:21 +00:00
|
|
|
await wallet.stop()
|
2017-10-14 03:29:08 +02:00
|
|
|
|
2019-05-13 19:21:26 +02:00
|
|
|
@staticmethod
|
2023-09-22 11:49:53 +02:00
|
|
|
def _load_db_from_json_string(*, wallet_json, upgrade):
|
|
|
|
|
db = WalletDB(wallet_json, storage=None, upgrade=upgrade)
|
2020-02-05 15:13:37 +01:00
|
|
|
return db
|