diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/sync/test_optimistic.py b/tests/core/pyspec/eth2spec/test/bellatrix/sync/test_optimistic.py index 899c6b5ab..cf757b583 100644 --- a/tests/core/pyspec/eth2spec/test/bellatrix/sync/test_optimistic.py +++ b/tests/core/pyspec/eth2spec/test/bellatrix/sync/test_optimistic.py @@ -79,7 +79,7 @@ def test_from_syncing_to_invalid(spec, state): signed_block = state_transition_with_full_block(spec, state, True, True, block=block) signed_blocks_b.append(signed_block.copy()) yield from add_optimistic_block(spec, mega_store, signed_block, test_steps, - status=PayloadStatusV1Status.SYNCING) + status=PayloadStatusV1Status.SYNCING, valid=False) assert spec.get_head(mega_store.fc_store) == mega_store.opt_store.head_block_root # Now add block 4 to chain `b` with INVALID @@ -92,7 +92,8 @@ def test_from_syncing_to_invalid(spec, state): latest_valid_hash=block_0.body.execution_payload.block_hash, validation_error="invalid", ) - yield from add_optimistic_block(spec, mega_store, signed_block, test_steps, payload_status=payload_status) + yield from add_optimistic_block(spec, mega_store, signed_block, test_steps, + payload_status=payload_status, valid=False) assert mega_store.opt_store.head_block_root == signed_blocks_a[-1].message.hash_tree_root() yield 'steps', test_steps diff --git a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py index a1d2e6ffc..bd8abd95b 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py +++ b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py @@ -137,9 +137,9 @@ def add_block(spec, return else: assert False - - run_on_block(spec, store, signed_block, valid=True) - test_steps.append({'block': get_block_file_name(signed_block)}) + else: + run_on_block(spec, store, signed_block, valid=True) + test_steps.append({'block': get_block_file_name(signed_block)}) # An on_block step implies receiving block's attestations for attestation in signed_block.message.body.attestations: diff --git a/tests/core/pyspec/eth2spec/test/helpers/optimistic_sync.py b/tests/core/pyspec/eth2spec/test/helpers/optimistic_sync.py index 3fc31e5b0..d88513a8a 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/optimistic_sync.py +++ b/tests/core/pyspec/eth2spec/test/helpers/optimistic_sync.py @@ -76,7 +76,14 @@ def get_optimistic_store(spec, anchor_state, anchor_block): def add_optimistic_block(spec, mega_store, signed_block, test_steps, - payload_status=None, status=PayloadStatusV1Status.SYNCING): + payload_status=None, status=PayloadStatusV1Status.SYNCING, + valid=True): + """ + Add a block with optimistic sync logic + + ``valid`` indicates if the given ``signed_block.message.body.execution_payload`` is valid/invalid + from ``notify_new_payload`` method response. + """ block = signed_block.message block_root = block.hash_tree_root() el_block_hash = block.body.execution_payload.block_hash @@ -93,8 +100,6 @@ def add_optimistic_block(spec, mega_store, signed_block, test_steps, # Optimistic sync - valid = True - # Case: INVALID if payload_status.status == PayloadStatusV1Status.INVALID: # Update parent status to INVALID @@ -108,9 +113,6 @@ def add_optimistic_block(spec, mega_store, signed_block, test_steps, current_block = mega_store.fc_store.blocks[current_block.parent_root] el_block_hash = current_block.body.execution_payload.block_hash - if payload_status.status != PayloadStatusV1Status.VALID: - valid = False - yield from add_block(spec, mega_store.fc_store, signed_block, valid=valid, test_steps=test_steps,