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 estimated_timestamp(self, height):
            return 1984

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

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

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

    async def mock_resolve(*args, **kwargs):
        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']
示例#2
0
 async def test_session_bloat_from_socket_timeout(self):
     await self.conductor.stop_spv()
     await self.ledger.stop()
     self.conductor.spv_node.session_timeout = 1
     await self.conductor.start_spv()
     session = ClientSession(network=None,
                             server=(self.conductor.spv_node.hostname,
                                     self.conductor.spv_node.port),
                             timeout=0.2)
     await session.create_connection()
     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)
示例#3
0
async def main():
    try:
        hostname = sys.argv[1]
    except IndexError:
        hostname = 'spv11.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))