l1 uses the logger_a, reject and logger_b plugin. l1 is configured to accept connections from l2, but not from l3. we check that logger_a is always called and logger_b only for l2.
(node_factory)
| 481 | |
| 482 | |
| 483 | def test_plugin_connected_hook_chaining(node_factory): |
| 484 | """ l1 uses the logger_a, reject and logger_b plugin. |
| 485 | |
| 486 | l1 is configured to accept connections from l2, but not from l3. |
| 487 | we check that logger_a is always called and logger_b only for l2. |
| 488 | """ |
| 489 | opts = [{'plugin': |
| 490 | [os.path.join(os.getcwd(), |
| 491 | 'tests/plugins/peer_connected_logger_a.py'), |
| 492 | os.path.join(os.getcwd(), |
| 493 | 'tests/plugins/reject.py'), |
| 494 | os.path.join(os.getcwd(), |
| 495 | 'tests/plugins/peer_connected_logger_b.py')], |
| 496 | 'allow_warning': True}, |
| 497 | {}, |
| 498 | {'allow_warning': True}] |
| 499 | |
| 500 | l1, l2, l3 = node_factory.get_nodes(3, opts=opts) |
| 501 | l2id = l2.info['id'] |
| 502 | l3id = l3.info['id'] |
| 503 | l1.rpc.reject(l3.info['id']) |
| 504 | |
| 505 | l2.connect(l1) |
| 506 | l1.daemon.wait_for_logs([ |
| 507 | f"peer_connected_logger_a {l2id}", |
| 508 | f"{l2id} is allowed", |
| 509 | f"peer_connected_logger_b {l2id}" |
| 510 | ]) |
| 511 | assert len(l1.rpc.listpeers(l2id)['peers']) == 1 |
| 512 | |
| 513 | # If reject happens fast enough, connect fails with "disconnected |
| 514 | # during connection" |
| 515 | try: |
| 516 | l3.connect(l1) |
| 517 | except RpcError as err: |
| 518 | assert "disconnected during connection" in err.error['message'] |
| 519 | |
| 520 | l1.daemon.wait_for_logs([ |
| 521 | f"peer_connected_logger_a {l3id}", |
| 522 | f"{l3id} is in reject list" |
| 523 | ]) |
| 524 | |
| 525 | # FIXME: this error occurs *after* connection, so we connect then drop. |
| 526 | l3.daemon.wait_for_log(r"-connectd: peer_in WIRE_WARNING") |
| 527 | l3.daemon.wait_for_log(r"You are in reject list") |
| 528 | |
| 529 | def check_disconnect(): |
| 530 | peers = l1.rpc.listpeers(l3id)['peers'] |
| 531 | return peers == [] or not peers[0]['connected'] |
| 532 | |
| 533 | wait_for(check_disconnect) |
| 534 | assert not l1.daemon.is_in_log(f"peer_connected_logger_b {l3id}") |
| 535 | |
| 536 | |
| 537 | def test_plugin_connected_hook_disconnect_crash(node_factory, executor): |
nothing calls this directly
no test coverage detected