Skip to content

test: add 100% coverage for BaseUint arithmetic operators#530

Merged
tcoratger merged 1 commit intoleanEthereum:mainfrom
tcoratger:test/uint-operator-coverage
Apr 7, 2026
Merged

test: add 100% coverage for BaseUint arithmetic operators#530
tcoratger merged 1 commit intoleanEthereum:mainfrom
tcoratger:test/uint-operator-coverage

Conversation

@tcoratger
Copy link
Copy Markdown
Collaborator

Summary

  • Adds 116 new tests (275 total) achieving 100% isolated coverage for src/lean_spec/types/uint.py (197 statements, 56 branches, 0 missing)
  • Covers all previously uncovered operator paths: forward type errors, reverse success paths, pow with modulo, reverse divmod/bitwise/shift, comparison type errors, and __index__

Closes #521

Spec compliance audit

Cross-referenced against the SSZ specification:

Requirement Status
Little-endian serialization Correct
Fixed-size property (N/8 bytes) Correct
Range [0, 2^N - 1] Correct
Uint8/16/32/64 defined Correct
Pydantic schema validation Correct

No bugs found. Two design notes (not spec violations):

  • __pow__/shift accept plain int while arithmetic requires BaseUint — pragmatic inconsistency (shift amounts are naturally plain ints)
  • __eq__ raises TypeError on non-BaseUint — deliberate strictness for spec code safety

Test plan

  • All 275 tests pass (uv run pytest tests/lean_spec/types/test_uint.py -v)
  • 100% isolated coverage (--cov=lean_spec.types.uint --cov-report=term-missing)
  • All quality checks pass (uvx tox -e all-checks)

🤖 Generated with Claude Code

Closes leanEthereum#521. Adds 116 new tests (275 total) achieving 100% isolated
coverage for types/uint.py (197 statements, 56 branches, 0 missing).

Covers all previously uncovered operator paths:
- Forward arithmetic type errors (__add__, __sub__, etc. with plain int)
- Reverse arithmetic success paths (__radd__, __rsub__, etc.)
- Exponentiation with modulo and reverse pow
- Reverse divmod
- Reverse bitwise delegation (__rand__, __ror__, __rxor__)
- Reverse shift operators (__rlshift__, __rrshift__)
- Comparison type errors (__lt__, __le__ with plain int)
- __index__ returns plain int

Spec audit confirms SSZ serialization, deserialization, ranges, and
fixed-size properties are all correct per the SSZ specification.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tcoratger tcoratger merged commit 14d3081 into leanEthereum:main Apr 7, 2026
12 of 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.

test: improve coverage for BaseUint arithmetic operators (81%)

1 participant