From 318f35b24372f8c6dd382b668ec4e53d08c2b93a Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 2 May 2023 13:03:30 +0200 Subject: [PATCH] pytest: Add a test for the grpc conversion of listpeerchannels This is still a huge response, so we better make sure we can actually convert it correctly. --- tests/test_cln_rs.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_cln_rs.py b/tests/test_cln_rs.py index 9485bc259..8d9a39091 100644 --- a/tests/test_cln_rs.py +++ b/tests/test_cln_rs.py @@ -348,3 +348,44 @@ def test_grpc_keysend_routehint(bitcoind, node_factory): res = stub.KeySend(call) print(res) + + +def test_grpc_listpeerchannels(bitcoind, node_factory): + """ Check that conversions of this rather complex type work. + """ + grpc_port = reserve() + l1, l2 = node_factory.line_graph( + 2, + opts=[ + {"grpc-port": str(grpc_port)}, {} + ], + announce_channels=True, # Do not enforce scid-alias + ) + + def connect(node): + p = Path(node.daemon.lightning_dir) / TEST_NETWORK + cert, key, ca = [f.open('rb').read() for f in [ + p / 'client.pem', + p / 'client-key.pem', + p / "ca.pem"]] + + creds = grpc.ssl_channel_credentials( + root_certificates=ca, + private_key=key, + certificate_chain=cert, + ) + + channel = grpc.secure_channel( + f"localhost:{grpc_port}", + creds, + options=(('grpc.ssl_target_name_override', 'cln'),) + ) + return nodegrpc.NodeStub(channel) + stub = connect(l1) + res = stub.ListPeerChannels(nodepb.ListpeerchannelsRequest(id=None)) + + # Way too many fields to check, so just do a couple + assert len(res.channels) == 1 + c = res.channels[0] + assert c.peer_id.hex() == l2.info['id'] + assert c.state == 2 # CHANNELD_NORMAL