def validate_password(storage: WalletStorage, password: str) -> bool: try: storage.check_password(password) except InvalidPassword: pass else: return True return False
def test_legacy_wallet_loading(storage_info: WalletStorageInfo) -> None: # When a wallet is composed of multiple files, we need to know which to load. wallet_filenames = [] if storage_info.kind != StorageKind.DATABASE: wallet_filenames.append(storage_info.filename) if storage_info.kind in (StorageKind.DATABASE, StorageKind.HYBRID): wallet_filenames.append(storage_info.filename + DATABASE_EXT) temp_dir = tempfile.mkdtemp() for _wallet_filename in wallet_filenames: source_wallet_path = os.path.join(TEST_WALLET_PATH, _wallet_filename) wallet_path = os.path.join(temp_dir, _wallet_filename) shutil.copyfile(source_wallet_path, wallet_path) wallet_filename = storage_info.filename wallet_path = os.path.join(temp_dir, wallet_filename) # "<expected version>_<network>_<type>[_<subtype>]" (expected_version_text, expected_network, expected_type, *expected_subtypes) \ = wallet_filename.split("_") expected_version = int(expected_version_text) if "testnet" == expected_network: Net.set_to(SVTestnet) if storage_info.kind == StorageKind.HYBRID: pytest.xfail("old development database wallets not supported yet") password = None storage = WalletStorage(wallet_path) if "passworded" in expected_subtypes: password = "******" text_store = storage.get_text_store() text_store.load_data(text_store.decrypt(password)) if "encrypted" in expected_subtypes: password = "******" if expected_version >= 22: password = "******" storage.check_password(password) storage.upgrade(password is not None, password) try: wallet = Wallet(storage) except FileNotFoundError as e: if sys.version_info[:3] >= (3, 8, 0): msg = "Could not find module 'libusb-1.0.dll' (or one of its dependencies)." if msg in e.args[0]: pytest.xfail("libusb DLL could not be found") return raise e except OSError as e: if sys.version_info[:3] < (3, 8, 0): if "The specified module could not be found" in e.args[1]: pytest.xfail("libusb DLL could not be found") return raise e old_password = password password = "******" wallet.update_password(password, old_password) if "standard" == expected_type: is_bip39 = "bip39" in expected_subtypes check_legacy_parent_of_standard_wallet(wallet, is_bip39=is_bip39, password=password) elif "imported" == expected_type: if "privkey" in wallet_filename: check_legacy_parent_of_imported_privkey_wallet(wallet) elif "address" in expected_subtypes: check_legacy_parent_of_imported_address_wallet(wallet) else: raise Exception(f"unrecognised wallet file {wallet_filename}") elif "multisig" == expected_type: check_legacy_parent_of_multisig_wallet(wallet) elif "hardware" == expected_type: check_legacy_parent_of_hardware_wallet(wallet) elif "blank" == expected_type: check_parent_of_blank_wallet(wallet) else: raise Exception(f"unrecognised wallet file {wallet_filename}") if "testnet" == expected_network: Net.set_to(SVMainnet)