contacts: fix adding new contacts
This is a regression from 7ca89f56ee, which introduced StoredList.
The newly added test was failing without the change.
```
Traceback (most recent call last):
File "/home/user/wspace/electrum/electrum/gui/qt/main_window.py", line 1786, in new_contact_dialog
self.set_contact(line2.text(), line1.text())
File "/home/user/wspace/electrum/electrum/gui/qt/main_window.py", line 1435, in set_contact
self.contacts[address] = ('address', label)
File "/home/user/wspace/electrum/electrum/contacts.py", line 75, in __setitem__
self.save()
File "/home/user/wspace/electrum/electrum/contacts.py", line 62, in save
self.db.put('contacts', dict(self))
File "/home/user/wspace/electrum/electrum/json_db.py", line 42, in wrapper
return func(self, *args, **kwargs)
File "/home/user/wspace/electrum/electrum/json_db.py", line 318, in put
self.data[key] = copy.deepcopy(value)
File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.10/copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.10/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/lib/python3.10/copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.10/copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.10/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/lib/python3.10/copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.10/copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.10/copy.py", line 161, in deepcopy
rv = reductor(4)
TypeError: cannot pickle '_thread.RLock' object
```
This commit is contained in:
31
electrum/tests/test_contacts.py
Normal file
31
electrum/tests/test_contacts.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import os
|
||||
|
||||
from . import ElectrumTestCase
|
||||
|
||||
from electrum.simple_config import SimpleConfig
|
||||
from electrum.wallet import restore_wallet_from_text, Abstract_Wallet
|
||||
from electrum.daemon import Daemon
|
||||
|
||||
|
||||
class TestContacts(ElectrumTestCase):
|
||||
TESTNET = True
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.config = SimpleConfig({'electrum_path': self.electrum_path})
|
||||
self.wallet_path = os.path.join(self.electrum_path, "somewallet1")
|
||||
|
||||
async def test_saving_contacts(self):
|
||||
text = 'cross end slow expose giraffe fuel track awake turtle capital ranch pulp'
|
||||
d = restore_wallet_from_text(text, path=self.wallet_path, gap_limit=2, config=self.config)
|
||||
w = d['wallet'] # type: Abstract_Wallet
|
||||
w.contacts["myNNuLYNgHE92nGQuJd5mXo6gy9gKXEDyQ"] = ("address", "alice")
|
||||
w.contacts["tb1q4syjltptqwhe62t3u5gwz9nsw87kmcwx003z05"] = ("address", "bob")
|
||||
self.assertEqual(2, len(w.contacts))
|
||||
await w.stop()
|
||||
del w
|
||||
# re-open wallet from disk
|
||||
w = Daemon._load_wallet(self.wallet_path, password=None, config=self.config)
|
||||
self.assertEqual(2, len(w.contacts))
|
||||
w.contacts["n4STqqWPrvkapAyvXY2wJzfoKMnuJbDWoH"] = ("address", "carol")
|
||||
self.assertEqual(3, len(w.contacts))
|
||||
@@ -103,6 +103,7 @@ class WalletFileExceptionVersion51(WalletFileException): pass
|
||||
json_db.register_dict('transactions', lambda x: tx_from_any(x, deserialize=False), None)
|
||||
json_db.register_dict('prevouts_by_scripthash', lambda x: set(tuple(k) for k in x), None)
|
||||
json_db.register_dict('data_loss_protect_remote_pcp', lambda x: bytes.fromhex(x), None)
|
||||
json_db.register_dict('contacts', tuple, None)
|
||||
# register dicts that require key conversion
|
||||
for key in [
|
||||
'adds', 'locked_in', 'settles', 'fails', 'fee_updates', 'buckets',
|
||||
|
||||
Reference in New Issue
Block a user