Update test format. Add `get_proposer_head`

This commit is contained in:
Michael Sproul 2023-10-26 17:44:48 +11:00 committed by Hsiao-Wei Wang
parent 3f1bc20512
commit 9ce8e3d6e9
No known key found for this signature in database
GPG Key ID: AE3D6B174F971DE4
4 changed files with 26 additions and 5 deletions

View File

@ -1,3 +1,4 @@
from eth_utils import encode_hex
from eth2spec.test.context import (
spec_state_test,
with_altair_and_later,
@ -13,6 +14,7 @@ from eth2spec.test.helpers.fork_choice import (
apply_next_slots_with_attestations,
get_genesis_forkchoice_store_and_block,
on_tick_and_append_step,
output_store_checks,
tick_and_add_block,
tick_and_run_on_attestation,
)
@ -51,9 +53,15 @@ def test_basic_is_head_root(spec, state):
current_time = slot * spec.config.SECONDS_PER_SLOT + store.genesis_time
on_tick_and_append_step(spec, store, current_time, test_steps)
proposer_head = spec.get_proposer_head(store, head_root, slot)
assert proposer_head == head_root
output_store_checks(spec, store, test_steps)
test_steps.append({
'checks': {
'get_proposer_head': encode_hex(proposer_head),
}
})
yield 'steps', test_steps
@ -149,6 +157,11 @@ def test_basic_is_parent_root(spec, state):
proposer_head = spec.get_proposer_head(store, head_root, state.slot)
assert proposer_head == parent_root
# TODO: export the `proposer_head` result to test vectors?
output_store_checks(spec, store, test_steps)
test_steps.append({
'checks': {
'get_proposer_head': encode_hex(proposer_head),
}
})
yield 'steps', test_steps

View File

@ -159,7 +159,7 @@ The checks to verify the current status of `store`.
checks: {<store_attibute>: value} -- the assertions.
```
`<store_attibute>` is the field member or property of [`Store`](../../../specs/phase0/fork-choice.md#store) object that maintained by client implementation. Currently, the possible fields included:
`<store_attibute>` is the field member or property of [`Store`](../../../specs/phase0/fork-choice.md#store) object that maintained by client implementation. The fields include:
```yaml
head: {
@ -177,7 +177,13 @@ finalized_checkpoint: {
root: string, -- Encoded 32-byte value from store.finalized_checkpoint.root
}
proposer_boost_root: string -- Encoded 32-byte value from store.proposer_boost_root
should_override_forkchoice_update: bool -- [New in Bellatrix] the result of `should_override_forkchoice_update(store, head_root)`
```
Additionally, these fields if `get_proposer_head` and `should_override_forkchoice_update` features are implemented:
```yaml
get_proposer_head: string -- Encoded 32-byte value from get_proposer_head(store)
should_override_forkchoice_update: bool -- [New in Bellatrix] the result of `should_override_forkchoice_update(store, head_root)`, where head_root is the result value from get_head(store)
```
For example:
@ -188,6 +194,8 @@ For example:
justified_checkpoint: {epoch: 3, root: '0xc25faab4acab38d3560864ca01e4d5cc4dc2cd473da053fbc03c2669143a2de4'}
finalized_checkpoint: {epoch: 2, root: '0x40d32d6283ec11c53317a46808bc88f55657d93b95a1af920403187accf48f4f'}
proposer_boost_root: '0xdaa1d49d57594ced0c35688a6da133abb086d191a2ebdfd736fad95299325aeb'
get_proposer_head: '0xdaa1d49d57594ced0c35688a6da133abb086d191a2ebdfd736fad95299325aeb'
should_override_forkchoice_update: false
```
*Note*: Each `checks` step may include one or multiple items. Each item has to be checked against the current store.

View File

@ -17,7 +17,7 @@ if __name__ == "__main__":
# PowBlock's which should be resolved by `get_pow_block(hash: Hash32) -> PowBlock` function
_new_bellatrix_mods = {key: 'eth2spec.test.bellatrix.fork_choice.test_' + key for key in [
'on_merge_block',
'reorg',
'should_override_forkchoice_update',
]}
bellatrix_mods = combine_mods(_new_bellatrix_mods, altair_mods)
capella_mods = bellatrix_mods # No additional Capella specific fork choice tests