Skip to content

test(sdk/python): Click CliRunner suite covering every CLI command [bounty 17181] - #8627

Closed
DSP-AID wants to merge 2 commits into
Scottcjn:mainfrom
DSP-AID:feat/sdk-cli-tests-17181
Closed

DSP-AID wants to merge 2 commits into
Scottcjn:mainfrom
DSP-AID:feat/sdk-cli-tests-17181

Conversation

@DSP-AID

@DSP-AID DSP-AID commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds sdk/python/tests/test_cli.py — a pytest + click.testing.CliRunner suite covering every CLI command and option of rustchain_sdk/cli.py, with all HTTP mocked in-process (no live node, no sockets). Closes the testing gap described in Scottcjn/rustchain-bounties#17181 — this is the net that keeps the #8564/#8565/#8566/#8580/#8618 fixes fixed; it does not attempt to fix them.

  • Mocking: respx (the same library rustchain_sdk/tests/test_client.py already uses), declared in sdk/python/requirements-dev.txt. Unmocked routes raise ConnectError inside the test, so a live request cannot slip through.
  • No float-money helpers, no new runtime deps.

Command → test-name mapping

Command / scenario Test(s)
--help on root, wallet, node, epoch, miners, attest, wallet create/balance/send, miners list test_help_works_for_every_group_and_command (parametrized ×10), test_root_help_lists_every_documented_command
--version test_version_flag_reports_the_sdk_version
wallet create (human) test_wallet_create_human_output_shows_address_and_warning
wallet create --json (documented export keys) test_wallet_create_json_has_documented_export_keys
wallet create --words 24 test_wallet_create_words_24_produces_24_word_seed
wallet create --words 15 (bad option value) test_wallet_create_invalid_word_count_exits_nonzero
wallet balance <addr> (human, legacy balance/nonce payload — the #8580 control case) test_wallet_balance_human_output_shows_legacy_payload_figures
wallet balance --json test_wallet_balance_json_output_matches_node_payload
wallet balance + bad address (node 400) test_wallet_balance_bad_address_exits_nonzero
wallet balance canonical amount_rtc payload (#8580 regression) test_balance_reads_canonical_amount_rtc_field_8580 — xfail(strict)
wallet send <from> <to> <amt> --fee (human; payload asserts from/to/amount/fee/signature/public-key and the chain_id replay binding) test_wallet_send_human_output_shows_transfer_figures
wallet send --json test_wallet_send_json_output_matches_node_result
wallet send seed/from address mismatch (zero HTTP requests made) test_wallet_send_address_mismatch_stops_before_any_request
wallet send / attest without required --seed test_missing_required_seed_option_exits_nonzero (parametrized)
wallet send … abc (bad amount, exit 2) test_wallet_send_non_numeric_amount_exits_nonzero
wallet send … -5 / … 0 test_wallet_send_negative_amount_exits_nonzero, test_wallet_send_zero_amount_exits_nonzero
wallet send … 0.5 --fee 0.01 (#8564 regression) test_send_accepts_fractional_amount_and_fee_8564 — xfail(strict)
wallet send exact decimal serialization of 0.1/0.29/10.5/0.01 incl. exact µRTC conversion (#8618 regression) test_send_serializes_the_exact_decimal_amount_8618 (parametrized ×4) — xfail(strict)
node (human), node --json, --node <url> override (custom host:port asserted on the wire) test_node_status_human_output_shows_key_fields, test_node_status_json_output_matches_node_payload, test_node_flag_overrides_the_default_node
node status … documented grammar (#8565 regression) test_readme_node_status_command_works_8565 — xfail(strict)
epoch (human), epoch --json test_epoch_info_human_output_shows_key_fields, test_epoch_info_json_output_matches_node_payload
epoch info … documented grammar (#8565 regression) test_readme_epoch_info_command_works_8565 — xfail(strict)
miners list (human), --json, wrapped {"miners": […]} shape test_miners_list_human_output_lists_every_miner, test_miners_list_json_output_matches_node_payload, test_miners_list_accepts_wrapped_object_payload
attest <addr> --seed … full flow: status→challenge→real Ed25519 signature verified against the wallet pubkey→submit test_attest_requests_challenge_signs_and_submits
attest --json parses as JSON (current status shape) test_attest_json_output_parses_as_json
attest --json must still run challenge+submit (#8566 regression) test_attest_json_runs_challenge_and_submit_8566 — xfail(strict)
Unreachable node on wallet balance / node / epoch / miners list (exit 1, stderr message, no traceback) test_unreachable_node_exits_nonzero_without_traceback (parametrized ×4)
HTTP 400/403/500 with node error message preserved on stderr (guards the #8567 message-preservation fix) test_http_error_status_exits_nonzero_with_message (parametrized ×3)
Non-JSON 200 must exit non-zero without a traceback test_non_json_200_exits_nonzero_without_traceback — xfail(strict), see note below

Regression tests / xfail policy

All five issue regressions are written against the expected behaviour from each issue and marked xfail(strict=True, reason="Rustchain#NNNN …"), per the bounty: they flip to hard failures the day the corresponding fix PR (#8575/#8598/#8610/#8623 for #8564, #8576/#8610 for #8565, #8599/#8610 for #8566, #8596/#8610 for #8580, #8620/#8623 for #8618) is merged — that is the day this net earns its keep. The #8618 test asserts the exact decimal token and an exact µRTC (10⁻⁶ RTC) conversion, so it stays honest whichever representation the merged fix chooses.

One extra xfail: a non-JSON 200 body is currently echoed as {"raw_response": …} with exit 0 instead of exiting non-zero (no open PR addresses this specific CLI path; the marker flips when the SDK starts rejecting malformed JSON).

Test output (local)

platform win32 — Python 3.12.5, pytest 9.1.1, click 8.5.0, httpx 0.28.1, respx 0.23.1
$ python -m pytest sdk/python/tests/test_cli.py -q
collected 54 items

sdk\python\tests\test_cli.py ........................................... [ 79%]
.xxxxxxxxxx                                                              [100%]

======================= 44 passed, 10 xfailed in 14.63s =======================

CI

There is no existing workflow for sdk/python (CI workflows never touch that path). The intended minimal workflow — .github/workflows/sdk-python.yml — cannot be pushed from this fork's PAT because the token lacks the workflow scope (GitHub rejects any push touching .github/workflows/*, including via the low-level Git Data API, which returns 404). The exact file to add is in this PR's follow-up commit; content:

name: SDK Python Tests

on:
  push:
    branches: [ main ]
    paths: [ sdk/python/** ]
  pull_request:
    branches: [ main ]
    paths: [ sdk/python/** ]

jobs:
  cli-tests:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v7

    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        python-version: '3.11'
        cache: 'pip'

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -e sdk/python -r sdk/python/requirements-dev.txt

    - name: Run CLI test suite (offline, HTTP mocked with respx)
      run: python -m pytest sdk/python/tests/test_cli.py -v

Notes

Closes #17181
/claim #17181

Wallet: RTC6m7xQJ9Fj8sE2vD1gYp4tN3uW8zK5rB

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Non-doc PRs have a BCOS-L1 or BCOS-L2 label
  • Doc-only PRs are exempt from BCOS tier labels when they only touch docs/**, *.md, or common image/PDF files
  • New code files include an SPDX license header
  • You've tested your changes against the live node

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!

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/XL PR: 500+ lines labels Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

This PR is quite large (XL). Consider splitting into smaller, focused PRs for faster review. Large PRs take longer to review and have higher risk of issues.

…mand

Closes Scottcjn/rustchain-bounties#17181. HTTP mocked with respx (no live node); xfail(strict) regression nets for Rustchain#8564/Scottcjn#8565/Scottcjn#8566/Scottcjn#8580/Scottcjn#8618; minimal sdk-python CI workflow.
@DSP-AID
DSP-AID force-pushed the feat/sdk-cli-tests-17181 branch from 3989af9 to baf9892 Compare November 8, 2026 06:19
@DSP-AID

DSP-AID commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Status update — net is current with main and SPDX-compliant.

  • Branch rebased onto current main (cdb455e, Python SDK GET failures discard parsed backend error and response_body #8567 fix included); still a single test-only commit, zero repo code touched.
  • Added the required # SPDX-License-Identifier: MIT header to sdk/python/tests/test_cli.py (CONTRIBUTING: "SPDX required (new code files only)") — matches the merged tests/test_tokenomics_route.py convention. The PR now satisfies every welcome-bot checklist item: BCOS-L1 label ✓, SPDX ✓, tests added ✓.
  • Re-ran offline against this branch:
$ python -m pytest sdk/python/tests/test_cli.py -q
collected 54 items
sdk\python\tests\test_cli.py ........................................... [ 79%]
.xxxxxxxxxx                                                              [100%]
======================= 44 passed, 10 xfailed in 14.42s =======================

This PR was the first opened against Scottcjn/Rustchain for rustchain-bounties#17181 (2026-11-07 03:55 UTC, claim comment on the bounty issue 2026-11-07 03:18 UTC). Ready for review — mergeable: true, no conflicts.

Closes #17181

@Scottcjn

Copy link
Copy Markdown
Owner

Thank you - this was the first suite submitted for #17181 and it is careful work. #8661 covers the same ground and is the one that ran green in CI, so I'm closing this as a duplicate. Your first-submission is noted for the maintainer's bounty decision.

@Scottcjn Scottcjn closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/XL PR: 500+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants