Browse Source

wallet: fix deleting address from Imported_Wallet

closes #4481
regtest_lnd
SomberNight 6 years ago
parent
commit
808239bbcc
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 12
      electrum/tests/test_wallet.py
  2. 2
      electrum/wallet.py

12
electrum/tests/test_wallet.py

@ -10,7 +10,7 @@ from io import StringIO
from electrum.storage import WalletStorage
from electrum.json_db import FINAL_SEED_VERSION
from electrum.wallet import (Abstract_Wallet, Standard_Wallet, create_new_wallet,
restore_wallet_from_text)
restore_wallet_from_text, Imported_Wallet)
from electrum.exchange_rate import ExchangeBase, FxThread
from electrum.util import TxMinedInfo
from electrum.bitcoin import COIN
@ -197,16 +197,22 @@ class TestCreateRestoreWallet(WalletTestCase):
def test_restore_wallet_from_text_addresses(self):
text = 'bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw bc1qnp78h78vp92pwdwq5xvh8eprlga5q8gu66960c'
d = restore_wallet_from_text(text, path=self.wallet_path, network=None)
wallet = d['wallet'] # type: Abstract_Wallet
wallet = d['wallet'] # type: Imported_Wallet
self.assertEqual('bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw', wallet.get_receiving_addresses()[0])
self.assertEqual(2, len(wallet.get_receiving_addresses()))
# also test addr deletion
wallet.delete_address('bc1qnp78h78vp92pwdwq5xvh8eprlga5q8gu66960c')
self.assertEqual(1, len(wallet.get_receiving_addresses()))
def test_restore_wallet_from_text_privkeys(self):
text = 'p2wpkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL p2wpkh:L24GxnN7NNUAfCXA6hFzB1jt59fYAAiFZMcLaJ2ZSawGpM3uqhb1'
d = restore_wallet_from_text(text, path=self.wallet_path, network=None)
wallet = d['wallet'] # type: Abstract_Wallet
wallet = d['wallet'] # type: Imported_Wallet
addr0 = wallet.get_receiving_addresses()[0]
self.assertEqual('bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw', addr0)
self.assertEqual('p2wpkh:L4jkdiXszG26SUYvwwJhzGwg37H2nLhrbip7u6crmgNeJysv5FHL',
wallet.export_private_key(addr0, password=None)[0])
self.assertEqual(2, len(wallet.get_receiving_addresses()))
# also test addr deletion
wallet.delete_address('bc1qnp78h78vp92pwdwq5xvh8eprlga5q8gu66960c')
self.assertEqual(1, len(wallet.get_receiving_addresses()))

2
electrum/wallet.py

@ -1451,7 +1451,7 @@ class Imported_Wallet(Simple_Wallet):
for tx_hash, height in details:
transactions_new.add(tx_hash)
transactions_to_remove -= transactions_new
self.db.remove_history(address)
self.db.remove_addr_history(address)
for tx_hash in transactions_to_remove:
self.remove_transaction(tx_hash)
self.db.remove_tx_fee(tx_hash)

Loading…
Cancel
Save