From 3ccfc09e0196d59ecbc9bf3484ea4f1d0151f1de Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Tue, 31 Dec 2019 15:30:13 -0500 Subject: [PATCH] conslidated testcase --- lbry/lbry/error/README.md | 2 +- lbry/lbry/error/__init__.py | 2 +- lbry/lbry/testcase.py | 253 +++++++++++++++++- lbry/lbry/wallet/claim_proofs.py | 2 +- lbry/lbry/wallet/client/basetransaction.py | 4 +- lbry/lbry/wallet/client/errors.py | 2 - lbry/lbry/wallet/testcase.py | 248 ----------------- lbry/setup.py | 2 +- .../test_blockchain_reorganization.py | 2 +- lbry/tests/integration/test_claim_commands.py | 2 +- lbry/tests/integration/test_cli.py | 2 +- lbry/tests/integration/test_dht.py | 2 +- .../integration/test_exchange_rate_manager.py | 2 +- .../test_internal_transaction_api.py | 2 +- lbry/tests/integration/test_network.py | 2 +- .../tests/integration/test_resolve_command.py | 3 +- lbry/tests/integration/test_transactions.py | 3 +- lbry/tests/unit/analytics/test_track.py | 1 + lbry/tests/unit/blob/test_blob_file.py | 2 +- lbry/tests/unit/blob/test_blob_manager.py | 3 +- .../unit/blob_exchange/test_transfer_blob.py | 2 +- .../unit/comments/test_comment_signing.py | 2 +- .../unit/components/test_component_manager.py | 2 +- lbry/tests/unit/core/test_utils.py | 2 +- .../tests/unit/database/test_SQLiteStorage.py | 2 +- lbry/tests/unit/dht/protocol/test_kbucket.py | 2 +- lbry/tests/unit/dht/protocol/test_protocol.py | 2 +- .../unit/dht/protocol/test_routing_table.py | 2 +- lbry/tests/unit/dht/test_blob_announcer.py | 2 +- lbry/tests/unit/dht/test_node.py | 2 +- lbry/tests/unit/dht/test_peer.py | 2 +- lbry/tests/unit/lbrynet_daemon/test_Daemon.py | 3 +- .../test_exchange_rate_manager.py | 3 +- lbry/tests/unit/stream/test_reflector.py | 2 +- .../unit/stream/test_stream_descriptor.py | 2 +- lbry/tests/unit/stream/test_stream_manager.py | 8 +- lbry/tests/unit/wallet/test_account.py | 2 +- lbry/tests/unit/wallet/test_bip32.py | 2 +- lbry/tests/unit/wallet/test_claim_proofs.py | 2 +- lbry/tests/unit/wallet/test_coinselection.py | 2 +- lbry/tests/unit/wallet/test_database.py | 4 +- lbry/tests/unit/wallet/test_hash.py | 4 +- lbry/tests/unit/wallet/test_headers.py | 4 +- lbry/tests/unit/wallet/test_ledger.py | 2 +- lbry/tests/unit/wallet/test_schema_signing.py | 2 +- .../unit/wallet/test_stream_controller.py | 2 +- lbry/tests/unit/wallet/test_transaction.py | 2 +- lbry/tests/unit/wallet/test_wallet.py | 2 +- lbry/tox.ini | 1 - 49 files changed, 303 insertions(+), 309 deletions(-) delete mode 100644 lbry/lbry/wallet/client/errors.py delete mode 100644 lbry/lbry/wallet/testcase.py diff --git a/lbry/lbry/error/README.md b/lbry/lbry/error/README.md index 034a2032f..3411e40ad 100644 --- a/lbry/lbry/error/README.md +++ b/lbry/lbry/error/README.md @@ -47,7 +47,7 @@ Code | Name | Message 401 | TransactionRejected | Transaction rejected, unknown reason. 402 | TransactionFeeTooLow | Fee too low. 403 | TransactionInvalidSignature | Invalid signature. -404 | InsufficientFunds | Insufficient funds. -- determined by wallet prior to attempting to broadcast a tx; this is different for example from a TX being created and sent but then rejected by lbrycrd for unspendable utxos. +404 | InsufficientFunds | Not enough funds to cover this transaction. -- determined by wallet prior to attempting to broadcast a tx; this is different for example from a TX being created and sent but then rejected by lbrycrd for unspendable utxos. 405 | ChannelKeyNotFound | Channel signing key not found. 406 | ChannelKeyInvalid | Channel signing key is out of date. -- For example, channel was updated but you don't have the updated key. 407 | DataDownload | Failed to download blob. *generic* diff --git a/lbry/lbry/error/__init__.py b/lbry/lbry/error/__init__.py index 59f244092..9791de671 100644 --- a/lbry/lbry/error/__init__.py +++ b/lbry/lbry/error/__init__.py @@ -161,7 +161,7 @@ class InsufficientFundsError(WalletError): """ def __init__(self): - super().__init__("Insufficient funds.") + super().__init__("Not enough funds to cover this transaction.") class ChannelKeyNotFoundError(WalletError): diff --git a/lbry/lbry/testcase.py b/lbry/lbry/testcase.py index 01e6604eb..d5fc574b7 100644 --- a/lbry/lbry/testcase.py +++ b/lbry/lbry/testcase.py @@ -1,18 +1,33 @@ import os +import sys import json import shutil -import tempfile import logging +import tempfile +import functools +import asyncio +from asyncio.runners import _cancel_all_tasks # type: ignore +import unittest +from unittest.case import _Outcome +from typing import Optional from time import time from binascii import unhexlify from functools import partial -from lbry.wallet.testcase import IntegrationTestCase, WalletNode - +import lbry.wallet from lbry.conf import Config -from lbry.extras.daemon.Daemon import Daemon, jsonrpc_dumps_pretty +from lbry.wallet import LbryWalletManager from lbry.wallet.account import Account +from lbry.wallet.orchstr8 import Conductor from lbry.wallet.transaction import Transaction +from lbry.wallet.client.wallet import Wallet +from lbry.wallet.client.util import satoshis_to_coins +from lbry.wallet.orchstr8.node import BlockchainNode, WalletNode +from lbry.wallet.client.baseledger import BaseLedger +from lbry.wallet.client.baseaccount import BaseAccount +from lbry.wallet.client.basemanager import BaseWalletManager + +from lbry.extras.daemon.Daemon import Daemon, jsonrpc_dumps_pretty from lbry.extras.daemon.Components import Component, WalletComponent from lbry.extras.daemon.Components import ( DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, @@ -28,6 +43,236 @@ from lbry.stream.reflector.server import ReflectorServer from lbry.blob_exchange.server import BlobServer +class ColorHandler(logging.StreamHandler): + + level_color = { + logging.DEBUG: "black", + logging.INFO: "light_gray", + logging.WARNING: "yellow", + logging.ERROR: "red" + } + + color_code = dict( + black=30, + red=31, + green=32, + yellow=33, + blue=34, + magenta=35, + cyan=36, + white=37, + light_gray='0;37', + dark_gray='1;30' + ) + + def emit(self, record): + try: + msg = self.format(record) + color_name = self.level_color.get(record.levelno, "black") + color_code = self.color_code[color_name] + stream = self.stream + stream.write(f'\x1b[{color_code}m{msg}\x1b[0m') + stream.write(self.terminator) + self.flush() + except Exception: + self.handleError(record) + + +HANDLER = ColorHandler(sys.stdout) +HANDLER.setFormatter( + logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +) +logging.getLogger().addHandler(HANDLER) + + +class AsyncioTestCase(unittest.TestCase): + # Implementation inspired by discussion: + # https://bugs.python.org/issue32972 + + LOOP_SLOW_CALLBACK_DURATION = 0.2 + + maxDiff = None + + async def asyncSetUp(self): # pylint: disable=C0103 + pass + + async def asyncTearDown(self): # pylint: disable=C0103 + pass + + def run(self, result=None): # pylint: disable=R0915 + orig_result = result + if result is None: + result = self.defaultTestResult() + startTestRun = getattr(result, 'startTestRun', None) # pylint: disable=C0103 + if startTestRun is not None: + startTestRun() + + result.startTest(self) + + testMethod = getattr(self, self._testMethodName) # pylint: disable=C0103 + if (getattr(self.__class__, "__unittest_skip__", False) or + getattr(testMethod, "__unittest_skip__", False)): + # If the class or method was skipped. + try: + skip_why = (getattr(self.__class__, '__unittest_skip_why__', '') + or getattr(testMethod, '__unittest_skip_why__', '')) + self._addSkip(result, self, skip_why) + finally: + result.stopTest(self) + return + expecting_failure_method = getattr(testMethod, + "__unittest_expecting_failure__", False) + expecting_failure_class = getattr(self, + "__unittest_expecting_failure__", False) + expecting_failure = expecting_failure_class or expecting_failure_method + outcome = _Outcome(result) + + self.loop = asyncio.new_event_loop() # pylint: disable=W0201 + asyncio.set_event_loop(self.loop) + self.loop.set_debug(True) + self.loop.slow_callback_duration = self.LOOP_SLOW_CALLBACK_DURATION + + try: + self._outcome = outcome + + with outcome.testPartExecutor(self): + self.setUp() + self.loop.run_until_complete(self.asyncSetUp()) + if outcome.success: + outcome.expecting_failure = expecting_failure + with outcome.testPartExecutor(self, isTest=True): + maybe_coroutine = testMethod() + if asyncio.iscoroutine(maybe_coroutine): + self.loop.run_until_complete(maybe_coroutine) + outcome.expecting_failure = False + with outcome.testPartExecutor(self): + self.loop.run_until_complete(self.asyncTearDown()) + self.tearDown() + + self.doAsyncCleanups() + + try: + _cancel_all_tasks(self.loop) + self.loop.run_until_complete(self.loop.shutdown_asyncgens()) + finally: + asyncio.set_event_loop(None) + self.loop.close() + + for test, reason in outcome.skipped: + self._addSkip(result, test, reason) + self._feedErrorsToResult(result, outcome.errors) + if outcome.success: + if expecting_failure: + if outcome.expectedFailure: + self._addExpectedFailure(result, outcome.expectedFailure) + else: + self._addUnexpectedSuccess(result) + else: + result.addSuccess(self) + return result + finally: + result.stopTest(self) + if orig_result is None: + stopTestRun = getattr(result, 'stopTestRun', None) # pylint: disable=C0103 + if stopTestRun is not None: + stopTestRun() # pylint: disable=E1102 + + # explicitly break reference cycles: + # outcome.errors -> frame -> outcome -> outcome.errors + # outcome.expectedFailure -> frame -> outcome -> outcome.expectedFailure + outcome.errors.clear() + outcome.expectedFailure = None + + # clear the outcome, no more needed + self._outcome = None + + def doAsyncCleanups(self): # pylint: disable=C0103 + outcome = self._outcome or _Outcome() + while self._cleanups: + function, args, kwargs = self._cleanups.pop() + with outcome.testPartExecutor(self): + maybe_coroutine = function(*args, **kwargs) + if asyncio.iscoroutine(maybe_coroutine): + self.loop.run_until_complete(maybe_coroutine) + + +class AdvanceTimeTestCase(AsyncioTestCase): + + async def asyncSetUp(self): + self._time = 0 # pylint: disable=W0201 + self.loop.time = functools.wraps(self.loop.time)(lambda: self._time) + await super().asyncSetUp() + + async def advance(self, seconds): + while self.loop._ready: + await asyncio.sleep(0) + self._time += seconds + await asyncio.sleep(0) + while self.loop._ready: + await asyncio.sleep(0) + + +class IntegrationTestCase(AsyncioTestCase): + + SEED = None + LEDGER = lbry.wallet + MANAGER = LbryWalletManager + ENABLE_SEGWIT = False + VERBOSITY = logging.WARN + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.conductor: Optional[Conductor] = None + self.blockchain: Optional[BlockchainNode] = None + self.wallet_node: Optional[WalletNode] = None + self.manager: Optional[BaseWalletManager] = None + self.ledger: Optional[BaseLedger] = None + self.wallet: Optional[Wallet] = None + self.account: Optional[BaseAccount] = None + + async def asyncSetUp(self): + self.conductor = Conductor( + ledger_module=self.LEDGER, manager_module=self.MANAGER, verbosity=self.VERBOSITY, + enable_segwit=self.ENABLE_SEGWIT, seed=self.SEED + ) + await self.conductor.start_blockchain() + self.addCleanup(self.conductor.stop_blockchain) + await self.conductor.start_spv() + self.addCleanup(self.conductor.stop_spv) + await self.conductor.start_wallet() + self.addCleanup(self.conductor.stop_wallet) + self.blockchain = self.conductor.blockchain_node + self.wallet_node = self.conductor.wallet_node + self.manager = self.wallet_node.manager + self.ledger = self.wallet_node.ledger + self.wallet = self.wallet_node.wallet + self.account = self.wallet_node.wallet.default_account + + async def assertBalance(self, account, expected_balance: str): # pylint: disable=C0103 + balance = await account.get_balance() + self.assertEqual(satoshis_to_coins(balance), expected_balance) + + def broadcast(self, tx): + return self.ledger.broadcast(tx) + + async def on_header(self, height): + if self.ledger.headers.height < height: + await self.ledger.on_header.where( + lambda e: e.height == height + ) + return True + + def on_transaction_id(self, txid, ledger=None): + return (ledger or self.ledger).on_transaction.where( + lambda e: e.tx.id == txid + ) + + def on_transaction_address(self, tx, address): + return self.ledger.on_transaction.where( + lambda e: e.tx.id == tx.id and e.address == address + ) + + class FakeExchangeRateManager(ExchangeRateManager): def __init__(self, market_feeds, rates): diff --git a/lbry/lbry/wallet/claim_proofs.py b/lbry/lbry/wallet/claim_proofs.py index 5ebd4f216..64692c24a 100644 --- a/lbry/lbry/wallet/claim_proofs.py +++ b/lbry/lbry/wallet/claim_proofs.py @@ -1,6 +1,6 @@ import struct import binascii -from lbry.wallet.client.hash import double_sha256 +from lbry.crypto.hash import double_sha256 class InvalidProofError(Exception): diff --git a/lbry/lbry/wallet/client/basetransaction.py b/lbry/lbry/wallet/client/basetransaction.py index 7b38b2e52..8429d641a 100644 --- a/lbry/lbry/wallet/client/basetransaction.py +++ b/lbry/lbry/wallet/client/basetransaction.py @@ -10,7 +10,7 @@ from lbry.wallet.client.constants import COIN, NULL_HASH32 from lbry.wallet.client.bcd_data_stream import BCDataStream from lbry.wallet.client.hash import TXRef, TXRefImmutable from lbry.wallet.client.util import ReadOnlyList -from lbry.wallet.client.errors import InsufficientFundsError +from lbry.error import InsufficientFundsError if typing.TYPE_CHECKING: from lbry.wallet.client import baseledger, wallet as basewallet @@ -514,7 +514,7 @@ class BaseTransaction: deficit = cost - payment spendables = await ledger.get_spendable_utxos(deficit, funding_accounts) if not spendables: - raise InsufficientFundsError('Not enough funds to cover this transaction.') + raise InsufficientFundsError() payment += sum(s.effective_amount for s in spendables) tx.add_inputs(s.txi for s in spendables) diff --git a/lbry/lbry/wallet/client/errors.py b/lbry/lbry/wallet/client/errors.py deleted file mode 100644 index cd290cf05..000000000 --- a/lbry/lbry/wallet/client/errors.py +++ /dev/null @@ -1,2 +0,0 @@ -class InsufficientFundsError(Exception): - pass diff --git a/lbry/lbry/wallet/testcase.py b/lbry/lbry/wallet/testcase.py deleted file mode 100644 index e48711c7b..000000000 --- a/lbry/lbry/wallet/testcase.py +++ /dev/null @@ -1,248 +0,0 @@ -import sys -import logging -import functools -import asyncio -from asyncio.runners import _cancel_all_tasks # type: ignore -import unittest -from unittest.case import _Outcome -from typing import Optional - -import lbry.wallet -from lbry.wallet.orchstr8 import Conductor -from lbry.wallet.orchstr8.node import BlockchainNode, WalletNode -from lbry.wallet.client.baseledger import BaseLedger -from lbry.wallet.client.baseaccount import BaseAccount -from lbry.wallet.client.basemanager import BaseWalletManager -from lbry.wallet.client.wallet import Wallet -from lbry.wallet.client.util import satoshis_to_coins -from lbry.wallet import LbryWalletManager - - -class ColorHandler(logging.StreamHandler): - - level_color = { - logging.DEBUG: "black", - logging.INFO: "light_gray", - logging.WARNING: "yellow", - logging.ERROR: "red" - } - - color_code = dict( - black=30, - red=31, - green=32, - yellow=33, - blue=34, - magenta=35, - cyan=36, - white=37, - light_gray='0;37', - dark_gray='1;30' - ) - - def emit(self, record): - try: - msg = self.format(record) - color_name = self.level_color.get(record.levelno, "black") - color_code = self.color_code[color_name] - stream = self.stream - stream.write(f'\x1b[{color_code}m{msg}\x1b[0m') - stream.write(self.terminator) - self.flush() - except Exception: - self.handleError(record) - - -HANDLER = ColorHandler(sys.stdout) -HANDLER.setFormatter( - logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') -) -logging.getLogger().addHandler(HANDLER) - - -class AsyncioTestCase(unittest.TestCase): - # Implementation inspired by discussion: - # https://bugs.python.org/issue32972 - - LOOP_SLOW_CALLBACK_DURATION = 0.2 - - maxDiff = None - - async def asyncSetUp(self): # pylint: disable=C0103 - pass - - async def asyncTearDown(self): # pylint: disable=C0103 - pass - - def run(self, result=None): # pylint: disable=R0915 - orig_result = result - if result is None: - result = self.defaultTestResult() - startTestRun = getattr(result, 'startTestRun', None) # pylint: disable=C0103 - if startTestRun is not None: - startTestRun() - - result.startTest(self) - - testMethod = getattr(self, self._testMethodName) # pylint: disable=C0103 - if (getattr(self.__class__, "__unittest_skip__", False) or - getattr(testMethod, "__unittest_skip__", False)): - # If the class or method was skipped. - try: - skip_why = (getattr(self.__class__, '__unittest_skip_why__', '') - or getattr(testMethod, '__unittest_skip_why__', '')) - self._addSkip(result, self, skip_why) - finally: - result.stopTest(self) - return - expecting_failure_method = getattr(testMethod, - "__unittest_expecting_failure__", False) - expecting_failure_class = getattr(self, - "__unittest_expecting_failure__", False) - expecting_failure = expecting_failure_class or expecting_failure_method - outcome = _Outcome(result) - - self.loop = asyncio.new_event_loop() # pylint: disable=W0201 - asyncio.set_event_loop(self.loop) - self.loop.set_debug(True) - self.loop.slow_callback_duration = self.LOOP_SLOW_CALLBACK_DURATION - - try: - self._outcome = outcome - - with outcome.testPartExecutor(self): - self.setUp() - self.loop.run_until_complete(self.asyncSetUp()) - if outcome.success: - outcome.expecting_failure = expecting_failure - with outcome.testPartExecutor(self, isTest=True): - maybe_coroutine = testMethod() - if asyncio.iscoroutine(maybe_coroutine): - self.loop.run_until_complete(maybe_coroutine) - outcome.expecting_failure = False - with outcome.testPartExecutor(self): - self.loop.run_until_complete(self.asyncTearDown()) - self.tearDown() - - self.doAsyncCleanups() - - try: - _cancel_all_tasks(self.loop) - self.loop.run_until_complete(self.loop.shutdown_asyncgens()) - finally: - asyncio.set_event_loop(None) - self.loop.close() - - for test, reason in outcome.skipped: - self._addSkip(result, test, reason) - self._feedErrorsToResult(result, outcome.errors) - if outcome.success: - if expecting_failure: - if outcome.expectedFailure: - self._addExpectedFailure(result, outcome.expectedFailure) - else: - self._addUnexpectedSuccess(result) - else: - result.addSuccess(self) - return result - finally: - result.stopTest(self) - if orig_result is None: - stopTestRun = getattr(result, 'stopTestRun', None) # pylint: disable=C0103 - if stopTestRun is not None: - stopTestRun() # pylint: disable=E1102 - - # explicitly break reference cycles: - # outcome.errors -> frame -> outcome -> outcome.errors - # outcome.expectedFailure -> frame -> outcome -> outcome.expectedFailure - outcome.errors.clear() - outcome.expectedFailure = None - - # clear the outcome, no more needed - self._outcome = None - - def doAsyncCleanups(self): # pylint: disable=C0103 - outcome = self._outcome or _Outcome() - while self._cleanups: - function, args, kwargs = self._cleanups.pop() - with outcome.testPartExecutor(self): - maybe_coroutine = function(*args, **kwargs) - if asyncio.iscoroutine(maybe_coroutine): - self.loop.run_until_complete(maybe_coroutine) - - -class AdvanceTimeTestCase(AsyncioTestCase): - - async def asyncSetUp(self): - self._time = 0 # pylint: disable=W0201 - self.loop.time = functools.wraps(self.loop.time)(lambda: self._time) - await super().asyncSetUp() - - async def advance(self, seconds): - while self.loop._ready: - await asyncio.sleep(0) - self._time += seconds - await asyncio.sleep(0) - while self.loop._ready: - await asyncio.sleep(0) - - -class IntegrationTestCase(AsyncioTestCase): - - SEED = None - LEDGER = lbry.wallet - MANAGER = LbryWalletManager - ENABLE_SEGWIT = False - VERBOSITY = logging.WARN - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.conductor: Optional[Conductor] = None - self.blockchain: Optional[BlockchainNode] = None - self.wallet_node: Optional[WalletNode] = None - self.manager: Optional[BaseWalletManager] = None - self.ledger: Optional[BaseLedger] = None - self.wallet: Optional[Wallet] = None - self.account: Optional[BaseAccount] = None - - async def asyncSetUp(self): - self.conductor = Conductor( - ledger_module=self.LEDGER, manager_module=self.MANAGER, verbosity=self.VERBOSITY, - enable_segwit=self.ENABLE_SEGWIT, seed=self.SEED - ) - await self.conductor.start_blockchain() - self.addCleanup(self.conductor.stop_blockchain) - await self.conductor.start_spv() - self.addCleanup(self.conductor.stop_spv) - await self.conductor.start_wallet() - self.addCleanup(self.conductor.stop_wallet) - self.blockchain = self.conductor.blockchain_node - self.wallet_node = self.conductor.wallet_node - self.manager = self.wallet_node.manager - self.ledger = self.wallet_node.ledger - self.wallet = self.wallet_node.wallet - self.account = self.wallet_node.wallet.default_account - - async def assertBalance(self, account, expected_balance: str): # pylint: disable=C0103 - balance = await account.get_balance() - self.assertEqual(satoshis_to_coins(balance), expected_balance) - - def broadcast(self, tx): - return self.ledger.broadcast(tx) - - async def on_header(self, height): - if self.ledger.headers.height < height: - await self.ledger.on_header.where( - lambda e: e.height == height - ) - return True - - def on_transaction_id(self, txid, ledger=None): - return (ledger or self.ledger).on_transaction.where( - lambda e: e.tx.id == txid - ) - - def on_transaction_address(self, tx, address): - return self.ledger.on_transaction.where( - lambda e: e.tx.id == tx.id and e.address == address - ) diff --git a/lbry/setup.py b/lbry/setup.py index 904f9b46c..b6c9f7a7c 100644 --- a/lbry/setup.py +++ b/lbry/setup.py @@ -28,7 +28,7 @@ setup( entry_points={ 'console_scripts': [ 'lbrynet=lbry.extras.cli:main', - 'torba-server=torba.server.cli:main', + 'torba-server=lbry.wallet.server.cli:main', ], }, install_requires=[ diff --git a/lbry/tests/integration/test_blockchain_reorganization.py b/lbry/tests/integration/test_blockchain_reorganization.py index 2205aa84f..6aabb09fd 100644 --- a/lbry/tests/integration/test_blockchain_reorganization.py +++ b/lbry/tests/integration/test_blockchain_reorganization.py @@ -1,5 +1,5 @@ import logging -from lbry.wallet.testcase import IntegrationTestCase +from lbry.testcase import IntegrationTestCase class BlockchainReorganizationTests(IntegrationTestCase): diff --git a/lbry/tests/integration/test_claim_commands.py b/lbry/tests/integration/test_claim_commands.py index c70455822..174809a5a 100644 --- a/lbry/tests/integration/test_claim_commands.py +++ b/lbry/tests/integration/test_claim_commands.py @@ -5,7 +5,7 @@ from binascii import unhexlify from urllib.request import urlopen -from lbry.wallet.client.errors import InsufficientFundsError +from lbry.error import InsufficientFundsError from lbry.extras.daemon.Daemon import DEFAULT_PAGE_SIZE from lbry.testcase import CommandTestCase diff --git a/lbry/tests/integration/test_cli.py b/lbry/tests/integration/test_cli.py index 7638711fa..e363842ca 100644 --- a/lbry/tests/integration/test_cli.py +++ b/lbry/tests/integration/test_cli.py @@ -1,6 +1,6 @@ import contextlib from io import StringIO -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.conf import Config from lbry.extras import cli diff --git a/lbry/tests/integration/test_dht.py b/lbry/tests/integration/test_dht.py index e6412de5c..bf6884f3a 100644 --- a/lbry/tests/integration/test_dht.py +++ b/lbry/tests/integration/test_dht.py @@ -7,7 +7,7 @@ from lbry.dht import constants from lbry.dht.node import Node from lbry.dht import peer as dht_peer from lbry.dht.peer import PeerManager, make_kademlia_peer -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase class DHTIntegrationTest(AsyncioTestCase): diff --git a/lbry/tests/integration/test_exchange_rate_manager.py b/lbry/tests/integration/test_exchange_rate_manager.py index d0c489967..30a753d17 100644 --- a/lbry/tests/integration/test_exchange_rate_manager.py +++ b/lbry/tests/integration/test_exchange_rate_manager.py @@ -1,5 +1,5 @@ from decimal import Decimal -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.extras.daemon.exchange_rate_manager import ExchangeRate, ExchangeRateManager diff --git a/lbry/tests/integration/test_internal_transaction_api.py b/lbry/tests/integration/test_internal_transaction_api.py index 1f016f3b9..f71522380 100644 --- a/lbry/tests/integration/test_internal_transaction_api.py +++ b/lbry/tests/integration/test_internal_transaction_api.py @@ -1,6 +1,6 @@ import asyncio -from lbry.wallet.testcase import IntegrationTestCase +from lbry.testcase import IntegrationTestCase import lbry.wallet from lbry.schema.claim import Claim diff --git a/lbry/tests/integration/test_network.py b/lbry/tests/integration/test_network.py index 1e8bbdca9..3fb0f77c5 100644 --- a/lbry/tests/integration/test_network.py +++ b/lbry/tests/integration/test_network.py @@ -8,7 +8,7 @@ from unittest.mock import Mock from lbry.wallet.client.basenetwork import BaseNetwork from lbry.wallet.orchstr8.node import SPVNode from lbry.wallet.rpc import RPCSession -from lbry.wallet.testcase import IntegrationTestCase, AsyncioTestCase +from lbry.testcase import IntegrationTestCase, AsyncioTestCase class NetworkTests(IntegrationTestCase): diff --git a/lbry/tests/integration/test_resolve_command.py b/lbry/tests/integration/test_resolve_command.py index a9f27bc8e..ba43b3b23 100644 --- a/lbry/tests/integration/test_resolve_command.py +++ b/lbry/tests/integration/test_resolve_command.py @@ -5,7 +5,8 @@ from binascii import hexlify, unhexlify from lbry.testcase import CommandTestCase from lbry.wallet.transaction import Transaction, Output from lbry.schema.compat import OldClaimMessage -from lbry.wallet.client.hash import sha256, Base58 +from lbry.crypto.hash import sha256 +from lbry.crypto.base58 import Base58 class BaseResolveTestCase(CommandTestCase): diff --git a/lbry/tests/integration/test_transactions.py b/lbry/tests/integration/test_transactions.py index be96ae9be..0fd7a6db0 100644 --- a/lbry/tests/integration/test_transactions.py +++ b/lbry/tests/integration/test_transactions.py @@ -1,10 +1,9 @@ -import logging import asyncio import random from itertools import chain from lbry.wallet.transaction import Transaction, Output, Input -from lbry.wallet.testcase import IntegrationTestCase +from lbry.testcase import IntegrationTestCase from lbry.wallet.client.util import satoshis_to_coins, coins_to_satoshis diff --git a/lbry/tests/unit/analytics/test_track.py b/lbry/tests/unit/analytics/test_track.py index e5164e28c..020bf7bc9 100644 --- a/lbry/tests/unit/analytics/test_track.py +++ b/lbry/tests/unit/analytics/test_track.py @@ -1,3 +1,4 @@ +import lbry.wallet from lbry.extras.daemon import analytics import unittest diff --git a/lbry/tests/unit/blob/test_blob_file.py b/lbry/tests/unit/blob/test_blob_file.py index daadca847..ba7923002 100644 --- a/lbry/tests/unit/blob/test_blob_file.py +++ b/lbry/tests/unit/blob/test_blob_file.py @@ -2,7 +2,7 @@ import asyncio import tempfile import shutil import os -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.error import InvalidDataError, InvalidBlobHashError from lbry.conf import Config from lbry.extras.daemon.storage import SQLiteStorage diff --git a/lbry/tests/unit/blob/test_blob_manager.py b/lbry/tests/unit/blob/test_blob_manager.py index eabcbb625..c868890f1 100644 --- a/lbry/tests/unit/blob/test_blob_manager.py +++ b/lbry/tests/unit/blob/test_blob_manager.py @@ -1,8 +1,7 @@ -import asyncio import tempfile import shutil import os -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.conf import Config from lbry.extras.daemon.storage import SQLiteStorage from lbry.blob.blob_manager import BlobManager diff --git a/lbry/tests/unit/blob_exchange/test_transfer_blob.py b/lbry/tests/unit/blob_exchange/test_transfer_blob.py index 9a3775ab4..28a414996 100644 --- a/lbry/tests/unit/blob_exchange/test_transfer_blob.py +++ b/lbry/tests/unit/blob_exchange/test_transfer_blob.py @@ -6,7 +6,7 @@ import shutil import os from lbry.blob_exchange.serialization import BlobRequest -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.conf import Config from lbry.extras.daemon.storage import SQLiteStorage from lbry.blob.blob_manager import BlobManager diff --git a/lbry/tests/unit/comments/test_comment_signing.py b/lbry/tests/unit/comments/test_comment_signing.py index d9fefe92f..9cdfd3d69 100644 --- a/lbry/tests/unit/comments/test_comment_signing.py +++ b/lbry/tests/unit/comments/test_comment_signing.py @@ -1,4 +1,4 @@ -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase import hashlib from lbry.extras.daemon.comment_client import sign_comment from lbry.extras.daemon.comment_client import is_comment_signed_by_channel diff --git a/lbry/tests/unit/components/test_component_manager.py b/lbry/tests/unit/components/test_component_manager.py index a6654363c..d87194133 100644 --- a/lbry/tests/unit/components/test_component_manager.py +++ b/lbry/tests/unit/components/test_component_manager.py @@ -1,5 +1,5 @@ import asyncio -from torba.testcase import AsyncioTestCase, AdvanceTimeTestCase +from lbry.testcase import AsyncioTestCase, AdvanceTimeTestCase from lbry.conf import Config from lbry.extras.daemon.ComponentManager import ComponentManager diff --git a/lbry/tests/unit/core/test_utils.py b/lbry/tests/unit/core/test_utils.py index a1942149c..1246e3995 100644 --- a/lbry/tests/unit/core/test_utils.py +++ b/lbry/tests/unit/core/test_utils.py @@ -1,7 +1,7 @@ import unittest import asyncio from lbry import utils -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase class CompareVersionTest(unittest.TestCase): diff --git a/lbry/tests/unit/database/test_SQLiteStorage.py b/lbry/tests/unit/database/test_SQLiteStorage.py index ab63512e7..07063aa7f 100644 --- a/lbry/tests/unit/database/test_SQLiteStorage.py +++ b/lbry/tests/unit/database/test_SQLiteStorage.py @@ -4,7 +4,7 @@ import unittest import asyncio import logging import hashlib -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.conf import Config from lbry.extras.daemon.storage import SQLiteStorage from lbry.blob.blob_info import BlobInfo diff --git a/lbry/tests/unit/dht/protocol/test_kbucket.py b/lbry/tests/unit/dht/protocol/test_kbucket.py index d6b42b33b..0063d51bd 100644 --- a/lbry/tests/unit/dht/protocol/test_kbucket.py +++ b/lbry/tests/unit/dht/protocol/test_kbucket.py @@ -4,7 +4,7 @@ from lbry.utils import generate_id from lbry.dht.protocol.routing_table import KBucket from lbry.dht.peer import PeerManager, make_kademlia_peer from lbry.dht import constants -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase def address_generator(address=(1, 2, 3, 4)): diff --git a/lbry/tests/unit/dht/protocol/test_protocol.py b/lbry/tests/unit/dht/protocol/test_protocol.py index 97303a2b4..e5a3f480e 100644 --- a/lbry/tests/unit/dht/protocol/test_protocol.py +++ b/lbry/tests/unit/dht/protocol/test_protocol.py @@ -1,6 +1,6 @@ import asyncio import binascii -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from tests import dht_mocks from lbry.dht.serialization.bencoding import bencode, bdecode from lbry.dht import constants diff --git a/lbry/tests/unit/dht/protocol/test_routing_table.py b/lbry/tests/unit/dht/protocol/test_routing_table.py index 0abc86d64..9ea21417b 100644 --- a/lbry/tests/unit/dht/protocol/test_routing_table.py +++ b/lbry/tests/unit/dht/protocol/test_routing_table.py @@ -1,5 +1,5 @@ import asyncio -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from tests import dht_mocks from lbry.dht import constants from lbry.dht.node import Node diff --git a/lbry/tests/unit/dht/test_blob_announcer.py b/lbry/tests/unit/dht/test_blob_announcer.py index 13a21249b..34be7c9aa 100644 --- a/lbry/tests/unit/dht/test_blob_announcer.py +++ b/lbry/tests/unit/dht/test_blob_announcer.py @@ -3,7 +3,7 @@ import typing import binascii import socket import asyncio -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from tests import dht_mocks from lbry.conf import Config from lbry.dht import constants diff --git a/lbry/tests/unit/dht/test_node.py b/lbry/tests/unit/dht/test_node.py index 9bf0e9c76..4ce7e7e59 100644 --- a/lbry/tests/unit/dht/test_node.py +++ b/lbry/tests/unit/dht/test_node.py @@ -1,7 +1,7 @@ import asyncio import unittest import typing -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from tests import dht_mocks from lbry.conf import Config from lbry.dht import constants diff --git a/lbry/tests/unit/dht/test_peer.py b/lbry/tests/unit/dht/test_peer.py index cd4c53436..8bf5d70a9 100644 --- a/lbry/tests/unit/dht/test_peer.py +++ b/lbry/tests/unit/dht/test_peer.py @@ -2,7 +2,7 @@ import asyncio import unittest from lbry.utils import generate_id from lbry.dht.peer import PeerManager, make_kademlia_peer -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase class PeerTest(AsyncioTestCase): diff --git a/lbry/tests/unit/lbrynet_daemon/test_Daemon.py b/lbry/tests/unit/lbrynet_daemon/test_Daemon.py index b3709caca..d247f6900 100644 --- a/lbry/tests/unit/lbrynet_daemon/test_Daemon.py +++ b/lbry/tests/unit/lbrynet_daemon/test_Daemon.py @@ -2,6 +2,7 @@ import unittest from unittest import mock import json +import lbry.wallet from lbry.conf import Config from lbry.extras.daemon.storage import SQLiteStorage from lbry.extras.daemon.ComponentManager import ComponentManager @@ -11,7 +12,7 @@ from lbry.extras.daemon.Components import UPNP_COMPONENT, BLOB_COMPONENT from lbry.extras.daemon.Components import PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT from lbry.extras.daemon.Daemon import Daemon as LBRYDaemon from lbry.wallet import LbryWalletManager -from torba.client.wallet import Wallet +from lbry.wallet.client.wallet import Wallet from tests import test_utils # from tests.mocks import mock_conf_settings, FakeNetwork, FakeFileManager diff --git a/lbry/tests/unit/lbrynet_daemon/test_exchange_rate_manager.py b/lbry/tests/unit/lbrynet_daemon/test_exchange_rate_manager.py index 65bd5afb8..3a88436f1 100644 --- a/lbry/tests/unit/lbrynet_daemon/test_exchange_rate_manager.py +++ b/lbry/tests/unit/lbrynet_daemon/test_exchange_rate_manager.py @@ -8,8 +8,7 @@ from lbry.extras.daemon.exchange_rate_manager import ( CryptonatorFeed, CryptonatorBTCFeed, BittrexFeed, ) -from torba.testcase import AsyncioTestCase -from lbry.testcase import FakeExchangeRateManager, get_fake_exchange_rate_manager +from lbry.testcase import AsyncioTestCase, FakeExchangeRateManager, get_fake_exchange_rate_manager from lbry.error import InvalidExchangeRateResponseError diff --git a/lbry/tests/unit/stream/test_reflector.py b/lbry/tests/unit/stream/test_reflector.py index 73ec39b47..8c228f92c 100644 --- a/lbry/tests/unit/stream/test_reflector.py +++ b/lbry/tests/unit/stream/test_reflector.py @@ -2,7 +2,7 @@ import os import asyncio import tempfile import shutil -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.conf import Config from lbry.extras.daemon.storage import SQLiteStorage from lbry.blob.blob_manager import BlobManager diff --git a/lbry/tests/unit/stream/test_stream_descriptor.py b/lbry/tests/unit/stream/test_stream_descriptor.py index 7536926e9..b46012711 100644 --- a/lbry/tests/unit/stream/test_stream_descriptor.py +++ b/lbry/tests/unit/stream/test_stream_descriptor.py @@ -5,7 +5,7 @@ import shutil import json from lbry.blob.blob_file import BlobFile -from torba.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.conf import Config from lbry.error import InvalidStreamDescriptorError from lbry.extras.daemon.storage import SQLiteStorage diff --git a/lbry/tests/unit/stream/test_stream_manager.py b/lbry/tests/unit/stream/test_stream_manager.py index ccf30652e..d34fa8159 100644 --- a/lbry/tests/unit/stream/test_stream_manager.py +++ b/lbry/tests/unit/stream/test_stream_manager.py @@ -8,11 +8,11 @@ from decimal import Decimal from tests.unit.blob_exchange.test_transfer_blob import BlobExchangeTestBase from lbry.testcase import get_fake_exchange_rate_manager from lbry.utils import generate_id -from torba.client.errors import InsufficientFundsError +from lbry.error import InsufficientFundsError from lbry.error import KeyFeeAboveMaxAllowedError, ResolveError, DownloadSDTimeoutError, DownloadDataTimeoutError -from torba.client.wallet import Wallet -from torba.client.constants import CENT, NULL_HASH32 -from torba.client.basenetwork import ClientSession +from lbry.wallet.client.wallet import Wallet +from lbry.wallet.client.constants import CENT, NULL_HASH32 +from lbry.wallet.client.basenetwork import ClientSession from lbry.conf import Config from lbry.wallet.ledger import MainNetLedger from lbry.wallet.transaction import Transaction, Input, Output diff --git a/lbry/tests/unit/wallet/test_account.py b/lbry/tests/unit/wallet/test_account.py index 1c6c243d6..b07e56dec 100644 --- a/lbry/tests/unit/wallet/test_account.py +++ b/lbry/tests/unit/wallet/test_account.py @@ -1,5 +1,5 @@ from binascii import hexlify -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.wallet.client.wallet import Wallet from lbry.wallet.ledger import MainNetLedger, WalletDatabase from lbry.wallet.header import Headers diff --git a/lbry/tests/unit/wallet/test_bip32.py b/lbry/tests/unit/wallet/test_bip32.py index 55a72577c..87c804b01 100644 --- a/lbry/tests/unit/wallet/test_bip32.py +++ b/lbry/tests/unit/wallet/test_bip32.py @@ -1,6 +1,6 @@ from binascii import unhexlify, hexlify -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from tests.unit.wallet.key_fixtures import expected_ids, expected_privkeys, expected_hardened_privkeys from lbry.wallet.client.bip32 import PubKey, PrivateKey, from_extended_key_string diff --git a/lbry/tests/unit/wallet/test_claim_proofs.py b/lbry/tests/unit/wallet/test_claim_proofs.py index f8fcca887..e393043f0 100644 --- a/lbry/tests/unit/wallet/test_claim_proofs.py +++ b/lbry/tests/unit/wallet/test_claim_proofs.py @@ -2,7 +2,7 @@ import unittest from binascii import hexlify, unhexlify from lbry.wallet.claim_proofs import get_hash_for_outpoint, verify_proof -from lbry.wallet.client.hash import double_sha256 +from lbry.crypto.hash import double_sha256 class ClaimProofsTestCase(unittest.TestCase): diff --git a/lbry/tests/unit/wallet/test_coinselection.py b/lbry/tests/unit/wallet/test_coinselection.py index 31874ea20..237a407be 100644 --- a/lbry/tests/unit/wallet/test_coinselection.py +++ b/lbry/tests/unit/wallet/test_coinselection.py @@ -1,6 +1,6 @@ from types import GeneratorType -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.wallet import MainNetLedger as ledger_class from lbry.wallet.client.coinselection import CoinSelector, MAXIMUM_TRIES diff --git a/lbry/tests/unit/wallet/test_database.py b/lbry/tests/unit/wallet/test_database.py index 85bf41b50..ba4809dd4 100644 --- a/lbry/tests/unit/wallet/test_database.py +++ b/lbry/tests/unit/wallet/test_database.py @@ -11,8 +11,8 @@ from lbry.wallet.transaction import Transaction from lbry.wallet.client.wallet import Wallet from lbry.wallet.client.constants import COIN from lbry.wallet.client.basedatabase import query, interpolate, constraints_to_sql, AIOSQLite -from lbry.wallet.client.hash import sha256 -from lbry.wallet.testcase import AsyncioTestCase +from lbry.crypto.hash import sha256 +from lbry.testcase import AsyncioTestCase from tests.unit.wallet.test_transaction import get_output, NULL_HASH diff --git a/lbry/tests/unit/wallet/test_hash.py b/lbry/tests/unit/wallet/test_hash.py index 30239a33f..0a09ea1e6 100644 --- a/lbry/tests/unit/wallet/test_hash.py +++ b/lbry/tests/unit/wallet/test_hash.py @@ -1,6 +1,6 @@ from unittest import TestCase, mock -from lbry.wallet.client.hash import aes_decrypt, aes_encrypt, better_aes_decrypt, better_aes_encrypt -from lbry.wallet.client.errors import InvalidPasswordError +from lbry.crypto.crypt import aes_decrypt, aes_encrypt, better_aes_decrypt, better_aes_encrypt +from lbry.error import InvalidPasswordError class TestAESEncryptDecrypt(TestCase): diff --git a/lbry/tests/unit/wallet/test_headers.py b/lbry/tests/unit/wallet/test_headers.py index 63c7233f0..3213146a8 100644 --- a/lbry/tests/unit/wallet/test_headers.py +++ b/lbry/tests/unit/wallet/test_headers.py @@ -3,9 +3,9 @@ import asyncio import tempfile from binascii import hexlify, unhexlify -from lbry.wallet.client.hash import sha256 +from lbry.crypto.hash import sha256 from lbry.wallet.client.util import ArithUint256 -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.wallet.ledger import Headers diff --git a/lbry/tests/unit/wallet/test_ledger.py b/lbry/tests/unit/wallet/test_ledger.py index a764fff8a..ac9e1e206 100644 --- a/lbry/tests/unit/wallet/test_ledger.py +++ b/lbry/tests/unit/wallet/test_ledger.py @@ -1,7 +1,7 @@ import os from binascii import hexlify -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.wallet.client.wallet import Wallet from lbry.wallet.account import Account from lbry.wallet.transaction import Transaction, Output, Input diff --git a/lbry/tests/unit/wallet/test_schema_signing.py b/lbry/tests/unit/wallet/test_schema_signing.py index e5a8d3026..5fc72f6ff 100644 --- a/lbry/tests/unit/wallet/test_schema_signing.py +++ b/lbry/tests/unit/wallet/test_schema_signing.py @@ -1,6 +1,6 @@ from binascii import unhexlify -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.wallet.client.constants import CENT, NULL_HASH32 from lbry.wallet.ledger import MainNetLedger diff --git a/lbry/tests/unit/wallet/test_stream_controller.py b/lbry/tests/unit/wallet/test_stream_controller.py index 59f534b4b..4cd11e64a 100644 --- a/lbry/tests/unit/wallet/test_stream_controller.py +++ b/lbry/tests/unit/wallet/test_stream_controller.py @@ -1,6 +1,6 @@ from lbry.wallet.stream import StreamController from lbry.wallet.tasks import TaskGroup -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase class StreamControllerTestCase(AsyncioTestCase): diff --git a/lbry/tests/unit/wallet/test_transaction.py b/lbry/tests/unit/wallet/test_transaction.py index d58574dd2..67768aec5 100644 --- a/lbry/tests/unit/wallet/test_transaction.py +++ b/lbry/tests/unit/wallet/test_transaction.py @@ -2,7 +2,7 @@ import unittest from binascii import hexlify, unhexlify from itertools import cycle -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.wallet.client.constants import CENT, COIN, NULL_HASH32 from lbry.wallet.client.wallet import Wallet diff --git a/lbry/tests/unit/wallet/test_wallet.py b/lbry/tests/unit/wallet/test_wallet.py index f2dedbbd4..9f1b18da0 100644 --- a/lbry/tests/unit/wallet/test_wallet.py +++ b/lbry/tests/unit/wallet/test_wallet.py @@ -2,7 +2,7 @@ import tempfile from binascii import hexlify from unittest import TestCase, mock -from lbry.wallet.testcase import AsyncioTestCase +from lbry.testcase import AsyncioTestCase from lbry.wallet.ledger import MainNetLedger, RegTestLedger from lbry.wallet.client.basemanager import BaseWalletManager diff --git a/lbry/tox.ini b/lbry/tox.ini index 6c961df83..dd891d86d 100644 --- a/lbry/tox.ini +++ b/lbry/tox.ini @@ -4,7 +4,6 @@ envlist = py37-integration [testenv] deps = coverage - ../torba extras = test changedir = {toxinidir}/tests