|
8 | 8 | Thread,
|
9 | 9 | )
|
10 | 10 | import time
|
| 11 | +from unittest.mock import ( |
| 12 | + AsyncMock, |
| 13 | + Mock, |
| 14 | +) |
11 | 15 |
|
12 | 16 | from websockets import (
|
13 | 17 | ConnectionClosed,
|
|
43 | 47 |
|
44 | 48 | TWENTY_MB = 20 * 1024 * 1024
|
45 | 49 | SIZED_MSG_START = b'{"id": 0, "jsonrpc": "2.0", "result": "'
|
46 |
| -SIZED_MSG_END = b'"}\n' b"" |
| 50 | +SIZED_MSG_END = b'"}\n' |
47 | 51 |
|
48 | 52 |
|
49 | 53 | @pytest.fixture
|
@@ -100,9 +104,9 @@ def server_fixture(response_fn):
|
100 | 104 | @pytest.fixture
|
101 | 105 | def serve_empty_result(ipc_server_fixture):
|
102 | 106 | def response_fn(connection):
|
103 |
| - connection.sendall(b'{"id": 0, "result": {}') |
| 107 | + connection.sendall(b'{"id": 0, "result": {}}') |
104 | 108 | time.sleep(0.1)
|
105 |
| - connection.sendall(b"}\n") |
| 109 | + connection.sendall(b"\n") |
106 | 110 |
|
107 | 111 | yield from ipc_server_fixture(response_fn)
|
108 | 112 |
|
@@ -342,3 +346,20 @@ async def test_async_ipc_read_buffer_limit_is_configurable(
|
342 | 346 | len(response["result"])
|
343 | 347 | == TWENTY_MB - len(SIZED_MSG_START) - len(SIZED_MSG_END) + 1024
|
344 | 348 | )
|
| 349 | + |
| 350 | + |
| 351 | +@pytest.mark.asyncio |
| 352 | +async def test_async_ipc_provider_write_messages_end_with_new_line_delimiter( |
| 353 | + simple_ipc_server, |
| 354 | + jsonrpc_ipc_pipe_path, |
| 355 | +): |
| 356 | + async with AsyncWeb3(AsyncIPCProvider(pathlib.Path(jsonrpc_ipc_pipe_path))) as w3: |
| 357 | + w3.provider._writer.write = Mock() |
| 358 | + w3.provider._reader.readline = AsyncMock( |
| 359 | + return_value=b'{"id": 0, "result": {}}\n' |
| 360 | + ) |
| 361 | + |
| 362 | + await w3.provider.make_request("method", []) |
| 363 | + |
| 364 | + request_data = b'{"jsonrpc": "2.0", "method": "method", "params": [], "id": 0}' |
| 365 | + w3.provider._writer.write.assert_called_with(request_data + b"\n") |
0 commit comments