MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_grpc_connect

Function test_grpc_connect

tests/test_cln_rs.py:75–125  ·  view source on GitHub ↗

Attempts to connect to the grpc interface and call getinfo

(node_factory)

Source from the content-addressed store, hash-verified

73
74
75def test_grpc_connect(node_factory):
76 """Attempts to connect to the grpc interface and call getinfo"""
77 # These only exist if we have rust!
78
79 grpc_port = reserve()
80 l1 = node_factory.get_node(options={"grpc-port": str(grpc_port)})
81
82 p = Path(l1.daemon.lightning_dir) / TEST_NETWORK
83 cert_path = p / "client.pem"
84 key_path = p / "client-key.pem"
85 ca_cert_path = p / "ca.pem"
86 creds = grpc.ssl_channel_credentials(
87 root_certificates=ca_cert_path.open('rb').read(),
88 private_key=key_path.open('rb').read(),
89 certificate_chain=cert_path.open('rb').read()
90 )
91
92 wait_for_grpc_start(l1)
93 channel = grpc.secure_channel(
94 f"localhost:{grpc_port}",
95 creds,
96 options=(('grpc.ssl_target_name_override', 'cln'),)
97 )
98 stub = nodegrpc.NodeStub(channel)
99
100 response = stub.Getinfo(nodepb.GetinfoRequest())
101 print(response)
102
103 response = stub.ListFunds(nodepb.ListfundsRequest())
104 print(response)
105
106 inv = stub.Invoice(nodepb.InvoiceRequest(
107 amount_msat=primitivespb.AmountOrAny(any=True),
108 description="hello",
109 label="lbl1",
110 preimage=b"\x00" * 32,
111 cltv=24
112 ))
113 print(inv)
114
115 rates = stub.Feerates(nodepb.FeeratesRequest(style='PERKB'))
116 print(rates)
117
118 # Test a failing RPC call, so we know that errors are returned correctly.
119 with pytest.raises(Exception, match=r'Duplicate label'):
120 # This request creates a label collision
121 stub.Invoice(nodepb.InvoiceRequest(
122 amount_msat=primitivespb.AmountOrAny(amount=primitivespb.Amount(msat=12345)),
123 description="hello",
124 label="lbl1",
125 ))
126
127
128def test_grpc_generate_certificate(node_factory):

Callers

nothing calls this directly

Calls 8

wait_for_grpc_startFunction · 0.85
openMethod · 0.80
get_nodeMethod · 0.45
readMethod · 0.45
GetinfoMethod · 0.45
ListFundsMethod · 0.45
InvoiceMethod · 0.45
FeeratesMethod · 0.45

Tested by

no test coverage detected