Commit 3b45c3d
refactor(types/uint): polish base uint type (leanEthereum#769)
* fix(types/uint): enforce strict same-type equality across widths
The hash mixes in the concrete subclass, so allowing cross-width equality
broke the hash/eq contract: Uint8(5) == Uint16(5) returned True while
hash(Uint8(5)) != hash(Uint16(5)), silently corrupting set and dict
membership. Tighten __eq__ and __ne__ to require type(other) is type(self)
and add parametrized tests covering every ordered pair of distinct widths.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(types/uint): require exact-same-concrete-type on all binary ops
Every BaseUint binary operator now uses type(other) is type(self) instead
of isinstance(other, BaseUint). Previously, Uint8(5) + Uint16(10) silently
produced Uint8(15) because the result type defaulted to the LHS. Now any
cross-width or cross-newtype mixing raises TypeError, matching how a
strongly typed language rejects u8 + u16 or Slot + Uint64.
Also in this commit:
- __rpow__ gains the missing mod parameter for 3-arg pow.
- __pow__ uses overloads to express the parent's two-overload return shape.
- Dead _validate_int_operand helper removed (no callers remain).
- Class docstring documents the universal strict-type rule.
Consumers throughout the chain/clock, fork-choice, validator service, and
xmss code that were silently relying on cross-type interop are updated to
convert explicitly via int() or the appropriate newtype constructor.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(types/uint): tighten docstrings and comments per /doc rules
Strip backticks, drop restated-code prose, collapse multi-line docstrings to
single-sentence summaries where the signature already documents the rest, and
fix two factually wrong Raises sections that cited non-existent error types.
Add brief Why comments to the Pydantic schema body where the plumbing is
non-obvious.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(types/uint): full-message error matching and 100% coverage
Every pytest.raises now anchors on the exact exception message via
re.escape, replacing partial or wildcard matches that could silently
accept the wrong error.
Add tests for the previously-untested three-argument reverse pow paths
(both the success path and the modulo type-rejection branch), lifting
uint.py coverage to 100%.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(chain/clock): trim redundant strict-typing comment in from_slot
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(testing/store_checks): type StoreChecks.time as Interval
Store.time is an Interval; the StoreChecks comparison field was still
typed as Uint64, which under the strict-typing rule causes Interval !=
Uint64 to raise TypeError during fixture validation. Update the field
to Interval and the two test call sites that constructed Uint64 values.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 3c61690 commit 3b45c3d
24 files changed
Lines changed: 454 additions & 353 deletions
File tree
- packages/testing/src/consensus_testing
- test_fixtures
- test_types
- src/lean_spec
- forks/lstar
- subspecs
- chain
- validator
- xmss
- types
- tests
- consensus/lstar/fc
- lean_spec
- forks/lstar/forkchoice
- subspecs
- chain
- genesis
- networking
- enr
- node
- types
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
126 | | - | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1092 | 1092 | | |
1093 | 1093 | | |
1094 | 1094 | | |
1095 | | - | |
| 1095 | + | |
| 1096 | + | |
1096 | 1097 | | |
1097 | 1098 | | |
1098 | 1099 | | |
| |||
1761 | 1762 | | |
1762 | 1763 | | |
1763 | 1764 | | |
1764 | | - | |
| 1765 | + | |
1765 | 1766 | | |
1766 | 1767 | | |
1767 | 1768 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| |||
167 | 166 | | |
168 | 167 | | |
169 | 168 | | |
| 169 | + | |
170 | 170 | | |
171 | | - | |
172 | | - | |
| 171 | + | |
| 172 | + | |
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
| 207 | + | |
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
333 | | - | |
| 333 | + | |
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
388 | | - | |
| 388 | + | |
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
| |||
0 commit comments