class CLIIntegrationTest(unittest.TestCase): USE_AUTH = False @defer.inlineCallbacks def setUp(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.initialize_settings(load_conf_file=False) conf.settings['api_port'] = 5299 conf.settings['use_auth_http'] = self.USE_AUTH conf.settings['components_to_skip'] = skip conf.settings.initialize_post_conf_load() Daemon.component_attributes = {} self.daemon = Daemon(analytics_manager=FakeAnalytics()) yield self.daemon.start_listening() def tearDown(self): return self.daemon._shutdown()
class CommandTestCase(IntegrationTestCase): timeout = 180 MANAGER = LbryWalletManager async def setUp(self): await super().setUp() logging.getLogger('lbrynet.p2p').setLevel(self.VERBOSITY) logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY) lbry_conf.settings = None lbry_conf.initialize_settings(load_conf_file=False) lbry_conf.settings['data_dir'] = self.wallet_node.data_path lbry_conf.settings['lbryum_wallet_dir'] = self.wallet_node.data_path lbry_conf.settings['download_directory'] = self.wallet_node.data_path lbry_conf.settings['use_upnp'] = False lbry_conf.settings['reflect_uploads'] = False lbry_conf.settings['blockchain_name'] = 'lbrycrd_regtest' lbry_conf.settings['lbryum_servers'] = [('localhost', 50001)] lbry_conf.settings['known_dht_nodes'] = [] lbry_conf.settings.node_id = None await self.account.ensure_address_gap() address = (await self.account.receiving.get_addresses(limit=1, only_usable=True))[0] sendtxid = await self.blockchain.send_to_address(address, 10) await self.confirm_tx(sendtxid) await self.generate(5) def wallet_maker(component_manager): self.wallet_component = WalletComponent(component_manager) self.wallet_component.wallet_manager = self.manager self.wallet_component._running = True return self.wallet_component skip = [ #UPNP_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT ] analytics_manager = FakeAnalytics() self.daemon = Daemon(analytics_manager, ComponentManager( analytics_manager=analytics_manager, skip_components=skip, wallet=wallet_maker, dht=FakeDHT, hash_announcer=FakeHashAnnouncerComponent, exchange_rate_manager=FakeExchangeRateComponent, upnp=FakeUPnP )) await d2f(self.daemon.setup()) self.daemon.wallet_manager = self.wallet_component.wallet_manager self.manager.old_db = self.daemon.storage async def tearDown(self): await super().tearDown() self.wallet_component._running = False await d2f(self.daemon._shutdown()) 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. """ await self.on_transaction_id(txid) await self.generate(1) await self.on_transaction_id(txid) async def on_transaction_dict(self, tx): await asyncio.wait([ self.ledger.on_transaction.where( partial(lambda address, event: address == event.address, address) ) for address in self.get_all_addresses(tx) ]) @staticmethod def get_all_addresses(tx): addresses = set() for txi in tx['inputs']: addresses.add(txi['address']) for txo in tx['outputs']: addresses.add(txo['address']) return list(addresses) async def generate(self, blocks): """ Ask lbrycrd to generate some blocks and wait until ledger has them. """ await self.blockchain.generate(blocks) await self.ledger.on_header.where(self.blockchain.is_expected_block) async def out(self, awaitable): """ Converts Daemon API call results (dictionary) to JSON and then back to a dictionary. """ return json.loads(jsonrpc_dumps_pretty(await awaitable, ledger=self.ledger))['result']