Merge bitcoin/bitcoin#35868: rpc, wallet: fix invalid JSON in HelpExampleRpc curl examples

21d4e0ba75 rpc, wallet, test: fix invalid JSON in HelpExampleRpc curl examples (GuTS805)

Pull request description:

  Several `HelpExampleRpc` call sites reused CLI-style argument strings
  verbatim instead of valid JSON — missing commas, bare unquoted words, or
  single backslashes that are not valid JSON escapes. As a result the
  documented `curl` command for 14 RPCs (`getblockfrompeer`, `addnode`,
  `addconnection`, `sendmsgtopeer`, `restorewallet`, `getmempoolcluster`,
  `importmempool`, `getindexinfo`, `listlabels`, `unloadwallet`,
  `createwalletdescriptor`, `addhdkey`, `loadwallet`, `listunspent`) fails
  to parse as JSON if copy-pasted as-is. Also fixes a stray trailing quote
  in the `restorewallet` named-argument examples.

  This was previously raised in #31275, which sipa confirmed at runtime by
  adding a `UniValue::read` check, but that PR was closed unmerged. Since
  then two more examples broke the same way (`getmempoolcluster`,
  `addhdkey`), which is why this adds a permanent regression check to
  `rpc_help.py::dump_help()` instead of just fixing the current list.

  Fixes #35864.

ACKs for top commit:
  maflcko:
    review ACK 21d4e0ba75 🚝
  sedited:
    ACK 21d4e0ba75

Tree-SHA512: 2a8abc07d681b9dc81b8079a68421278da890049cea33a1561a48d53cbf919a30df588f559e9df94fa4a1ab7027f742f3b12c163afc25246a620340cb3522336
This commit is contained in:
merge-script
2026-08-29 10:33:22 +02:00
9 changed files with 26 additions and 17 deletions

View File

@@ -8,6 +8,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error
from collections import defaultdict
import json
import os
import re
@@ -153,9 +154,17 @@ class HelpRpcTest(BitcoinTestFramework):
os.mkdir(dump_dir)
calls = [line.split(' ', 1)[0] for line in self.nodes[0].help().splitlines() if line and not line.startswith('==')]
for call in calls:
help_text = self.nodes[0].help(call)
with open(os.path.join(dump_dir, call), 'w') as f:
# Make sure the node can generate the help at runtime without crashing
f.write(self.nodes[0].help(call))
f.write(help_text)
# Make sure any curl examples have a JSON-RPC payload that is valid JSON
for match in re.finditer(r"--data-binary '(.*)' -H", help_text):
payload = match.group(1)
try:
json.loads(payload)
except json.JSONDecodeError as e:
raise AssertionError(f"HelpExampleRpc for '{call}' is not valid JSON: {payload!r}\n{e}")
def wallet_help(self):
assert 'getnewaddress ( "label" "address_type" )' in self.nodes[0].help('getnewaddress')