Repository navigation
Conversation
…ance path, offline pytest for check_balance.sh (Scottcjn#7889)
Contributor
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
4 tasks
This branch has not been deployed
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.
Consistent error handling + exit codes — wallet balance check
Addresses #7889 (base fix was merged earlier in #8024; this PR closes the remaining inconsistencies that were still live on
main).Bounty issue: Scottcjn/rustchain-bounties#16253
Inconsistencies fixed (enumerated per acceptance criteria)
Pre-existing in the merged
scripts/check_balance.shonmain:Malformed JSON was not reported distinctly — a non-JSON body (e.g. an nginx HTML error page behind a proxy) fell through to
Error: response missing amount_rtc field. Issue Bug: Inconsistent Error Handling in Wallet Balance Check Script #7889 / bounty deliverable DOS Tools Initial Upload #1 explicitly requires malformed JSON to produce a clear, distinct message. → Now:Error: malformed JSON response from <URL>(exit 3), while themissing amount_rtcmessage is reserved for well-formed JSON that lacks the field.Missing
jqsilently misreported as a bad response — withoutjq, everyjqcall is swallowed by2>/dev/null || true, so users on hosts withoutjqgotError: response missing amount_rtc field(exit 3) instead of a clear dependency error. → Now an explicit preflight check:Error: required dependency 'jq' is not installed(exit 1), documented in the header comment and--help.Default request path did not match the repo's own API contract — the script requested
/api/balance?wallet=…, which returns HTTP 404 against the public RPC and against the documented read-only contract (compatibility_lab/read_only_api.openapi.json→getWalletBalance=GET /wallet/balance?miner_id=…). A balance tool whose default happy path always errors is exactly the Bug: Inconsistent Error Handling in Wallet Balance Check Script #7889 complaint ("can confuse users troubleshooting miner setup"). → Now uses the contract path/wallet/balance?miner_id=…; live probe:Exit-code scheme unchanged and now fully accurate in
--help/ header:0ok,1usage/environment (incl. missing jq),2network,3bad response.Tests (no behavior change on the happy path)
New hermetic suite
tests/test_check_balance_script_7889.py— runs the real bash script against a local HTTP stub (no external network; connection-refused via closed port), so it is collected by the existingpytest tests/CI step. Skips cleanly on hosts without bash/jq (Windows). Covers every failure path: no args,--help, invalid wallet, missing jq, connection refused, non-200, empty body, malformed JSON (asserts the distinct message), missing field, non-numeric amount, wallet mismatch, and the happy path (stdout = balance only, exit 0).Live transcript after the change (docker
python:3.11-bookworm, curl+jq):Acceptance criteria
balance\n, exit 0; output format untouched)