Skip to content

Commit e293f69

Browse files
committed
Fix test_demo.py
1. Fix serenity validation type hinting 2. Fix test_demo.py arguments 3. Add more testcase for `test_get_shard_committees_at_slot` 4. Add more output message for `get_shard_committees_at_slot` and `get_block_root`
1 parent 82905a4 commit e293f69

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

eth/beacon/helpers.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,14 @@ def _get_block_root(
7676
if state_slot > slot + latest_block_roots_length:
7777
raise ValueError(
7878
"state.slot (%s) should be less than or equal to "
79-
"(slot + latest_block_roots_length) (%s)" %
80-
(state_slot, slot + latest_block_roots_length)
79+
"(slot + latest_block_roots_length) (%s), "
80+
"where slot=%s, latest_block_roots_length=%s" %
81+
(
82+
state_slot,
83+
slot + latest_block_roots_length,
84+
slot,
85+
latest_block_roots_length,
86+
)
8187
)
8288
if slot >= state_slot:
8389
raise ValueError(
@@ -121,8 +127,15 @@ def _get_shard_committees_at_slot(
121127
)
122128
if slot >= earliest_slot_in_array + epoch_length * 2:
123129
raise ValueError(
124-
"slot (%s) should be less than earliest_slot_in_array + epoch_length * 2 (%s)" %
125-
(slot, earliest_slot_in_array + epoch_length * 2)
130+
"slot (%s) should be less than "
131+
"(earliest_slot_in_array + epoch_length * 2) (%s), "
132+
"where earliest_slot_in_array=%s, epoch_length=%s" %
133+
(
134+
slot,
135+
earliest_slot_in_array + epoch_length * 2,
136+
earliest_slot_in_array,
137+
epoch_length,
138+
)
126139
)
127140

128141
return shard_committees_at_slots[slot - earliest_slot_in_array]

eth/beacon/state_machines/forks/serenity/validation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
ValidationError,
66
)
77
import rlp
8-
from typing import Type
98

109
from eth.constants import (
1110
ZERO_HASH32,
@@ -69,7 +68,7 @@ def validate_serenity_proposer_signature(state: BeaconState,
6968
#
7069
# Attestation validation
7170
#
72-
def validate_serenity_attestation(state: Type[BeaconState],
71+
def validate_serenity_attestation(state: BeaconState,
7372
attestation: Attestation,
7473
epoch_length: int,
7574
min_attestation_inclusion_delay: int,
@@ -238,7 +237,7 @@ def validate_serenity_attestation_shard_block_root(attestation_data: Attestation
238237
)
239238

240239

241-
def validate_serenity_attestation_aggregate_signature(state: Type[BeaconState],
240+
def validate_serenity_attestation_aggregate_signature(state: BeaconState,
242241
attestation: Attestation,
243242
epoch_length: int) -> None:
244243
"""

tests/beacon/state_machines/test_demo.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
'shard_count'
2727
),
2828
[
29-
(10, 2, 1, 2, 2)
29+
(10, 10, 1, 2, 2)
3030
]
3131
)
3232
def test_demo(base_db,
@@ -45,10 +45,7 @@ def test_demo(base_db,
4545

4646
# Sign block
4747
beacon_proposer_index = get_beacon_proposer_index(
48-
# TODO: use `state` when the bug of `get_shard_committees_at_slot` is fixed.
49-
state.copy(
50-
slot=state.slot + 2,
51-
),
48+
state,
5249
block.slot,
5350
config.EPOCH_LENGTH,
5451
)

tests/beacon/test_helpers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ def test_get_block_root(current_slot,
183183
64,
184184
True,
185185
),
186+
(
187+
100,
188+
64,
189+
1,
190+
128,
191+
10,
192+
1,
193+
True,
194+
),
186195
# slot is too small
187196
(
188197
100,

0 commit comments

Comments
 (0)