Skip to content

refactor: extract duplicate network/contract resolution to _resolve_contract_and_network helper#442

Merged
anderdc merged 2 commits intoentrius:testfrom
bittoby:refactor/extract-network-resolution-boilerplate
Apr 15, 2026
Merged

refactor: extract duplicate network/contract resolution to _resolve_contract_and_network helper#442
anderdc merged 2 commits intoentrius:testfrom
bittoby:refactor/extract-network-resolution-boilerplate

Conversation

@bittoby
Copy link
Copy Markdown
Contributor

@bittoby bittoby commented Apr 15, 2026

Summary

Every issue CLI command started with the same 5-line block - get_contract_address, resolve_network, then an if not contract_addr guard. This was copy-pasted across 15 call sites in 4 files. Extracted it into _resolve_contract_and_network() in helpers.py

What changed

  • Added _resolve_contract_and_network(contract, network, rpc_url) to helpers.py. Returns (contract_addr, ws_endpoint, network_name), raises click.ClickException if contract is empty. Accepts an optional missing_contract_message for the 3 commands that had custom error text.
  • Replaced all 15 duplicated blocks:
    • admin.py - 6 commands
    • view.py - 4 commands (1 with custom error message)
    • vote.py - 3 commands
    • mutations.py - 2 commands (both with custom error messages)
  • submissions.py left unchanged - it uses handle_exception(as_json, ...) instead of raise, so the shared helper doesn't fit.
  • Updated test patches to mock _resolve_contract_and_network instead of the removed module-level imports.

Testing

  • Ruff lint: clean
  • Ruff format: clean
  • Pyright: 0 errors, 0 warnings
  • Pytest: 300 passed, 0 failed

@bittoby
Copy link
Copy Markdown
Contributor Author

bittoby commented Apr 15, 2026

@anderdc Pls review this PR.

@anderdc anderdc merged commit 8060e32 into entrius:test Apr 15, 2026
4 checks passed
@anderdc anderdc added the refactor Code restructuring without behavior change label Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants