Commit Graph

16 Commits

Author SHA1 Message Date
SomberNight
2863fb4ab4 tests: add "as_testnet" fn decorator, to run single tests in testnet
As opposed to using TestCaseForTestnet class, this allows having a single class
of many related unit tests, some using testnet and some using mainnet constants.
2022-10-31 18:44:38 +00:00
SomberNight
872ce82418 tests: clean up event-loop creation 2022-05-04 01:53:21 +02:00
SomberNight
2c57c78ebe asyncio: stop using get_event_loop(). introduce ~singleton loop.
asyncio.get_event_loop() became deprecated in python3.10. (see https://github.com/python/cpython/issues/83710)
```
.../electrum/electrum/daemon.py:470: DeprecationWarning: There is no current event loop
  self.asyncio_loop = asyncio.get_event_loop()
.../electrum/electrum/network.py:276: DeprecationWarning: There is no current event loop
  self.asyncio_loop = asyncio.get_event_loop()
```
Also, according to that thread, "set_event_loop() [... is] not deprecated by oversight".
So, we stop using get_event_loop() and set_event_loop() in our own code.
Note that libraries we use (such as the stdlib for python <3.10), might call get_event_loop,
which then relies on us having called set_event_loop e.g. for the GUI thread. To work around
this, a custom event loop policy providing a get_event_loop implementation is used.

Previously, we have been using a single asyncio event loop, created with
util.create_and_start_event_loop, and code in many places got a reference to this loop
using asyncio.get_event_loop().
Now, we still use a single asyncio event loop, but it is now stored as a global in
util._asyncio_event_loop (access with util.get_asyncio_loop()).

I believe these changes also fix https://github.com/spesmilo/electrum/issues/5376
2022-04-29 18:49:07 +02:00
SomberNight
05fd424548 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
SomberNight
3c019c2f9c daemon/wallet/network: make stop() methods async 2021-03-09 17:52:36 +01:00
SomberNight
8dc3fadd13 tests: add tests for #6066 and #6401. latter is failing atm.
see #6066
see #6401
2020-09-03 18:04:27 +02:00
SomberNight
307403a02c invoices: rm old corrupted non-bip70 invoices
fixes #6345
2020-07-08 00:57:23 +02:00
ThomasV
e1ce3aace7 Separate db from storage
- storage is content-agnostic
 - db and storage are passed to wallet contructor
2020-02-10 17:45:23 +01:00
SomberNight
04edad9984 config: no longer singleton. it is passed to Wallet.__init__
The few other cases that used SimpleConfig.get_instance() now
either get passed a config instance, or they try to get a reference
to something else that has a reference to a config.
(see lnsweep, qt/qrcodewidget, qt/qrtextedit)
2019-09-22 20:46:01 +02:00
SomberNight
53d189fc7a storage: fix some madness about get_data_ref() and put() interacting badly
previously load_transactions() had to be called before upgrade();
now we reverse this order.

to reproduce/illustrate issue, before this commit:

try running convert_version_17 and convert_version_18
(e.g. see testcase test_upgrade_from_client_2_9_3_old_seeded_with_realistic_history)
and then in qt console:
>> wallet.storage.db.get_data_ref('spent_outpoints') == wallet.storage.db.spent_outpoints
False
>> wallet.storage.db.get_data_ref('verified_tx3') == wallet.storage.db.verified_tx
False
2019-06-06 19:49:06 +02:00
SomberNight
fd58a0cb20 json_db: enforce order of 'load_transactions' and 'upgrade'
fixes #5331
2019-05-13 19:21:26 +02:00
SomberNight
94c4cb44d7 fix storage upgrade tests: "fixture 'func' not found" 2019-03-01 21:02:10 +01:00
SomberNight
9ecb504739 storage: fix convert_version_17 and add new test case
follow-up 121b8048b0
2019-03-01 19:46:23 +01:00
SomberNight
c4e09fa874 simplify Plugins constructor 2018-10-22 18:21:38 +02:00
Dzhelil Rufat
c9ffffc526 Remove unneccessary imports from the unit testing directory. (#4699) 2018-09-08 17:24:23 +02:00
Janus
097ac144d9 file reorganization with top-level module 2018-07-13 14:01:37 +02:00