mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-11 21:20:39 +02:00
rpc, wallet, test: fix invalid JSON in HelpExampleRpc curl examples
Several HelpExampleRpc call sites reused CLI-style argument strings verbatim (missing commas, bare unquoted words, or single backslashes that are not valid JSON escapes), producing curl examples that fail JSON parsing as documented. Also fixes a stray trailing quote in the restorewallet named-argument examples, a missing comma in the listunspent example, and a wrong-schema string-instead-of-array listunspent argument caught in review. Lines touched are converted to raw string literals (or strprintf with a raw string template) throughout, for consistency and to avoid manual quote/backslash escaping. Adds a regression check to rpc_help.py::dump_help() so this class of bug can't silently reappear.
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user