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 cf757b583..4fb8adbaf 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, valid=False) + status=PayloadStatusV1Status.SYNCING) assert spec.get_head(mega_store.fc_store) == mega_store.opt_store.head_block_root # Now add block 4 to chain `b` with INVALID @@ -93,7 +93,7 @@ def test_from_syncing_to_invalid(spec, state): validation_error="invalid", ) yield from add_optimistic_block(spec, mega_store, signed_block, test_steps, - payload_status=payload_status, valid=False) + payload_status=payload_status) 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/optimistic_sync.py b/tests/core/pyspec/eth2spec/test/helpers/optimistic_sync.py index a89c3083e..6f42aa9ba 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/optimistic_sync.py +++ b/tests/core/pyspec/eth2spec/test/helpers/optimistic_sync.py @@ -75,9 +75,18 @@ def get_optimistic_store(spec, anchor_state, anchor_block): return opt_store +def get_valid_flag_value(status: PayloadStatusV1Status) -> bool: + if status == PayloadStatusV1Status.VALID: + return True + elif status.alias == PayloadStatusV1StatusAlias.NOT_VALIDATED: + return True + else: + # status.alias == PayloadStatusV1StatusAlias.INVALIDATED or other cases + return False + + def add_optimistic_block(spec, mega_store, signed_block, test_steps, - payload_status=None, status=PayloadStatusV1Status.SYNCING, - valid=True): + payload_status=None, status=PayloadStatusV1Status.SYNCING): """ Add a block with optimistic sync logic @@ -99,6 +108,9 @@ def add_optimistic_block(spec, mega_store, signed_block, test_steps, 'payload_status': payload_status.formatted_output, }) + # Set `valid` flag + valid = get_valid_flag_value(payload_status.status) + # Optimistic sync # Case: INVALID