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

Function test_rpc_method

tests/test_clnrest.py:187–239  ·  view source on GitHub ↗

Test POST requests on `/v1/ ` end points with default values for options.

(node_factory)

Source from the content-addressed store, hash-verified

185
186
187def test_rpc_method(node_factory):
188 """Test POST requests on `/v1/<rpc_method>` end points with default values for options."""
189 # start a node with clnrest
190 l1, base_url, ca_cert = start_node_with_clnrest(node_factory)
191 http_session = http_session_with_retry()
192
193 # /v1/getinfo no rune provided in header of the request
194 response = http_session.post(base_url + '/v1/getinfo', verify=ca_cert)
195 assert response.status_code == 403
196 assert response.json()['code'] == 1501
197 assert response.json()['message'] == 'Not authorized: Missing rune'
198
199 # /v1/getinfo with a rune which doesn't authorized getinfo method
200 rune_no_getinfo = l1.rpc.createrune(restrictions=[["method/getinfo"]])['rune']
201 response = http_session.post(base_url + '/v1/getinfo', headers={'Rune': rune_no_getinfo},
202 verify=ca_cert)
203 assert response.status_code == 401
204 assert response.json()['code'] == 1502
205 assert response.json()['message'] == 'Not permitted: method is equal to getinfo'
206
207 # /v1/getinfo with a correct rune
208 rune_getinfo = l1.rpc.createrune(restrictions=[["method=getinfo"]])['rune']
209 response = http_session.post(base_url + '/v1/getinfo', headers={'Rune': rune_getinfo},
210 verify=ca_cert)
211 assert response.status_code == 201
212 assert response.json()['id'] == l1.info['id']
213
214 # /v1/invoice with a correct rune but missing parameters
215 rune_invoice = l1.rpc.createrune(restrictions=[["method=invoice"]])['rune']
216 response = http_session.post(base_url + '/v1/invoice', headers={'Rune': rune_invoice},
217 verify=ca_cert)
218 assert response.status_code == 500
219 assert response.json()['code'] == -32602
220
221 # /v1/invoice with a correct rune but wrong parameters
222 rune_invoice = l1.rpc.createrune(restrictions=[["method=invoice"]])['rune']
223 response = http_session.post(base_url + '/v1/invoice', headers={'Rune': rune_invoice},
224 data={'amount_msat': '<WRONG>',
225 'label': 'label',
226 'description': 'description'},
227 verify=ca_cert)
228 assert response.status_code == 500
229 assert response.json()['code'] == -32602
230
231 # l2 pays l1's invoice where the invoice is created with /v1/invoice
232 rune_invoice = l1.rpc.createrune(restrictions=[["method=invoice"]])['rune']
233 response = http_session.post(base_url + '/v1/invoice', headers={'Rune': rune_invoice},
234 data={'amount_msat': '50000000',
235 'label': 'label',
236 'description': 'description'},
237 verify=ca_cert)
238 assert response.status_code == 201
239 assert 'bolt11' in response.json()
240
241
242def test_large_response(node_factory):

Callers

nothing calls this directly

Calls 3

start_node_with_clnrestFunction · 0.85
http_session_with_retryFunction · 0.85
jsonMethod · 0.80

Tested by

no test coverage detected