def make_client_server(): init_logging() run = asyncio.get_event_loop().run_until_complete path = pathlib.Path(tempfile.mkdtemp(), "port") server, aiter = run(start_unix_server_aiter(path)) rws_aiter = map_aiter(lambda rw: dict( reader=rw[0], writer=rw[1], server=server), aiter) initial_block_hash = bytes(([0] * 31) + [1]) ledger = ledger_api.LedgerAPI(initial_block_hash, RAM_DB()) server_task = asyncio.ensure_future(api_server(rws_aiter, ledger)) remote = run(proxy_for_unix_connection(path)) # make sure server_task isn't garbage collected remote.server_task = server_task return remote
def test_client_server(): init_logging() run = asyncio.get_event_loop().run_until_complete path = pathlib.Path(tempfile.mkdtemp(), "port") server, aiter = run(start_unix_server_aiter(path)) rws_aiter = map_aiter( lambda rw: dict(reader=rw[0], writer=rw[1], server=server), aiter) initial_block_hash = bytes(([0] * 31) + [1]) ledger = ledger_api.LedgerAPI(initial_block_hash, RAM_DB()) server_task = asyncio.ensure_future(api_server(rws_aiter, ledger)) run(client_test(path)) server_task.cancel()
def run_ledger_api(server, aiter): db = RAM_DB() INITIAL_BLOCK_HASH = bytes(([0] * 31) + [1]) ledger = ledger_api.LedgerAPI(INITIAL_BLOCK_HASH, db) rws_aiter = map_aiter(lambda rw: dict(reader=rw[0], writer=rw[1], server=server), aiter) return api_server(rws_aiter, ledger)