From 2ca438c36e51418eba8e2b0e5e1b8cf90636226e Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Wed, 23 Jan 2019 18:04:16 -0500 Subject: [PATCH] passing integration tests --- .travis.yml | 9 ++++++ lbrynet/extras/daemon/Daemon.py | 15 +++++---- tests/integration/cli/test_cli.py | 37 ++++++----------------- tests/integration/wallet/test_commands.py | 35 ++------------------- 4 files changed, 31 insertions(+), 65 deletions(-) diff --git a/.travis.yml b/.travis.yml index e67b4b1a2..d27f5629b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,15 @@ jobs: - coverage combine - bash <(curl -s https://codecov.io/bash) + - name: "Integration Tests" + install: + - pip install tox-travis coverage + - pushd .. && git clone https://github.com/lbryio/torba.git && popd + script: tox + after_success: + - coverage combine tests/ + - bash <(curl -s https://codecov.io/bash) + - stage: build name: "Windows" language: generic diff --git a/lbrynet/extras/daemon/Daemon.py b/lbrynet/extras/daemon/Daemon.py index c99c838d6..800e77007 100644 --- a/lbrynet/extras/daemon/Daemon.py +++ b/lbrynet/extras/daemon/Daemon.py @@ -247,14 +247,13 @@ class Daemon(metaclass=JSONRPCServerType): """ allowed_during_startup = [] - def __init__(self, conf: Config, analytics_manager: typing.Optional[analytics.Manager] = None, - component_manager: typing.Optional[ComponentManager] = None): + def __init__(self, conf: Config, component_manager: typing.Optional[ComponentManager] = None): self.conf = conf self._node_id = None self._installation_id = None self.session_id = base58.b58encode(utils.generate_id()).decode() to_skip = conf.components_to_skip - self.analytics_manager = analytics_manager or analytics.Manager(conf, self.installation_id, self.session_id) + self.analytics_manager = analytics.Manager(conf, self.installation_id, self.session_id) self.component_manager = component_manager or ComponentManager( conf, analytics_manager=self.analytics_manager, skip_components=to_skip or [] ) @@ -447,8 +446,12 @@ class Daemon(metaclass=JSONRPCServerType): async def handle_old_jsonrpc(self, request): data = await request.json() result = await self._process_rpc_call(data) + ledger = None + if 'wallet' in self.component_manager.get_components_status(): + # self.ledger only available if wallet component is not skipped + ledger = self.ledger return web.Response( - text=jsonrpc_dumps_pretty(result, ledger=self.ledger), + text=jsonrpc_dumps_pretty(result, ledger=ledger), content_type='application/json' ) @@ -2195,8 +2198,8 @@ class Daemon(metaclass=JSONRPCServerType): raise Exception("no previous stream to update") claim_dict['stream']['source'] = existing_claims[-1].claim_dict['stream']['source'] stream_hash = await self.storage.get_stream_hash_for_sd_hash(claim_dict['stream']['source']['source']) - tx = await self.default_wallet.claim_name( - account, name, bid, claim_dict, certificate, claim_address + tx = await self.wallet_manager.claim_name( + account, name, amount, claim_dict, certificate, claim_address ) await self.storage.save_content_claim( stream_hash, tx.outputs[0].id diff --git a/tests/integration/cli/test_cli.py b/tests/integration/cli/test_cli.py index b85f9151b..34a1561d2 100644 --- a/tests/integration/cli/test_cli.py +++ b/tests/integration/cli/test_cli.py @@ -4,43 +4,26 @@ from torba.testcase import AsyncioTestCase from lbrynet.conf import Config from lbrynet.extras import cli -from lbrynet.extras.daemon.Components import DATABASE_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT, WALLET_COMPONENT, \ - DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT, \ - PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, \ - RATE_LIMITER_COMPONENT, PAYMENT_RATE_COMPONENT +from lbrynet.extras.daemon.Components import ( + DATABASE_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT, + HASH_ANNOUNCER_COMPONENT, STREAM_MANAGER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, + UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT +) from lbrynet.extras.daemon.Daemon import Daemon -class FakeAnalytics: - - @property - def is_started(self): - return True - - async def send_server_startup_success(self): - pass - - async def send_server_startup(self): - pass - - def shutdown(self): - pass - - class CLIIntegrationTest(AsyncioTestCase): async def asyncSetUp(self): - skip = [ - DATABASE_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT, WALLET_COMPONENT, - DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT, - PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, - RATE_LIMITER_COMPONENT, PAYMENT_RATE_COMPONENT - ] conf = Config() conf.data_dir = '/tmp' conf.share_usage_data = False conf.api = 'localhost:5299' - conf.components_to_skip = skip + conf.components_to_skip = ( + DATABASE_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT, + HASH_ANNOUNCER_COMPONENT, STREAM_MANAGER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, + UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT + ) Daemon.component_attributes = {} self.daemon = Daemon(conf) await self.daemon.start() diff --git a/tests/integration/wallet/test_commands.py b/tests/integration/wallet/test_commands.py index 2e00a6f93..af3d9e333 100644 --- a/tests/integration/wallet/test_commands.py +++ b/tests/integration/wallet/test_commands.py @@ -1,14 +1,10 @@ -import sys import json import tempfile import logging from binascii import unhexlify -import twisted.internet -from twisted.internet.asyncioreactor import AsyncioSelectorReactor - from lbrynet.extras.wallet.transaction import Transaction -from lbrynet.p2p.Error import InsufficientFundsError +from lbrynet.error import InsufficientFundsError from lbrynet.schema.claim import ClaimDict from torba.testcase import IntegrationTestCase @@ -22,33 +18,11 @@ from lbrynet.extras.wallet import LbryWalletManager from lbrynet.extras.daemon.Components import WalletComponent from lbrynet.extras.daemon.Components import ( DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, - REFLECTOR_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT + UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT ) from lbrynet.extras.daemon.ComponentManager import ComponentManager -class FakeAnalytics: - - @property - def is_started(self): - return True - - async def send_new_channel(self): - pass - - def shutdown(self): - pass - - async def send_claim_action(self, action): - pass - - async def send_credits_sent(self): - pass - - async def send_server_startup(self): - pass - - class CommandTestCase(IntegrationTestCase): timeout = 180 @@ -58,8 +32,6 @@ class CommandTestCase(IntegrationTestCase): async def asyncSetUp(self): await super().asyncSetUp() - twisted.internet.reactor = sys.modules['twisted.internet.reactor'] = AsyncioSelectorReactor() - logging.getLogger('lbrynet.blob_exchange').setLevel(self.VERBOSITY) logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY) @@ -88,13 +60,12 @@ class CommandTestCase(IntegrationTestCase): conf.components_to_skip = [ DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT, - PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT + PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT ] self.daemon = Daemon(conf, ComponentManager( conf, skip_components=conf.components_to_skip, wallet=wallet_maker )) await self.daemon.setup() - self.daemon.wallet_manager = self.wallet_component.wallet_manager self.manager.old_db = self.daemon.storage async def asyncTearDown(self):