Add test_proposer_boost_is_first_block test case

This commit is contained in:
Hsiao-Wei Wang 2023-08-04 21:41:57 +08:00
parent 63c39dbaff
commit 1904b47e3e
No known key found for this signature in database
GPG Key ID: AE3D6B174F971DE4

View File

@ -539,6 +539,56 @@ def test_proposer_boost_root_same_slot_untimely_block(spec, state):
yield 'steps', test_steps
@with_altair_and_later
@spec_state_test
def test_proposer_boost_is_first_block(spec, state):
test_steps = []
genesis_state = state.copy()
# Initialization
store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state)
yield 'anchor_state', state
yield 'anchor_block', anchor_block
# Build block that serves as head ONLY on timely arrival, and ONLY in that slot
state = genesis_state.copy()
next_slots(spec, state, 3)
pre_state = state.copy()
block_a = build_empty_block_for_next_slot(spec, state)
signed_block_a = state_transition_and_sign_block(spec, state, block_a)
# Process block on timely arrival just before end of boost interval
time = (store.genesis_time + block_a.slot * spec.config.SECONDS_PER_SLOT +
spec.config.SECONDS_PER_SLOT // spec.INTERVALS_PER_SLOT - 1)
on_tick_and_append_step(spec, store, time, test_steps)
yield from add_block(spec, store, signed_block_a, test_steps)
# `proposer_boost_root` is now `block_a`
assert store.proposer_boost_root == spec.hash_tree_root(block_a)
assert spec.get_weight(store, spec.hash_tree_root(block_a)) > 0
test_steps.append({
'checks': {
'proposer_boost_root': encode_hex(store.proposer_boost_root),
}
})
# make a different block at the same slot
state = pre_state.copy()
block_b = block_a.copy()
block_b.body.graffiti = b'\x34' * 32
signed_block_b = state_transition_and_sign_block(spec, state, block_b)
yield from add_block(spec, store, signed_block_b, test_steps)
# `proposer_boost_root` is still `block_a`
assert store.proposer_boost_root == spec.hash_tree_root(block_a)
assert spec.get_weight(store, spec.hash_tree_root(block_b)) == 0
test_steps.append({
'checks': {
'proposer_boost_root': encode_hex(store.proposer_boost_root),
}
})
yield 'steps', test_steps
@with_altair_and_later
@spec_state_test
@with_presets([MINIMAL], reason="too slow")