Fix replace_empty_or_append, remove assert False & test

This commit is contained in:
Dankrad Feist 2020-06-12 11:53:00 +01:00
parent 7bf491d49d
commit 65c3417f90
No known key found for this signature in database
GPG Key ID: 6815E6A20BEBBABA
2 changed files with 29 additions and 7 deletions

View File

@ -193,14 +193,13 @@ class EarlyDerivedSecretReveal(Container):
### `replace_empty_or_append` ### `replace_empty_or_append`
```python ```python
def replace_empty_or_append(list: List, new_element: Any) -> int: def replace_empty_or_append(l: List, new_element: Any) -> int:
for i in range(len(list)): for i in range(len(l)):
if list[i] == type(new_element)(): if l[i] == type(new_element)():
assert False l[i] = new_element
list[i] = new_element
return i return i
list.append(new_element) l.append(new_element)
return len(list) - 1 return len(l) - 1
``` ```
### `legendre_bit` ### `legendre_bit`

View File

@ -85,6 +85,29 @@ def test_challenge_appended(spec, state):
yield from run_chunk_challenge_processing(spec, state, challenge) 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']) @with_all_phases_except(['phase0'])
@spec_state_test @spec_state_test
def test_duplicate_challenge(spec, state): def test_duplicate_challenge(spec, state):