aboutsummaryrefslogtreecommitdiff
path: root/qa
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2017-02-10 18:02:10 +0100
committerMarcoFalke <falke.marco@gmail.com>2017-02-10 18:02:56 +0100
commitb860915f8b0dae98e57a254d11575ea41f5c5a79 (patch)
tree743d0c2798aa8181e31cf08e9f9ddfd7745f4c2b /qa
parent2447c1024e6069bfe62ddff65c4e1aaf28f32b38 (diff)
parent9db8eecac1c713c760c0217b6acb7455c657fa8b (diff)
downloadbitcoin-b860915f8b0dae98e57a254d11575ea41f5c5a79.tar.xz
Merge #9707: Fix RPC failure testing
9db8eec Fix RPC failure testing (John Newbery)
Diffstat (limited to 'qa')
-rwxr-xr-xqa/rpc-tests/rpcnamedargs.py2
-rw-r--r--qa/rpc-tests/test_framework/util.py23
2 files changed, 21 insertions, 4 deletions
diff --git a/qa/rpc-tests/rpcnamedargs.py b/qa/rpc-tests/rpcnamedargs.py
index 0484204668..da2d8f040f 100755
--- a/qa/rpc-tests/rpcnamedargs.py
+++ b/qa/rpc-tests/rpcnamedargs.py
@@ -37,7 +37,7 @@ class NamedArgumentTest(BitcoinTestFramework):
h = node.help(command='getinfo')
assert(h.startswith('getinfo\n'))
- assert_raises_jsonrpc(-8, node.help, random='getinfo')
+ assert_raises_jsonrpc(-8, 'Unknown named parameter', node.help, random='getinfo')
h = node.getblockhash(height=0)
node.getblock(blockhash=h)
diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py
index aca82c8b6f..dc8555c44c 100644
--- a/qa/rpc-tests/test_framework/util.py
+++ b/qa/rpc-tests/test_framework/util.py
@@ -550,13 +550,30 @@ def assert_raises_message(exc, message, fun, *args, **kwds):
else:
raise AssertionError("No exception raised")
-def assert_raises_jsonrpc(code, fun, *args, **kwds):
- '''Check for specific JSONRPC exception code'''
+def assert_raises_jsonrpc(code, message, fun, *args, **kwds):
+ """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 returned or if the error code/message are not as expected.
+
+ Args:
+ code (int), optional: the error code returned by the RPC call (defined
+ in src/rpc/protocol.h). Set to None if checking the error code is not required.
+ message (string), optional: [a substring of] the error string returned by the
+ RPC call. Set to None if checking the error string is not required
+ fun (function): the function to call. This should be the name of an RPC.
+ args*: positional arguments for the function.
+ kwds**: named arguments for the function.
+ """
try:
fun(*args, **kwds)
except JSONRPCException as e:
- if e.error["code"] != code:
+ # JSONRPCException was thrown as expected. Check the code and message values are correct.
+ if (code is not None) and (code != e.error["code"]):
raise AssertionError("Unexpected JSONRPC error code %i" % e.error["code"])
+ if (message is not None) and (message not in e.error['message']):
+ raise AssertionError("Expected substring not found:"+e.error['message'])
except Exception as e:
raise AssertionError("Unexpected exception raised: "+type(e).__name__)
else: