2020
2121def wait_for_grpc_start (node ):
2222 """This can happen before "public key" which start() swallows"""
23- wait_for (lambda : node .daemon .is_in_log (r'serving grpc on 0.0.0.0: ' ))
23+ wait_for (lambda : node .daemon .is_in_log (r'serving grpc' ))
2424
2525
2626def test_rpc_client (node_factory ):
@@ -35,8 +35,9 @@ def test_plugin_start(node_factory):
3535 """Start a minimal plugin and ensure it is well-behaved
3636 """
3737 bin_path = Path .cwd () / "target" / RUST_PROFILE / "examples" / "cln-plugin-startup"
38- l1 = node_factory .get_node (options = {"plugin" : str (bin_path ), 'test-option' : 31337 })
39- l2 = node_factory .get_node ()
38+ l1 , l2 = node_factory .get_nodes (2 , opts = [
39+ {"plugin" : str (bin_path ), 'test-option' : 31337 }, {}
40+ ])
4041
4142 # The plugin should be in the list of active plugins
4243 plugins = l1 .rpc .plugin ('list' )['plugins' ]
@@ -107,9 +108,7 @@ def test_plugin_options_handle_defaults(node_factory):
107108def test_grpc_connect (node_factory ):
108109 """Attempts to connect to the grpc interface and call getinfo"""
109110 # These only exist if we have rust!
110-
111- grpc_port = node_factory .get_unused_port ()
112- l1 = node_factory .get_node (options = {"grpc-port" : str (grpc_port )})
111+ l1 = node_factory .get_node ()
113112
114113 p = Path (l1 .daemon .lightning_dir ) / TEST_NETWORK
115114 cert_path = p / "client.pem"
@@ -123,7 +122,7 @@ def test_grpc_connect(node_factory):
123122
124123 wait_for_grpc_start (l1 )
125124 channel = grpc .secure_channel (
126- f"localhost:{ grpc_port } " ,
125+ f"localhost:{ l1 . grpc_port } " ,
127126 creds ,
128127 options = (('grpc.ssl_target_name_override' , 'cln' ),)
129128 )
@@ -164,10 +163,7 @@ def test_grpc_generate_certificate(node_factory):
164163 - If we have certs, we they should just get loaded
165164 - If we delete one cert or its key it should get regenerated.
166165 """
167- grpc_port = node_factory .get_unused_port ()
168- l1 = node_factory .get_node (options = {
169- "grpc-port" : str (grpc_port ),
170- }, start = False )
166+ l1 = node_factory .get_node (start = False )
171167
172168 p = Path (l1 .daemon .lightning_dir ) / TEST_NETWORK
173169 files = [p / f for f in [
@@ -202,18 +198,20 @@ def test_grpc_generate_certificate(node_factory):
202198 assert all (private )
203199
204200
205- def test_grpc_no_auto_start (node_factory ):
206- """Ensure that we do not start cln-grpc unless a port is configured.
207- Also check that we do not generate certificates.
208- """
209- l1 = node_factory .get_node ()
201+ def test_grpc_default_port_auto_starts (node_factory ):
202+ """Ensure that we start cln-grpc on default port. Also check that certificates are generated."""
203+ l1 = node_factory .get_node (unused_grpc_port = False )
210204
211- wait_for (lambda : [p for p in l1 .rpc .plugin ('list' )['plugins' ] if 'cln-grpc' in p ['name' ]] == [])
212- assert l1 .daemon .is_in_log (r'plugin-cln-grpc: Killing plugin: disabled itself at init' )
213- p = Path (l1 .daemon .lightning_dir ) / TEST_NETWORK
214- files = os .listdir (p )
215- pem_files = [f for f in files if re .match (r".*\.pem$" , f )]
216- assert pem_files == []
205+ grpcplugin = next ((p for p in l1 .rpc .plugin ('list' )['plugins' ] if 'cln-grpc' in p ['name' ] and p ['active' ]), None )
206+ # Check that the plugin is active
207+ assert grpcplugin is not None
208+ # Check that the plugin is listening on the default port
209+ assert l1 .daemon .is_in_log (f'plugin-cln-grpc: Plugin logging initialized' )
210+ # Check that the certificates are generated
211+ assert len ([f for f in os .listdir (Path (l1 .daemon .lightning_dir ) / TEST_NETWORK ) if re .match (r".*\.pem$" , f )]) >= 6
212+
213+ # Check server connection
214+ l1 .grpc .Getinfo (clnpb .GetinfoRequest ())
217215
218216
219217def test_grpc_wrong_auth (node_factory ):
@@ -223,12 +221,7 @@ def test_grpc_wrong_auth(node_factory):
223221 and then we try to cross the wires.
224222 """
225223 # These only exist if we have rust!
226-
227- grpc_port = node_factory .get_unused_port ()
228- l1 , l2 = node_factory .get_nodes (2 , opts = {
229- "start" : False ,
230- "grpc-port" : str (grpc_port ),
231- })
224+ l1 , l2 = node_factory .get_nodes (2 , opts = [{"start" : False }, {"start" : False }])
232225 l1 .start ()
233226 wait_for_grpc_start (l1 )
234227
@@ -246,7 +239,7 @@ def connect(node):
246239 )
247240
248241 channel = grpc .secure_channel (
249- f"localhost:{ grpc_port } " ,
242+ f"localhost:{ node . grpc_port } " ,
250243 creds ,
251244 options = (('grpc.ssl_target_name_override' , 'cln' ),)
252245 )
@@ -282,8 +275,7 @@ def test_cln_plugin_reentrant(node_factory, executor):
282275
283276 """
284277 bin_path = Path .cwd () / "target" / RUST_PROFILE / "examples" / "cln-plugin-reentrant"
285- l1 = node_factory .get_node (options = {"plugin" : str (bin_path )})
286- l2 = node_factory .get_node ()
278+ l1 , l2 = node_factory .get_nodes (2 , opts = [{"plugin" : str (bin_path )}, {}])
287279 l2 .connect (l1 )
288280 l2 .fundchannel (l1 )
289281
@@ -311,18 +303,13 @@ def test_grpc_keysend_routehint(bitcoind, node_factory):
311303 recipient.
312304
313305 """
314- grpc_port = node_factory .get_unused_port ()
315306 l1 , l2 , l3 = node_factory .line_graph (
316307 3 ,
317- opts = [
318- {"grpc-port" : str (grpc_port )}, {}, {}
319- ],
320308 announce_channels = True , # Do not enforce scid-alias
321309 )
322310 bitcoind .generate_block (3 )
323311 sync_blockheight (bitcoind , [l1 , l2 , l3 ])
324312
325- stub = l1 .grpc
326313 chan = l2 .rpc .listpeerchannels (l3 .info ['id' ])
327314
328315 routehint = clnpb .RoutehintList (hints = [
@@ -348,19 +335,15 @@ def test_grpc_keysend_routehint(bitcoind, node_factory):
348335 routehints = routehint ,
349336 )
350337
351- res = stub .KeySend (call )
338+ res = l1 . grpc .KeySend (call )
352339 print (res )
353340
354341
355342def test_grpc_listpeerchannels (bitcoind , node_factory ):
356343 """ Check that conversions of this rather complex type work.
357344 """
358- grpc_port = node_factory .get_unused_port ()
359345 l1 , l2 = node_factory .line_graph (
360346 2 ,
361- opts = [
362- {"grpc-port" : str (grpc_port )}, {}
363- ],
364347 announce_channels = True , # Do not enforce scid-alias
365348 )
366349
@@ -385,8 +368,7 @@ def test_grpc_listpeerchannels(bitcoind, node_factory):
385368
386369
387370def test_grpc_decode (node_factory ):
388- grpc_port = node_factory .get_unused_port ()
389- l1 = node_factory .get_node (options = {'grpc-port' : str (grpc_port )})
371+ l1 = node_factory .get_node ()
390372 inv = l1 .grpc .Invoice (clnpb .InvoiceRequest (
391373 amount_msat = clnpb .AmountOrAny (any = True ),
392374 description = "desc" ,
@@ -418,9 +400,7 @@ def test_rust_plugin_subscribe_wildcard(node_factory):
418400
419401
420402def test_grpc_block_added_notifications (node_factory , bitcoind ):
421- grpc_port = node_factory .get_unused_port ()
422-
423- l1 = node_factory .get_node (options = {"grpc-port" : str (grpc_port )})
403+ l1 = node_factory .get_node ()
424404
425405 # Test the block_added notification
426406 # Start listening to block added events over grpc
@@ -436,10 +416,7 @@ def test_grpc_block_added_notifications(node_factory, bitcoind):
436416
437417
438418def test_grpc_connect_notification (node_factory ):
439- grpc_port = node_factory .get_unused_port ()
440-
441- l1 = node_factory .get_node (options = {"grpc-port" : str (grpc_port )})
442- l2 = node_factory .get_node ()
419+ l1 , l2 = node_factory .get_nodes (2 )
443420
444421 # Test the connect notification
445422 connect_stream = l1 .grpc .SubscribeConnect (clnpb .StreamConnectRequest ())
@@ -451,10 +428,7 @@ def test_grpc_connect_notification(node_factory):
451428
452429
453430def test_grpc_custommsg_notification (node_factory ):
454- grpc_port = node_factory .get_unused_port ()
455-
456- l1 = node_factory .get_node (options = {"grpc-port" : str (grpc_port )})
457- l2 = node_factory .get_node ()
431+ l1 , l2 = node_factory .get_nodes (2 )
458432
459433 # Test the connect notification
460434 custommsg_stream = l1 .grpc .SubscribeCustomMsg (clnpb .StreamCustomMsgRequest ())
0 commit comments