Repository navigation
Conversation
Contributor
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. LLM Linter (✨ experimental)Possible places where named args for integral literals may be used (e.g.
2026-12-03 14:20:16 |
This was referenced Nov 27, 2026
l0rinc
force-pushed
the
l0rinc/test-rpc-error-codes
branch
from
November 27, 2026 12:16
f8c5b6c to
7599576
Compare
This was referenced Nov 27, 2026
Open
Open
This was referenced Nov 28, 2026
Expose `RPCErrorCode` to the Python functional tests using the names, values, and aliases from `src/rpc/protocol.h`. Add a note beside the C++ enum to keep the Python definitions in sync. -BEGIN VERIFY SCRIPT- rpc_codes_file=test/functional/test_framework/rpc_error_codes.py sed -n '2,4p' test/functional/feature_io_errors.py > "$rpc_codes_file" printf '\n# Values from RPCErrorCode in src/rpc/protocol.h.\n' >> "$rpc_codes_file" sed -nE '/^enum RPCErrorCode$/,/^};$/s/^ (RPC_[A-Z0-9_]+) *= ([^,]+),.*/\1 = \2/p' src/rpc/protocol.h >> "$rpc_codes_file" sed -i "/^enum RPCErrorCode$/i //! Keep $rpc_codes_file in sync with this enum." src/rpc/protocol.h git add -N "$rpc_codes_file" -END VERIFY SCRIPT-
Replace numeric first arguments to `assert_raises_rpc_error` with their primary `RPCErrorCode` names and import the constants each test uses.
-BEGIN VERIFY SCRIPT-
python3 - <<'PY'
import re
from pathlib import Path
definitions = Path("test/functional/test_framework/rpc_error_codes.py").read_text()
codes = {value: name for name, value in re.findall(r"^(RPC_\w+) = (-\d+)$", definitions, re.M)}
calls = re.compile(r"(^[ \t]*assert_raises_rpc_error\(\s*)(-\d+)\b", re.M)
for path in Path("test/functional").glob("*.py"):
source = path.read_text()
used = sorted({codes[value] for _, value in calls.findall(source)})
if not used:
continue
imports = used[0] if len(used) == 1 else "(\n " + ",\n ".join(used) + ",\n)"
source = calls.sub(lambda match: match[1] + codes[match[2]], source)
source = re.sub(
r"^from test_framework\.(?:script\w*|test_framework|util) import",
lambda match: f"from test_framework.rpc_error_codes import {imports}\n{match[0]}",
source, count=1, flags=re.M,
)
path.write_text(source)
PY
-END VERIFY SCRIPT-
Use the named codes in the C++ RPC unit tests and in Python checks outside the scripted conversion. Give the errors generated by the test client their own constants so `AuthServiceProxy` and `TestNodeCLI` can share the HTTP error code.
l0rinc
force-pushed
the
l0rinc/test-rpc-error-codes
branch
from
December 3, 2026 14:19
7599576 to
ec534b0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem: When a test expects an RPC error by number, readers have to look up the code to tell which failure it covers.
Fix: Use the
RPCErrorCodenames in the C++ RPC tests and mirror the enum in the Python test framework.Give the test client’s errors their own constants so
AuthServiceProxyandTestNodeCLIcan share the HTTP error code.I split this out while reviewing #36976.
Compare the original numeric error codes
Run this diff to inline the constants back to validate that the values haven't changed.