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

Function test_malformed_rpc

tests/test_misc.py:957–996  ·  view source on GitHub ↗

Test that we get a correct response to malformed RPC commands

(node_factory)

Source from the content-addressed store, hash-verified

955
956
957def test_malformed_rpc(node_factory):
958 """Test that we get a correct response to malformed RPC commands"""
959 l1 = node_factory.get_node()
960
961 sock = connect_unix(l1.rpc.socket_path)
962
963 # No ID
964 sock.sendall(b'{"jsonrpc":"2.0","method":"getinfo","params":[]}')
965 obj, _ = l1.rpc._readobj(sock, b'')
966 assert obj['error']['code'] == -32600
967
968 # No method
969 sock.sendall(b'{"id":1, "jsonrpc":"2.0","params":[]}')
970 obj, _ = l1.rpc._readobj(sock, b'')
971 assert obj['error']['code'] == -32600
972
973 # Complete crap: needs } to even try parsing, and also this makes it hang up!
974 sock.sendall(b'[]}')
975 obj, _ = l1.rpc._readobj(sock, b'')
976 assert obj['error']['code'] == -32600
977
978 sock.close()
979 sock = connect_unix(l1.rpc.socket_path)
980
981 # Bad ID
982 sock.sendall(b'{"id":{}, "jsonrpc":"2.0","method":"getinfo","params":[]}')
983 obj, _ = l1.rpc._readobj(sock, b'')
984 assert obj['error']['code'] == -32600
985
986 # Bad method
987 sock.sendall(b'{"id":1, "method": 12, "jsonrpc":"2.0","params":[]}')
988 obj, _ = l1.rpc._readobj(sock, b'')
989 assert obj['error']['code'] == -32600
990
991 # Unknown method
992 sock.sendall(b'{"id":1, "method": "unknown", "jsonrpc":"2.0","params":[]}')
993 obj, _ = l1.rpc._readobj(sock, b'')
994 assert obj['error']['code'] == -32601
995
996 sock.close()
997
998
999def test_valid_json_cli(node_factory):

Callers

nothing calls this directly

Calls 5

connect_unixFunction · 0.85
sendallMethod · 0.80
_readobjMethod · 0.80
get_nodeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected