Skip to content

fix: remove dead branches in _encode_args and compact length encoder - #988

Closed
aliangm wants to merge 1 commit into
entrius:testfrom
aliangm:fix-contract-dead-branches
Closed

fix: remove dead branches in _encode_args and compact length encoder#988
aliangm wants to merge 1 commit into
entrius:testfrom
aliangm:fix-contract-dead-branches

Conversation

@aliangm

@aliangm aliangm commented May 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #987

Summary

Removes three dead/unreachable branches in contract_client.py that contained incorrect code and replaced them with assertions that make the invariants explicit.

  • Compact encode else branch (_call_contract_method_raw): input_data is always a 4-byte selector so data_len is always 4 — the else (data_len ≥ 64) was never reached. The formula was also wrong: (data_len << 2) | 1 overflows a single byte for data_len ≥ 64, producing a ValueError if ever triggered.
  • u128 branch in _encode_args: only register_issue uses u128, but that method is called from the CLI via a different execution path (ContractInstance.exec), never through _exec_contract_raw_encode_args.
  • else: raise ValueError fallback in _encode_args: only str (from register_issue) and unknown (from get_issues_by_status) would reach this branch — neither method is routed through _encode_args.

Changes

  • Replace compact encode if/else with assert data_len < 64
  • Remove unreachable u128 encoder branch
  • Replace raise ValueError fallback with assert False and an explanatory message

Testing

No behavior change for any current caller. The assertions will surface loudly if a future refactor accidentally routes a new method through these paths.

@xiao-xiao-mao xiao-xiao-mao Bot added the refactor Code restructuring without behavior change label May 5, 2026
@aliangm
aliangm force-pushed the fix-contract-dead-branches branch from d6e69c6 to e03bd7f Compare May 5, 2026 10:22
@anderdc

anderdc commented May 5, 2026

Copy link
Copy Markdown
Collaborator

Branches are unreachable as the issue notes; replacing them with assert is no functional change (asserts strip under -O). Closing.

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.

fix: remove dead branches in _encode_args and compact length encoder

2 participants