Exemplo n.º 1
0
 async def test_session_bloat_from_socket_timeout(self):
     await self.conductor.stop_spv()
     self.conductor.spv_node.session_timeout = 1
     await self.conductor.start_spv()
     session = ClientSession(network=None, server=self.ledger.network.client.server, timeout=0.2)
     await session.create_connection()
     session.ping_task.cancel()
     await session.send_request('server.banner', ())
     self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 1)
     self.assertFalse(session.is_closing())
     await asyncio.sleep(1.1)
     with self.assertRaises(asyncio.TimeoutError):
         await session.send_request('server.banner', ())
     self.assertTrue(session.is_closing())
     self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 0)
Exemplo n.º 2
0
async def main():
    try:
        hostname = sys.argv[1]
    except IndexError:
        hostname = 'spv1.lbry.com'

    loop = asyncio.get_event_loop()
    client = ClientSession(network=None, server=(hostname, 50001))
    error = None
    args = {
        'any_tags': ['art'],
        'not_tags': ['xxx', 'p**n', 'mature', 'nsfw', 'titan'],
        'order_by': ["name"],
        'offset': 3000,
        'limit': 200,
        'no_totals': False,
    }

    start = loop.time()
    try:
        await client.create_connection()
        try:
            await client.send_request('blockchain.claimtrie.search', args)
        except RPCError as err:
            error = err
        finally:
            await client.close()
    finally:
        print(json.dumps({
            "time": loop.time() - start,
            "error": error.__str__() if error else None,
            "args": args,
        }, indent=4))
Exemplo n.º 3
0
async def get_mock_wallet(sd_hash, storage, balance=10.0, fee=None):
    claim = Claim()
    if fee:
        if fee['currency'] == 'LBC':
            claim.stream.fee.lbc = Decimal(fee['amount'])
        elif fee['currency'] == 'USD':
            claim.stream.fee.usd = Decimal(fee['amount'])
    claim.stream.title = "33rpm"
    claim.stream.languages.append("en")
    claim.stream.source.sd_hash = sd_hash
    claim.stream.source.media_type = "image/png"

    tx = get_claim_transaction("33rpm", claim.to_bytes())
    tx.height = 514081
    txo = tx.outputs[0]
    txo.meta.update({
        "permanent_url":
        "33rpm#c49566d631226492317d06ad7fdbe1ed32925124",
    })

    class FakeHeaders:
        def __init__(self, height):
            self.height = height

        def __getitem__(self, item):
            return {'timestamp': 1984}

    wallet = Wallet()
    ledger = MainNetLedger({
        'db': MainNetLedger.database_class(':memory:'),
        'headers': FakeHeaders(514082)
    })
    await ledger.db.open()
    wallet.generate_account(ledger)
    manager = LbryWalletManager()
    manager.config = Config()
    manager.wallets.append(wallet)
    manager.ledgers[MainNetLedger] = ledger
    manager.ledger.network.client = ClientSession(
        network=manager.ledger.network, server=('fakespv.lbry.com', 50001))

    async def mock_resolve(*args):
        result = {txo.meta['permanent_url']: txo}
        claims = [
            StreamManager._convert_to_old_resolve_output(
                manager, result)[txo.meta['permanent_url']]
        ]
        await storage.save_claims(claims)
        return result

    manager.ledger.resolve = mock_resolve

    async def get_balance(*_):
        return balance

    manager.get_balance = get_balance

    return manager, txo.meta['permanent_url']