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

Function test_check_command

tests/test_misc.py:2094–2158  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

2092
2093
2094def test_check_command(node_factory):
2095 l1 = node_factory.get_node()
2096
2097 l1.rpc.check(command_to_check='help')
2098 l1.rpc.check(command_to_check='help', command='check')
2099 # Actually checks that command is there!
2100 with pytest.raises(RpcError, match=r'Unknown command'):
2101 l1.rpc.check(command_to_check='help', command='badcommand')
2102 with pytest.raises(RpcError, match=r'Unknown command'):
2103 l1.rpc.check(command_to_check='badcommand')
2104 with pytest.raises(RpcError, match=r'unknown parameter'):
2105 l1.rpc.check(command_to_check='help', badarg='x')
2106
2107 # Ensures we have compulsory parameters.
2108 with pytest.raises(RpcError, match=r'missing required parameter'):
2109 l1.rpc.check(command_to_check='connect')
2110 # Even with optional parameters.
2111 with pytest.raises(RpcError, match=r'missing required parameter'):
2112 l1.rpc.check(command_to_check='connect', host='x', port=77)
2113 # Makes sure parameter types are correct.
2114 with pytest.raises(RpcError, match=r'should be a 16-bit integer'):
2115 l1.rpc.check(command_to_check='connect',
2116 id='022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59',
2117 host='x', port="abcd")
2118
2119 # FIXME: python wrapper doesn't let us test array params.
2120 sock = connect_unix(l1.rpc.socket_path)
2121
2122 sock.sendall(b'{"id":1, "jsonrpc":"2.0","method":"check","params":["help"]}')
2123 obj, _ = l1.rpc._readobj(sock, b'')
2124 assert obj['id'] == 1
2125 assert 'result' in obj
2126 assert 'error' not in obj
2127
2128 sock.sendall(b'{"id":1, "jsonrpc":"2.0","method":"check","params":["help", "check"]}')
2129 obj, _ = l1.rpc._readobj(sock, b'')
2130 assert obj['id'] == 1
2131 assert 'result' in obj
2132 assert 'error' not in obj
2133
2134 sock.sendall(b'{"id":1, "jsonrpc":"2.0","method":"check","params":["help", "a", "b"]}')
2135 obj, _ = l1.rpc._readobj(sock, b'')
2136 assert obj['id'] == 1
2137 assert 'result' not in obj
2138 assert 'error' in obj
2139
2140 sock.sendall(b'{"id":1, "jsonrpc":"2.0","method":"check","params":["badcommand"]}')
2141 obj, _ = l1.rpc._readobj(sock, b'')
2142 assert obj['id'] == 1
2143 assert 'result' not in obj
2144 assert 'error' in obj
2145
2146 sock.sendall(b'{"id":1, "jsonrpc":"2.0","method":"check","params":["connect"]}')
2147 obj, _ = l1.rpc._readobj(sock, b'')
2148 assert obj['id'] == 1
2149 assert 'result' not in obj
2150 assert 'error' in obj
2151

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected