Return the list of notifications received by the websocket client. We try to connect to the websocket server running at `base_url` with `http_session` parameters. Then we create an invoice on the node: - if we were effectively connected, we received an `invoice_creation` notific
(l1, base_url, http_session, rpc_method='invoice', rpc_params=[100000, 'label', 'description'], expect_error=None)
| 264 | # unused 'message'". |
| 265 | |
| 266 | def notifications_received_via_websocket(l1, base_url, http_session, rpc_method='invoice', rpc_params=[100000, 'label', 'description'], expect_error=None): |
| 267 | """Return the list of notifications received by the websocket client. |
| 268 | |
| 269 | We try to connect to the websocket server running at `base_url` |
| 270 | with `http_session` parameters. Then we create an invoice on the node: |
| 271 | |
| 272 | - if we were effectively connected, we received an `invoice_creation` |
| 273 | notification via websocket that should be in the list of notifications |
| 274 | we return. |
| 275 | - if we couldn't connect to the websocket server, the notification list |
| 276 | we return is empty.""" |
| 277 | http_session.headers.update({"upgrade": "websocket"}) |
| 278 | sio = socketio.Client(http_session=http_session) |
| 279 | notifications = [] |
| 280 | connection_error_msg = None |
| 281 | |
| 282 | @sio.event |
| 283 | def message(data): |
| 284 | notifications.append(data) |
| 285 | |
| 286 | @sio.event |
| 287 | def connect_error(data): |
| 288 | nonlocal connection_error_msg |
| 289 | connection_error_msg = str(data) |
| 290 | |
| 291 | try: |
| 292 | sio.connect(base_url) |
| 293 | except socketio.exceptions.ConnectionError as e: |
| 294 | # Use the detailed error message if available |
| 295 | error_str = connection_error_msg if connection_error_msg else str(e) |
| 296 | |
| 297 | if expect_error and expect_error in error_str: |
| 298 | return notifications |
| 299 | else: |
| 300 | raise ValueError(f"Expected error code `{expect_error}`, got `{error_str}` instead") |
| 301 | except Exception: |
| 302 | raise |
| 303 | if expect_error: |
| 304 | raise Exception(f"did not raise expected error {expect_error}") |
| 305 | time.sleep(2) |
| 306 | # trigger notification by calling method |
| 307 | rpc_call = getattr(l1.rpc, rpc_method) |
| 308 | rpc_call(*rpc_params) |
| 309 | time.sleep(2) |
| 310 | sio.disconnect() |
| 311 | return notifications |
| 312 | |
| 313 | |
| 314 | def test_websocket_no_rune(node_factory): |
no test coverage detected