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)
| 153 | |
| 154 | |
| 155 | def 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 | |
| 174 | def try_rpc(code, message, fun, *args, **kwds): |