diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 0c190ee936b..03ece6f064a 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -165,13 +165,13 @@ def try_rpc(code, message, fun, *args, **kwds): try: fun(*args, **kwds) except JSONRPCException as e: - # 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"]) + # JSONRPCException was thrown as expected. Check the message and code values are correct. if (message is not None) and (message not in e.error['message']): raise AssertionError( "Expected substring not found in error message:\nsubstring: '{}'\nerror message: '{}'.".format( message, e.error['message'])) + if (code is not None) and (code != e.error["code"]): + raise AssertionError("Unexpected JSONRPC error code %i" % e.error["code"]) return True except Exception as e: raise AssertionError("Unexpected exception raised: " + type(e).__name__)