diff --git a/specs/phase1/custody-game.md b/specs/phase1/custody-game.md index d4ce4640a..8185b6baa 100644 --- a/specs/phase1/custody-game.md +++ b/specs/phase1/custody-game.md @@ -193,14 +193,13 @@ class EarlyDerivedSecretReveal(Container): ### `replace_empty_or_append` ```python -def replace_empty_or_append(list: List, new_element: Any) -> int: - for i in range(len(list)): - if list[i] == type(new_element)(): - assert False - list[i] = new_element +def replace_empty_or_append(l: List, new_element: Any) -> int: + for i in range(len(l)): + if l[i] == type(new_element)(): + l[i] = new_element return i - list.append(new_element) - return len(list) - 1 + l.append(new_element) + return len(l) - 1 ``` ### `legendre_bit` diff --git a/tests/core/pyspec/eth2spec/test/phase_1/block_processing/test_process_chunk_challenge.py b/tests/core/pyspec/eth2spec/test/phase_1/block_processing/test_process_chunk_challenge.py index 97fe0c222..94b1c3b11 100644 --- a/tests/core/pyspec/eth2spec/test/phase_1/block_processing/test_process_chunk_challenge.py +++ b/tests/core/pyspec/eth2spec/test/phase_1/block_processing/test_process_chunk_challenge.py @@ -85,6 +85,29 @@ def test_challenge_appended(spec, state): yield from run_chunk_challenge_processing(spec, state, challenge) +@with_all_phases_except(['phase0']) +@spec_state_test +def test_challenge_empty_element_replaced(spec, state): + transition_to(spec, state, state.slot + 1) + shard = 0 + offset_slots = spec.get_offset_slots(state, shard) + shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots)) + attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, + shard_transition=shard_transition) + + transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY) + + _, _, _ = run_attestation_processing(spec, state, attestation) + + transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * spec.EPOCHS_PER_CUSTODY_PERIOD) + + challenge = get_valid_chunk_challenge(spec, state, attestation, shard_transition) + + state.custody_chunk_challenge_records.append(spec.CustodyChunkChallengeRecord()) + + yield from run_chunk_challenge_processing(spec, state, challenge) + + @with_all_phases_except(['phase0']) @spec_state_test def test_duplicate_challenge(spec, state):