Apply HWW code's review - properly update test steps

This commit is contained in:
Aditya Asgaonkar 2021-11-23 07:20:54 -08:00
parent a0b5a809d5
commit ecbe9190b9
2 changed files with 23 additions and 16 deletions

View File

@ -304,21 +304,23 @@ def test_proposer_boost_correct_head(spec, state):
assert spec.hash_tree_root(block_1) < spec.hash_tree_root(block_2)
# Tick to block_1 slot time
spec.on_tick(store, store.genesis_time + block_1.slot * spec.config.SECONDS_PER_SLOT)
time = store.genesis_time + block_1.slot * spec.config.SECONDS_PER_SLOT
on_tick_and_append_step(spec, store, time, test_steps)
# Process block_2
yield from tick_and_add_block(spec, store, signed_block_2, test_steps)
yield from add_block(spec, store, signed_block_2, test_steps)
assert store.proposer_boost_root == spec.Root()
assert spec.get_head(store) == spec.hash_tree_root(block_2)
# Process block_1 on timely arrival
# The head should temporarily change to block_1
yield from tick_and_add_block(spec, store, signed_block_1, test_steps)
yield from add_block(spec, store, signed_block_1, test_steps)
assert store.proposer_boost_root == spec.hash_tree_root(block_1)
assert spec.get_head(store) == spec.hash_tree_root(block_1)
# After block_1.slot, the head should revert to block_2
spec.on_tick(store, store.genesis_time + (block_1.slot + 1) * spec.config.SECONDS_PER_SLOT)
time = store.genesis_time + (block_1.slot + 1) * spec.config.SECONDS_PER_SLOT
on_tick_and_append_step(spec, store, time, test_steps)
assert store.proposer_boost_root == spec.Root()
assert spec.get_head(store) == spec.hash_tree_root(block_2)

View File

@ -723,15 +723,17 @@ def test_proposer_boost(spec, state):
signed_block = state_transition_and_sign_block(spec, state, block)
# Process block on timely arrival just before end of boost interval
spec.on_tick(store, store.genesis_time + block.slot * spec.config.SECONDS_PER_SLOT +
spec.config.SECONDS_PER_SLOT // spec.INTERVALS_PER_SLOT - 1)
yield from tick_and_add_block(spec, store, signed_block, test_steps)
time = (store.genesis_time + block.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, test_steps)
assert store.proposer_boost_root == spec.hash_tree_root(block)
assert spec.get_latest_attesting_balance(store, spec.hash_tree_root(block)) > 0
# Ensure that boost is removed after slot is over
spec.on_tick(store, store.genesis_time + block.slot * spec.config.SECONDS_PER_SLOT +
spec.config.SECONDS_PER_SLOT)
time = (store.genesis_time + block.slot * spec.config.SECONDS_PER_SLOT +
spec.config.SECONDS_PER_SLOT)
on_tick_and_append_step(spec, store, time, test_steps)
assert store.proposer_boost_root == spec.Root()
assert spec.get_latest_attesting_balance(store, spec.hash_tree_root(block)) == 0
@ -740,14 +742,16 @@ def test_proposer_boost(spec, state):
signed_block = state_transition_and_sign_block(spec, state, block)
# Process block on timely arrival at start of boost interval
spec.on_tick(store, store.genesis_time + block.slot * spec.config.SECONDS_PER_SLOT)
yield from tick_and_add_block(spec, store, signed_block, test_steps)
time = (store.genesis_time + block.slot * spec.config.SECONDS_PER_SLOT)
on_tick_and_append_step(spec, store, time, test_steps)
yield from add_block(spec, store, signed_block, test_steps)
assert store.proposer_boost_root == spec.hash_tree_root(block)
assert spec.get_latest_attesting_balance(store, spec.hash_tree_root(block)) > 0
# Ensure that boost is removed after slot is over
spec.on_tick(store, store.genesis_time + block.slot * spec.config.SECONDS_PER_SLOT +
spec.config.SECONDS_PER_SLOT)
time = (store.genesis_time + block.slot * spec.config.SECONDS_PER_SLOT +
spec.config.SECONDS_PER_SLOT)
on_tick_and_append_step(spec, store, time, test_steps)
assert store.proposer_boost_root == spec.Root()
assert spec.get_latest_attesting_balance(store, spec.hash_tree_root(block)) == 0
@ -772,9 +776,10 @@ def test_proposer_boost_root_same_slot_untimely_block(spec, state):
signed_block = state_transition_and_sign_block(spec, state, block)
# Process block on untimely arrival in the same slot
spec.on_tick(store, store.genesis_time + block.slot * spec.config.SECONDS_PER_SLOT +
spec.config.SECONDS_PER_SLOT // spec.INTERVALS_PER_SLOT)
yield from tick_and_add_block(spec, store, signed_block, test_steps)
time = (store.genesis_time + block.slot * spec.config.SECONDS_PER_SLOT +
spec.config.SECONDS_PER_SLOT // spec.INTERVALS_PER_SLOT)
on_tick_and_append_step(spec, store, time, test_steps)
yield from add_block(spec, store, signed_block, test_steps)
assert store.proposer_boost_root == spec.Root()
yield 'steps', test_steps