Equivalent functional test, maybe easier to read:
diff --git a/test/functional/interface_ipc.py b/test/functional/interface_ipc.py
index 2c11f88305..119591a675 100755
--- a/test/functional/interface_ipc.py
+++ b/test/functional/interface_ipc.py
@@ -5,4 +5,5 @@
"""Test the IPC (multiprocess) interface."""
import asyncio
+import json
from contextlib import ExitStack
@@ -10,4 +11,5 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
from test_framework.ipc_util import (
+ assert_capnp_failed,
load_capnp_modules,
make_capnp_init_ctx,
@@ -52,4 +54,22 @@ class IPCInterfaceTest(BitcoinTestFramework):
asyncio.run(capnp.run(async_routine()))
+ def run_rpc_invalid_json_test(self):
+ self.log.info("Running RPC invalid JSON test")
+ async def async_routine():
+ ctx, init = await make_capnp_init_ctx(self)
+ self.log.debug("Create Rpc proxy object")
+ rpc = init.makeRpc(ctx).result
+ self.log.debug("Invalid JSON in an executeRpc request must be rejected")
+ try:
+ await rpc.executeRpc(ctx, "invalid json", "/", "")
+ raise AssertionError("executeRpc unexpectedly succeeded")
+ except capnp.KjException as e:
+ assert_capnp_failed(e, "remote exception: std::exception: invalid JSON received over IPC")
+ self.log.debug("The connection still works after the failed call")
+ request = json.dumps({"method": "getblockcount", "params": [], "id": 1})
+ response = json.loads((await rpc.executeRpc(ctx, request, "/", "")).result)
+ assert_equal(response["result"], self.nodes[0].getblockcount())
+ asyncio.run(capnp.run(async_routine()))
+
def run_mining_test(self):
self.log.info("Running mining test")
@@ -165,4 +185,5 @@ class IPCInterfaceTest(BitcoinTestFramework):
def run_test(self):
self.run_echo_test()
+ self.run_rpc_invalid_json_test()
self.run_mining_test()
self.run_deprecated_mining_test()