Attempts to connect to the grpc interface and call getinfo
(node_factory)
| 128 | |
| 129 | |
| 130 | def test_grpc_connect(node_factory): |
| 131 | """Attempts to connect to the grpc interface and call getinfo""" |
| 132 | # These only exist if we have rust! |
| 133 | l1 = node_factory.get_node() |
| 134 | |
| 135 | p = Path(l1.daemon.lightning_dir) / TEST_NETWORK |
| 136 | cert_path = p / "client.pem" |
| 137 | key_path = p / "client-key.pem" |
| 138 | ca_cert_path = p / "ca.pem" |
| 139 | creds = grpc.ssl_channel_credentials( |
| 140 | root_certificates=ca_cert_path.read_bytes(), |
| 141 | private_key=key_path.read_bytes(), |
| 142 | certificate_chain=cert_path.read_bytes() |
| 143 | ) |
| 144 | |
| 145 | wait_for_grpc_start(l1) |
| 146 | channel = grpc.secure_channel( |
| 147 | f"localhost:{l1.grpc_port}", |
| 148 | creds, |
| 149 | options=(('grpc.ssl_target_name_override', 'cln'),) |
| 150 | ) |
| 151 | stub = clnpb.NodeStub(channel) |
| 152 | |
| 153 | response = stub.Getinfo(clnpb.GetinfoRequest()) |
| 154 | print(response) |
| 155 | |
| 156 | response = stub.ListFunds(clnpb.ListfundsRequest()) |
| 157 | print(response) |
| 158 | |
| 159 | inv = stub.Invoice(clnpb.InvoiceRequest( |
| 160 | amount_msat=clnpb.AmountOrAny(any=True), |
| 161 | description="hello", |
| 162 | label="lbl1", |
| 163 | preimage=b"\x00" * 32, |
| 164 | cltv=24 |
| 165 | )) |
| 166 | print(inv) |
| 167 | |
| 168 | rates = stub.Feerates(clnpb.FeeratesRequest(style='PERKB')) |
| 169 | print(rates) |
| 170 | |
| 171 | # Test a failing RPC call, so we know that errors are returned correctly. |
| 172 | with pytest.raises(Exception, match=r'Duplicate label'): |
| 173 | # This request creates a label collision |
| 174 | stub.Invoice(clnpb.InvoiceRequest( |
| 175 | amount_msat=clnpb.AmountOrAny(amount=clnpb.Amount(msat=12345)), |
| 176 | description="hello", |
| 177 | label="lbl1", |
| 178 | )) |
| 179 | |
| 180 | |
| 181 | def test_grpc_generate_certificate(node_factory): |