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

Function test_commando

tests/test_plugin.py:3180–3275  ·  view source on GitHub ↗
(node_factory, executor)

Source from the content-addressed store, hash-verified

3178
3179
3180def test_commando(node_factory, executor):
3181 l1, l2 = node_factory.line_graph(2, fundchannel=False,
3182 opts={'log-level': 'io'})
3183
3184 rune = l1.rpc.createrune()['rune']
3185
3186 # Bad rune fails
3187 with pytest.raises(RpcError, match="Not authorized: Not derived from master"):
3188 l2.rpc.call(method='commando',
3189 payload={'peer_id': l1.info['id'],
3190 'rune': 'VXY4AAkrPyH2vzSvOHnI7PDVfS6O04bRQLUCIUFJD5Y9NjQmbWV0aG9kPWludm9pY2UmcmF0ZT0yMZ==',
3191 'method': 'listpeers'})
3192
3193 # This works
3194 res = l2.rpc.call(method='commando',
3195 payload={'peer_id': l1.info['id'],
3196 'rune': rune,
3197 'method': 'listpeers'})
3198 assert len(res['peers']) == 1
3199 assert res['peers'][0]['id'] == l2.info['id']
3200
3201 # Check JSON id is as expected (unfortunately pytest does not use a reliable name
3202 # for itself: with -k it calls itself `-c` here, instead of `pytest`).
3203 l2.daemon.wait_for_log(r'plugin-commando: "[^:/]*:commando#[0-9]*/cln:commando#[0-9]*"\[OUT\]')
3204 l1.daemon.wait_for_log(r'jsonrpc#[0-9]*: "[^:/]*:commando#[0-9]*/cln:commando#[0-9]*/commando:listpeers#[0-9]*"\[IN\]')
3205
3206 res = l2.rpc.call(method='commando',
3207 payload={'peer_id': l1.info['id'],
3208 'rune': rune,
3209 'method': 'listpeers',
3210 'params': {'id': l2.info['id']}})
3211 assert len(res['peers']) == 1
3212 assert res['peers'][0]['id'] == l2.info['id']
3213
3214 # Filter test
3215 res = l2.rpc.call(method='commando',
3216 payload={'peer_id': l1.info['id'],
3217 'rune': rune,
3218 'method': 'listpeers',
3219 'filter': {'peers': [{'id': True}]}})
3220 assert res == {'peers': [{'id': l2.info['id']}]}
3221
3222 with pytest.raises(RpcError, match='missing required parameter'):
3223 l2.rpc.call(method='commando',
3224 payload={'peer_id': l1.info['id'],
3225 'rune': rune,
3226 'method': 'withdraw'})
3227
3228 with pytest.raises(RpcError, match='unknown parameter: foobar'):
3229 l2.rpc.call(method='commando',
3230 payload={'peer_id': l1.info['id'],
3231 'method': 'invoice',
3232 'rune': rune,
3233 'params': {'foobar': 1}})
3234
3235 ret = l2.rpc.call(method='commando',
3236 payload={'peer_id': l1.info['id'],
3237 'rune': rune,

Callers

nothing calls this directly

Calls 4

line_graphMethod · 0.80
wait_for_logMethod · 0.80
callMethod · 0.45
datastoreMethod · 0.45

Tested by

no test coverage detected