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

Function test_methods_errors

contrib/pyln-client/tests/test_plugin.py:116–172  ·  view source on GitHub ↗

A bunch of tests that should fail calling the methods.

()

Source from the content-addressed store, hash-verified

114
115
116def test_methods_errors():
117 """A bunch of tests that should fail calling the methods."""
118 call_list = []
119 p = Plugin(autopatch=False)
120
121 # Fails because we haven't added the method yet
122 request = p._parse_request({
123 'id': 1,
124 'jsonrpc': '2.0',
125 'method': 'test1',
126 'params': {}
127 })
128 with pytest.raises(ValueError):
129 p._dispatch_request(request)
130 assert call_list == []
131
132 @p.method("test1")
133 def test1(name):
134 call_list.append(test1)
135
136 # Attempting to add it twice should fail
137 with pytest.raises(ValueError):
138 p.add_method("test1", test1)
139
140 # Fails because it is missing the 'name' argument
141 request = p._parse_request({'id': 1, 'jsonrpc': '2.0', 'method': 'test1', 'params': {}})
142 with pytest.raises(TypeError):
143 p._exec_func(test1, request)
144 assert call_list == []
145
146 # The same with positional arguments
147 request = p._parse_request({'id': 1, 'jsonrpc': '2.0', 'method': 'test1', 'params': []})
148 with pytest.raises(TypeError):
149 p._exec_func(test1, request)
150 assert call_list == []
151
152 # Fails because we have a non-matching argument
153 request = p._parse_request({
154 'id': 1,
155 'jsonrpc': '2.0',
156 'method': 'test1',
157 'params': {'name': 'World', 'extra': 1}
158 })
159 with pytest.raises(TypeError):
160 p._exec_func(test1, request)
161 assert call_list == []
162
163 request = p._parse_request({
164 'id': 1,
165 'jsonrpc': '2.0',
166 'method': 'test1',
167 'params': ['World', 1]
168 })
169
170 with pytest.raises(TypeError):
171 p._exec_func(test1, request)
172 assert call_list == []
173

Callers

nothing calls this directly

Calls 5

_parse_requestMethod · 0.95
_dispatch_requestMethod · 0.95
add_methodMethod · 0.95
_exec_funcMethod · 0.95
PluginClass · 0.90

Tested by

no test coverage detected