def check_legacy_parent_of_imported_privkey_wallet( parent_wallet: ParentWallet, keypairs: Optional[Dict[str, str]] = None) -> None: assert len(parent_wallet.get_child_wallets()) == 1 child_wallet: ImportedPrivkeyWallet = parent_wallet.get_child_wallets()[0] parent_keystores = parent_wallet.get_keystores() assert len(parent_keystores) == 1 child_keystores = child_wallet.get_keystores() assert len(child_keystores) == 1 assert parent_keystores[0] is child_keystores[0] keystore_data = parent_keystores[0].dump() assert 'type' in keystore_data assert len(keystore_data) == 2 assert keystore_data['type'] == 'imported' if keypairs is not None: assert keystore_data['keypairs'] == keypairs else: assert "keypairs" in keystore_data child_wallet_data = child_wallet.dump() # A newly created wallet. expected_count = 3 if "stored_height" in child_wallet_data: # A wallet that has synced after it was created. expected_count = 4 assert len(child_wallet_data) == expected_count assert child_wallet_data['id'] == 0 assert child_wallet_data[ 'wallet_type'] == ImportedPrivkeyWallet.wallet_type keystore_usage = child_wallet_data['keystore_usage'] assert len(keystore_usage) == 1 assert len(keystore_usage[0]) == 1 assert keystore_usage[0]['index'] == 0
def check_legacy_parent_of_standard_wallet( parent_wallet: ParentWallet, seed_words: Optional[str] = None, is_bip39: bool = False, password: Optional[str] = None) -> None: assert len(parent_wallet.get_child_wallets()) == 1 child_wallet: Standard_Wallet = parent_wallet.get_child_wallets()[0] parent_keystores = parent_wallet.get_keystores() assert len(parent_keystores) == 1 child_keystores = child_wallet.get_keystores() assert len(child_keystores) == 1 assert parent_keystores[0] is child_keystores[0] keystore_encrypted = parent_wallet.has_password() if keystore_encrypted: assert password is not None assert not child_keystores[0].has_seed( ) or child_keystores[0].get_seed(password) assert type(child_keystores[0].get_passphrase(password)) is str assert child_keystores[0].get_master_private_key(password) keystore_data = parent_keystores[0].dump() entry_count = 4 if is_bip39: entry_count = 3 assert len(keystore_data) == entry_count assert keystore_data['type'] == 'bip32' assert 'xpub' in keystore_data assert 'xprv' in keystore_data assert "encrypted" not in parent_wallet.name() or keystore_encrypted if is_bip39: assert "seed" not in keystore_data else: if seed_words is None: assert "seed" in keystore_data else: assert keystore_data['seed'] == seed_words child_wallet_data = child_wallet.dump() # A newly created wallet. expected_count = 3 if "stored_height" in child_wallet_data: # A wallet that has synced after it was created. assert "labels" in child_wallet_data expected_count = 5 assert len(child_wallet_data) == expected_count assert child_wallet_data['id'] == 0 assert child_wallet_data['wallet_type'] == 'standard' keystore_usage = child_wallet_data['keystore_usage'] assert len(keystore_usage) == 1 assert len(keystore_usage[0]) == 1 assert keystore_usage[0]['index'] == 0
def check_legacy_parent_of_imported_address_wallet( parent_wallet: ParentWallet) -> None: assert len(parent_wallet.get_child_wallets()) == 1 child_wallet: ImportedAddressWallet = parent_wallet.get_child_wallets()[0] assert len(parent_wallet.get_keystores()) == 0 assert len(child_wallet.get_keystores()) == 0 child_wallet_data = child_wallet.dump() # A newly created wallet. expected_count = 2 if "stored_height" in child_wallet_data: # A wallet that has synced after it was created. expected_count = 3 assert len(child_wallet_data) == expected_count assert child_wallet_data['id'] == 0 assert child_wallet_data[ 'wallet_type'] == ImportedAddressWallet.wallet_type assert "keystore_usage" not in child_wallet_data
def check_legacy_parent_of_standard_wallet(parent_wallet: ParentWallet, seed_words: Optional[str] = None, is_bip39: bool = False) -> None: assert len(parent_wallet.get_child_wallets()) == 1 child_wallet: Standard_Wallet = parent_wallet.get_child_wallets()[0] parent_keystores = parent_wallet.get_keystores() assert len(parent_keystores) == 1 child_keystores = child_wallet.get_keystores() assert len(child_keystores) == 1 assert parent_keystores[0] is child_keystores[0] keystore_data = parent_keystores[0].dump() entry_count = 4 if is_bip39: entry_count = 3 assert len(keystore_data) == entry_count assert keystore_data['type'] == 'bip32' assert 'xpub' in keystore_data assert 'xprv' in keystore_data if is_bip39: assert "seed" not in keystore_data else: if seed_words is None: assert "seed" in keystore_data else: assert keystore_data['seed'] == seed_words child_wallet_data = child_wallet.dump() # A newly created wallet. expected_count = 3 if "stored_height" in child_wallet_data: # A wallet that has synced after it was created. assert "labels" in child_wallet_data expected_count = 5 assert len(child_wallet_data) == expected_count assert child_wallet_data['id'] == 0 assert child_wallet_data['wallet_type'] == 'standard' keystore_usage = child_wallet_data['keystore_usage'] assert len(keystore_usage) == 1 assert len(keystore_usage[0]) == 1 assert keystore_usage[0]['index'] == 0
def check_legacy_parent_of_multisig_wallet( parent_wallet: ParentWallet) -> None: assert len(parent_wallet.get_child_wallets()) == 1 child_wallet: Multisig_Wallet = parent_wallet.get_child_wallets()[0] wallet_type = child_wallet.wallet_type m, n = multisig_type(wallet_type) parent_keystores = parent_wallet.get_keystores() assert len(parent_keystores) == 2 child_keystores = child_wallet.get_keystores() assert len(child_keystores) == n for i in range(n): assert parent_keystores[i] is child_keystores[i] for i in range(n): keystore_data = parent_keystores[0].dump() if len(keystore_data) == 4: assert keystore_data['type'] == 'bip32' assert keystore_data['seed'] is not None # == seed_words assert keystore_data['xpub'] is not None assert keystore_data['xprv'] is not None else: assert len(keystore_data) == 3 assert keystore_data['type'] == 'bip32' assert keystore_data['xpub'] is not None assert keystore_data['xprv'] is None child_wallet_data = child_wallet.dump() # A newly created wallet. entry_count = 3 if "stored_height" in child_wallet_data: assert "labels" in child_wallet_data # A wallet that has synced after it was created. entry_count = 5 assert len(child_wallet_data) == entry_count assert child_wallet_data['id'] == 0 assert child_wallet_data['wallet_type'] == wallet_type keystore_usage = [] for i in range(n): keystore_usage.append({'index': i, 'name': f'x{i+1}/'}) assert child_wallet_data['keystore_usage'] == keystore_usage
def check_legacy_parent_of_hardware_wallet( parent_wallet: ParentWallet) -> None: assert len(parent_wallet.get_child_wallets()) == 1 child_wallet = parent_wallet.get_child_wallets()[0] parent_keystores = parent_wallet.get_keystores() assert len(parent_keystores) == 1 child_keystores = child_wallet.get_keystores() assert len(child_keystores) == 1 assert parent_keystores[0] is child_keystores[0] keystore_data = parent_keystores[0].dump() # General hardware wallet. entry_count = 5 if keystore_data['hw_type'] == "ledger": # Ledger wallets extend the keystore. assert "cfg" in keystore_data entry_count = 6 assert len(keystore_data) == entry_count assert keystore_data['type'] == 'hardware' assert 'hw_type' in keystore_data assert 'label' in keystore_data assert "derivation" in keystore_data child_wallet_data = child_wallet.dump() # A newly created wallet. expected_count = 3 if "stored_height" in child_wallet_data: # A wallet that has synced after it was created. assert "labels" in child_wallet_data expected_count = 5 assert len(child_wallet_data) == expected_count assert child_wallet_data['id'] == 0 assert child_wallet_data['wallet_type'] == 'standard' keystore_usage = child_wallet_data['keystore_usage'] assert len(keystore_usage) == 1 assert len(keystore_usage[0]) == 1 assert keystore_usage[0]['index'] == 0