|
9 | 9 | from electrum import storage, bitcoin, keystore, bip32, slip39, wallet
|
10 | 10 | from electrum import Transaction
|
11 | 11 | from electrum import SimpleConfig
|
| 12 | +from electrum import util |
12 | 13 | from electrum.address_synchronizer import TX_HEIGHT_UNCONFIRMED, TX_HEIGHT_UNCONF_PARENT
|
13 | 14 | from electrum.wallet import (sweep, Multisig_Wallet, Standard_Wallet, Imported_Wallet,
|
14 | 15 | restore_wallet_from_text, Abstract_Wallet, BumpFeeStrategy)
|
|
18 | 19 | from electrum.transaction import (TxOutput, Transaction, PartialTransaction, PartialTxOutput,
|
19 | 20 | PartialTxInput, tx_from_any, TxOutpoint)
|
20 | 21 | from electrum.mnemonic import seed_type
|
| 22 | +from electrum.network import Network |
21 | 23 |
|
22 | 24 | from electrum.plugins.trustedcoin import trustedcoin
|
23 | 25 |
|
@@ -699,8 +701,14 @@ class TestWalletSending(TestCaseForTestnet):
|
699 | 701 |
|
700 | 702 | def setUp(self):
|
701 | 703 | super().setUp()
|
| 704 | + self.asyncio_loop, self._stop_loop, self._loop_thread = util.create_and_start_event_loop() |
702 | 705 | self.config = SimpleConfig({'electrum_path': self.electrum_path})
|
703 | 706 |
|
| 707 | + def tearDown(self): |
| 708 | + self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1) |
| 709 | + self._loop_thread.join(timeout=1) |
| 710 | + super().tearDown() |
| 711 | + |
704 | 712 | def create_standard_wallet_from_seed(self, seed_words, *, config=None, gap_limit=2):
|
705 | 713 | if config is None:
|
706 | 714 | config = self.config
|
@@ -1369,14 +1377,7 @@ async def get_transaction(self, txid, timeout=None):
|
1369 | 1377 | raise Exception("unexpected txid")
|
1370 | 1378 | def has_internet_connection(self):
|
1371 | 1379 | return True
|
1372 |
| - def run_from_another_thread(self, coro, *, timeout=None): |
1373 |
| - loop, stop_loop, loop_thread = create_and_start_event_loop() |
1374 |
| - fut = asyncio.run_coroutine_threadsafe(coro, loop) |
1375 |
| - try: |
1376 |
| - return fut.result(timeout) |
1377 |
| - finally: |
1378 |
| - loop.call_soon_threadsafe(stop_loop.set_result, 1) |
1379 |
| - loop_thread.join(timeout=1) |
| 1380 | + run_from_another_thread = Network.run_from_another_thread |
1380 | 1381 | def get_local_height(self):
|
1381 | 1382 | return 0
|
1382 | 1383 | def blockchain(self):
|
@@ -1429,14 +1430,7 @@ async def get_transaction(self, txid, timeout=None):
|
1429 | 1430 | raise Exception("unexpected txid")
|
1430 | 1431 | def has_internet_connection(self):
|
1431 | 1432 | return True
|
1432 |
| - def run_from_another_thread(self, coro, *, timeout=None): |
1433 |
| - loop, stop_loop, loop_thread = create_and_start_event_loop() |
1434 |
| - fut = asyncio.run_coroutine_threadsafe(coro, loop) |
1435 |
| - try: |
1436 |
| - return fut.result(timeout) |
1437 |
| - finally: |
1438 |
| - loop.call_soon_threadsafe(stop_loop.set_result, 1) |
1439 |
| - loop_thread.join(timeout=1) |
| 1433 | + run_from_another_thread = Network.run_from_another_thread |
1440 | 1434 | def get_local_height(self):
|
1441 | 1435 | return 0
|
1442 | 1436 | def blockchain(self):
|
@@ -1844,8 +1838,8 @@ async def get_transaction(self, txid):
|
1844 | 1838 | network = NetworkMock()
|
1845 | 1839 | dest_addr = 'tb1q3ws2p0qjk5vrravv065xqlnkckvzcpclk79eu2'
|
1846 | 1840 | sweep_coro = sweep(privkeys, network=network, config=self.config, to_address=dest_addr, fee=5000, locktime=1325785, tx_version=1)
|
1847 |
| - loop = asyncio.get_event_loop() |
1848 |
| - tx = loop.run_until_complete(sweep_coro) |
| 1841 | + loop = util.get_asyncio_loop() |
| 1842 | + tx = asyncio.run_coroutine_threadsafe(sweep_coro, loop).result() |
1849 | 1843 |
|
1850 | 1844 | tx_copy = tx_from_any(tx.serialize())
|
1851 | 1845 | self.assertEqual('010000000129349e5641d79915e9d0282fdbaee8c3df0b6731bab9d70bf626e8588bde24ac010000004847304402206bf0d0a93abae0d5873a62ebf277a5dd2f33837821e8b93e74d04e19d71b578002201a6d729bc159941ef5c4c9e5fe13ece9fc544351ba531b00f68ba549c8b38a9a01fdffffff01b82e0f00000000001600148ba0a0bc12b51831f58c7ea8607e76c5982c071fd93a1400',
|
@@ -2199,14 +2193,7 @@ async def get_transaction(self, txid, timeout=None):
|
2199 | 2193 | raise Exception("unexpected txid")
|
2200 | 2194 | def has_internet_connection(self):
|
2201 | 2195 | return True
|
2202 |
| - def run_from_another_thread(self, coro, *, timeout=None): |
2203 |
| - loop, stop_loop, loop_thread = create_and_start_event_loop() |
2204 |
| - fut = asyncio.run_coroutine_threadsafe(coro, loop) |
2205 |
| - try: |
2206 |
| - return fut.result(timeout) |
2207 |
| - finally: |
2208 |
| - loop.call_soon_threadsafe(stop_loop.set_result, 1) |
2209 |
| - loop_thread.join(timeout=1) |
| 2196 | + run_from_another_thread = Network.run_from_another_thread |
2210 | 2197 | def get_local_height(self):
|
2211 | 2198 | return 0
|
2212 | 2199 | def blockchain(self):
|
|
0 commit comments