Skip to content

Commit 3f2e3b4

Browse files
committed
PR feedback
1 parent fdc6c14 commit 3f2e3b4

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

eth/beacon/helpers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,14 @@ def get_attestation_indices(crystallized_state: 'CrystallizedState',
214214
yield from shard_and_committee.committee
215215

216216

217-
@to_tuple
218217
def get_active_validator_indices(validators: Sequence['ValidatorRecord']) -> Iterable[int]:
219218
"""
220219
Gets indices of active validators from ``validators``.
221220
"""
222-
return [
221+
return tuple(
223222
i for i, v in enumerate(validators)
224223
if v.status in [ValidatorStatusCode.ACTIVE, ValidatorStatusCode.PENDING_EXIT]
225-
]
224+
)
226225

227226

228227
#

eth/beacon/utils/random.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,13 @@ def shuffle(values: Sequence[Any],
8585
return output
8686

8787

88-
@to_tuple
8988
def split(values: Sequence[TItem], split_count: int) -> Iterable[Any]:
9089
"""
9190
Returns the split ``values`` in ``split_count`` pieces in protocol.
9291
Spec: https://github.com/ethereum/eth2.0-specs/blob/70cef14a08de70e7bd0455d75cf380eb69694bfb/specs/core/0_beacon-chain.md#helper-functions # noqa: E501
9392
"""
9493
list_length = len(values)
95-
return [
94+
return tuple(
9695
values[(list_length * i // split_count): (list_length * (i + 1) // split_count)]
9796
for i in range(split_count)
98-
]
97+
)

tests/beacon/conftest.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import pytest
22

33
from eth_utils import denoms
4-
from eth_utils import (
5-
to_tuple,
6-
)
74

85
from eth.constants import (
96
ZERO_HASH32,
@@ -369,11 +366,10 @@ def initial_fork_version():
369366
# genesis
370367
#
371368
@pytest.fixture
372-
@to_tuple
373369
def genesis_validators(init_validator_keys,
374370
init_randao,
375371
deposit_size):
376-
return [
372+
return tuple(
377373
ValidatorRecord(
378374
pubkey=pub,
379375
withdrawal_credentials=ZERO_HASH32,
@@ -384,4 +380,4 @@ def genesis_validators(init_validator_keys,
384380
last_status_change_slot=0,
385381
exit_seq=0,
386382
) for pub in init_validator_keys
387-
]
383+
)
Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import pytest
2+
from hypothesis import (
3+
given,
4+
strategies as st,
5+
)
26

37
from eth.utils.numeric import (
48
integer_squareroot,
59
)
610

711

12+
@given(st.integers(min_value=0, max_value=100))
13+
def test_integer_squareroot_correct(value):
14+
result = integer_squareroot(value)
15+
assert (result + 1) ** 2 > value
16+
assert result ** 2 <= value
17+
18+
819
@pytest.mark.parametrize(
920
'value,expected',
1021
(
@@ -17,14 +28,20 @@
1728
(65535, 255),
1829
(65536, 256),
1930
(18446744073709551615, 4294967295),
20-
(1.5, ValueError()),
21-
(-1, ValueError()),
2231
)
2332
)
24-
def test_integer_squareroot(value, expected):
25-
if isinstance(expected, Exception):
26-
with pytest.raises(ValueError):
27-
integer_squareroot(value)
28-
else:
29-
actual = integer_squareroot(value)
30-
assert actual == expected
33+
def test_integer_squareroot_success(value, expected):
34+
actual = integer_squareroot(value)
35+
assert actual == expected
36+
37+
38+
@pytest.mark.parametrize(
39+
'value',
40+
(
41+
(1.5),
42+
(-1),
43+
)
44+
)
45+
def test_integer_squareroot_edge_cases(value):
46+
with pytest.raises(ValueError):
47+
integer_squareroot(value)

0 commit comments

Comments
 (0)