MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / assert_raises_rpc_error

Function assert_raises_rpc_error

test/functional/test_framework/util.py:155–171  ·  view source on GitHub ↗

Run an RPC and verify that a specific JSONRPC exception code and message is raised. Calls function `fun` with arguments `args` and `kwds`. Catches a JSONRPCException and verifies that the error code and message are as expected. Throws AssertionError if no JSONRPCException was raised or

(code: Optional[int], message: Optional[str], fun: Callable, *args, **kwds)

Source from the content-addressed store, hash-verified

153
154
155def assert_raises_rpc_error(code: Optional[int], message: Optional[str], fun: Callable, *args, **kwds):
156 """Run an RPC and verify that a specific JSONRPC exception code and message is raised.
157
158 Calls function `fun` with arguments `args` and `kwds`. Catches a JSONRPCException
159 and verifies that the error code and message are as expected. Throws AssertionError if
160 no JSONRPCException was raised or if the error code/message are not as expected.
161
162 Args:
163 code: the error code returned by the RPC call (defined in src/rpc/protocol.h).
164 Set to None if checking the error code is not required.
165 message: [a substring of] the error string returned by the RPC call.
166 Set to None if checking the error string is not required.
167 fun: the function to call. This should be the name of an RPC.
168 args*: positional arguments for the function.
169 kwds**: named arguments for the function.
170 """
171 assert try_rpc(code, message, fun, *args, **kwds), "No exception raised"
172
173
174def try_rpc(code, message, fun, *args, **kwds):

Calls 1

try_rpcFunction · 0.85