simplified component setup
This commit is contained in:
parent
86fb99a37c
commit
c186c31bf7
2 changed files with 26 additions and 90 deletions
|
@ -1,7 +1,6 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
from twisted.trial import unittest
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from twisted.internet import defer
|
from unittest import skip
|
||||||
from torba.testcase import AsyncioTestCase
|
from torba.testcase import AsyncioTestCase
|
||||||
|
|
||||||
from lbrynet import conf
|
from lbrynet import conf
|
||||||
|
@ -52,6 +51,7 @@ class CLIIntegrationTest(AsyncioTestCase):
|
||||||
await self.daemon.shutdown()
|
await self.daemon.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
@skip
|
||||||
class AuthenticatedCLITest(CLIIntegrationTest):
|
class AuthenticatedCLITest(CLIIntegrationTest):
|
||||||
USE_AUTH = True
|
USE_AUTH = True
|
||||||
|
|
||||||
|
|
|
@ -1,75 +1,32 @@
|
||||||
|
import sys
|
||||||
import json
|
import json
|
||||||
import asyncio
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import logging
|
import logging
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
from functools import partial
|
|
||||||
from types import SimpleNamespace
|
|
||||||
|
|
||||||
from twisted.trial import unittest
|
import twisted.internet
|
||||||
from twisted.internet import utils, defer
|
from twisted.internet.asyncioreactor import AsyncioSelectorReactor
|
||||||
from twisted.internet.utils import runWithWarningsSuppressed as originalRunWith
|
|
||||||
|
|
||||||
from lbrynet.extras.wallet.transaction import Transaction
|
from lbrynet.extras.wallet.transaction import Transaction
|
||||||
from lbrynet.p2p.Error import InsufficientFundsError
|
from lbrynet.p2p.Error import InsufficientFundsError
|
||||||
from lbrynet.schema.claim import ClaimDict
|
from lbrynet.schema.claim import ClaimDict
|
||||||
|
|
||||||
from torba.testcase import IntegrationTestCase as BaseIntegrationTestCase
|
from torba.testcase import IntegrationTestCase
|
||||||
|
|
||||||
import lbrynet.schema
|
import lbrynet.schema
|
||||||
lbrynet.schema.BLOCKCHAIN_NAME = 'lbrycrd_regtest'
|
lbrynet.schema.BLOCKCHAIN_NAME = 'lbrycrd_regtest'
|
||||||
|
|
||||||
from lbrynet import conf as lbry_conf
|
from lbrynet import conf as lbry_conf
|
||||||
from lbrynet.dht.node import Node
|
|
||||||
from lbrynet.extras.daemon.Daemon import Daemon, jsonrpc_dumps_pretty
|
from lbrynet.extras.daemon.Daemon import Daemon, jsonrpc_dumps_pretty
|
||||||
from lbrynet.extras.wallet import LbryWalletManager
|
from lbrynet.extras.wallet import LbryWalletManager
|
||||||
from lbrynet.extras.daemon.Components import WalletComponent, DHTComponent, HashAnnouncerComponent, \
|
from lbrynet.extras.daemon.Components import WalletComponent
|
||||||
ExchangeRateManagerComponent
|
from lbrynet.extras.daemon.Components import (
|
||||||
from lbrynet.extras.daemon.Components import REFLECTOR_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT
|
DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT,
|
||||||
from lbrynet.extras.daemon.Components import UPnPComponent
|
REFLECTOR_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
|
||||||
from lbrynet.extras.daemon.Components import d2f
|
)
|
||||||
from lbrynet.extras.daemon.ComponentManager import ComponentManager
|
from lbrynet.extras.daemon.ComponentManager import ComponentManager
|
||||||
|
|
||||||
|
|
||||||
class FakeUPnP(UPnPComponent):
|
|
||||||
|
|
||||||
def __init__(self, component_manager):
|
|
||||||
self.component_manager = component_manager
|
|
||||||
self._running = False
|
|
||||||
self.use_upnp = False
|
|
||||||
self.upnp_redirects = {}
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class FakeDHT(DHTComponent):
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
self.dht_node = Node()
|
|
||||||
|
|
||||||
|
|
||||||
class FakeExchangeRateComponent(ExchangeRateManagerComponent):
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
self.exchange_rate_manager = SimpleNamespace()
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class FakeHashAnnouncerComponent(HashAnnouncerComponent):
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
self.hash_announcer = SimpleNamespace()
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class FakeAnalytics:
|
class FakeAnalytics:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -92,41 +49,25 @@ class FakeAnalytics:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class IntegrationTestCase(unittest.TestCase, BaseIntegrationTestCase):
|
|
||||||
|
|
||||||
async def setUp(self):
|
|
||||||
await self.asyncSetUp()
|
|
||||||
|
|
||||||
async def tearDown(self):
|
|
||||||
await self.asyncTearDown()
|
|
||||||
|
|
||||||
|
|
||||||
def run_with_async_support(suppress, f, *a, **kw):
|
|
||||||
if asyncio.iscoroutinefunction(f):
|
|
||||||
def test_method(*args, **kwargs):
|
|
||||||
return defer.Deferred.fromFuture(asyncio.ensure_future(f(*args, **kwargs)))
|
|
||||||
else:
|
|
||||||
test_method = f
|
|
||||||
return originalRunWith(suppress, test_method, *a, **kw)
|
|
||||||
|
|
||||||
|
|
||||||
utils.runWithWarningsSuppressed = run_with_async_support
|
|
||||||
|
|
||||||
|
|
||||||
class CommandTestCase(IntegrationTestCase):
|
class CommandTestCase(IntegrationTestCase):
|
||||||
|
|
||||||
timeout = 180
|
timeout = 180
|
||||||
MANAGER = LbryWalletManager
|
MANAGER = LbryWalletManager
|
||||||
|
VERBOSITY = logging.WARN
|
||||||
|
|
||||||
async def setUp(self):
|
async def asyncSetUp(self):
|
||||||
await super().setUp()
|
await super().asyncSetUp()
|
||||||
|
|
||||||
|
twisted.internet.reactor = sys.modules['twisted.internet.reactor'] = AsyncioSelectorReactor()
|
||||||
|
|
||||||
logging.getLogger('lbrynet.p2p').setLevel(self.VERBOSITY)
|
logging.getLogger('lbrynet.p2p').setLevel(self.VERBOSITY)
|
||||||
logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)
|
logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)
|
||||||
|
|
||||||
lbry_conf.settings = None
|
lbry_conf.settings = None
|
||||||
lbry_conf.initialize_settings(
|
lbry_conf.initialize_settings(
|
||||||
load_conf_file=False, data_dir=self.wallet_node.data_path, wallet_dir=self.wallet_node.data_path,
|
load_conf_file=False,
|
||||||
|
data_dir=self.wallet_node.data_path,
|
||||||
|
wallet_dir=self.wallet_node.data_path,
|
||||||
download_dir=self.wallet_node.data_path
|
download_dir=self.wallet_node.data_path
|
||||||
)
|
)
|
||||||
lbry_conf.settings['use_upnp'] = False
|
lbry_conf.settings['use_upnp'] = False
|
||||||
|
@ -149,27 +90,22 @@ class CommandTestCase(IntegrationTestCase):
|
||||||
return self.wallet_component
|
return self.wallet_component
|
||||||
|
|
||||||
skip = [
|
skip = [
|
||||||
#UPNP_COMPONENT,
|
DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
|
||||||
PEER_PROTOCOL_SERVER_COMPONENT,
|
PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
|
||||||
REFLECTOR_COMPONENT
|
|
||||||
]
|
]
|
||||||
analytics_manager = FakeAnalytics()
|
analytics_manager = FakeAnalytics()
|
||||||
self.daemon = Daemon(analytics_manager, ComponentManager(
|
self.daemon = Daemon(analytics_manager, ComponentManager(
|
||||||
analytics_manager=analytics_manager,
|
analytics_manager=analytics_manager,
|
||||||
skip_components=skip, wallet=wallet_maker,
|
skip_components=skip, wallet=wallet_maker
|
||||||
dht=FakeDHT, hash_announcer=FakeHashAnnouncerComponent,
|
|
||||||
exchange_rate_manager=FakeExchangeRateComponent,
|
|
||||||
upnp=FakeUPnP
|
|
||||||
))
|
))
|
||||||
await d2f(self.daemon.setup())
|
await self.daemon.setup()
|
||||||
self.daemon.wallet_manager = self.wallet_component.wallet_manager
|
self.daemon.wallet_manager = self.wallet_component.wallet_manager
|
||||||
self.manager.old_db = self.daemon.storage
|
self.manager.old_db = self.daemon.storage
|
||||||
|
|
||||||
async def tearDown(self):
|
async def asyncTearDown(self):
|
||||||
self.conductor.spv_node.server.stop()
|
await super().asyncTearDown()
|
||||||
await super().tearDown()
|
|
||||||
self.wallet_component._running = False
|
self.wallet_component._running = False
|
||||||
await d2f(self.daemon._shutdown())
|
await self.daemon.shutdown()
|
||||||
|
|
||||||
async def confirm_tx(self, txid):
|
async def confirm_tx(self, txid):
|
||||||
""" Wait for tx to be in mempool, then generate a block, wait for tx to be in a block. """
|
""" Wait for tx to be in mempool, then generate a block, wait for tx to be in a block. """
|
||||||
|
|
Loading…
Add table
Reference in a new issue