Add `get_valid_flag_value` helper to determine the `valid` flag value
This commit is contained in:
parent
0f8b5ae6bd
commit
2e73091258
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue