Skip to content

refactor(koalabear): drop tests-only Fp.__bytes__ - #749

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/koalabear-bytes
May 21, 2026
Merged

refactor(koalabear): drop tests-only Fp.__bytes__#749
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/koalabear-bytes

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

Summary

Fp.__bytes__ only enabled bytes(fp) syntactic sugar used by a handful of test sites. No production code calls it — the canonical SSZ path is Fp.encode_bytes().

  • src/lean_spec/subspecs/koalabear/field.py (−11 lines): Fp.__bytes__ deleted.
  • tests/lean_spec/subspecs/koalabear/test_field.py (−40 lines net):
    • test_bytes_protocol deleted entirely. The decode_bytes error paths it exercised (wrong length, exceeds modulus) are already covered by the dedicated test_ssz_deserialize_wrong_scope, test_ssz_deserialize_short_data, and test_ssz_deserialize_exceeds_modulus tests.
    • test_ssz_roundtrip and test_ssz_deterministic simplified — removed the bytes(fp) vs encode_bytes() cross-checks, which become meaningless without the dunder. The encode-decode roundtrip and encode determinism are still asserted.

Test plan

  • ruff check — clean.
  • uv run pytest tests/lean_spec/subspecs/koalabear/test_field.py — 11 tests pass.
  • grep -r "bytes(.*Fp\|__bytes__" across src/, tests/, packages/ — no remaining production references to Fp.__bytes__.

🤖 Generated with Claude Code

The dunder only enabled bytes(fp) syntactic sugar that no production
code used. Fp.encode_bytes() is the canonical SSZ path.

Removed test_bytes_protocol entirely; its decode_bytes error checks
(wrong length and exceeds-modulus) are already covered by the
dedicated tests at test_ssz_deserialize_wrong_scope,
test_ssz_deserialize_short_data, and test_ssz_deserialize_exceeds_modulus.

Simplified test_ssz_roundtrip and test_ssz_deterministic by dropping
the bytes(fp) versus encode_bytes() cross-checks; without the dunder
those comparisons are meaningless. The encode-decode roundtrip and
encode determinism are still asserted.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tcoratger
tcoratger merged commit 89d4274 into leanEthereum:main May 21, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant