Allow extending LC merkle proof tests

Currently, `test_single_merkle_proof` only supports `BeaconState` tests.
For future tests, different object classes are desirable. Update format
to allow testing other objects as well.
This commit is contained in:
Etan Kissling 2022-10-27 21:59:17 +02:00
parent aac851f860
commit cdaf7e84dd
No known key found for this signature in database
GPG Key ID: B21DA824C5A3D03D
2 changed files with 24 additions and 12 deletions

View File

@ -7,8 +7,10 @@ from eth2spec.test.context import (
@with_altair_and_later @with_altair_and_later
@spec_state_test @spec_state_test
def test_current_sync_committee_merkle_proof(spec, state): def test_current_sync_committee_merkle_proof(spec, state):
yield "state", state yield "object_class", "meta", "BeaconState"
current_sync_committee_branch = spec.compute_merkle_proof_for_state(state, spec.CURRENT_SYNC_COMMITTEE_INDEX) yield "object", state
current_sync_committee_branch = \
spec.compute_merkle_proof_for_state(state, spec.CURRENT_SYNC_COMMITTEE_INDEX)
yield "proof", { yield "proof", {
"leaf": "0x" + state.current_sync_committee.hash_tree_root().hex(), "leaf": "0x" + state.current_sync_committee.hash_tree_root().hex(),
"leaf_index": spec.CURRENT_SYNC_COMMITTEE_INDEX, "leaf_index": spec.CURRENT_SYNC_COMMITTEE_INDEX,
@ -26,8 +28,10 @@ def test_current_sync_committee_merkle_proof(spec, state):
@with_altair_and_later @with_altair_and_later
@spec_state_test @spec_state_test
def test_next_sync_committee_merkle_proof(spec, state): def test_next_sync_committee_merkle_proof(spec, state):
yield "state", state yield "object_class", "meta", "BeaconState"
next_sync_committee_branch = spec.compute_merkle_proof_for_state(state, spec.NEXT_SYNC_COMMITTEE_INDEX) yield "object", state
next_sync_committee_branch = \
spec.compute_merkle_proof_for_state(state, spec.NEXT_SYNC_COMMITTEE_INDEX)
yield "proof", { yield "proof", {
"leaf": "0x" + state.next_sync_committee.hash_tree_root().hex(), "leaf": "0x" + state.next_sync_committee.hash_tree_root().hex(),
"leaf_index": spec.NEXT_SYNC_COMMITTEE_INDEX, "leaf_index": spec.NEXT_SYNC_COMMITTEE_INDEX,
@ -45,8 +49,10 @@ def test_next_sync_committee_merkle_proof(spec, state):
@with_altair_and_later @with_altair_and_later
@spec_state_test @spec_state_test
def test_finality_root_merkle_proof(spec, state): def test_finality_root_merkle_proof(spec, state):
yield "state", state yield "object_class", "meta", "BeaconState"
finality_branch = spec.compute_merkle_proof_for_state(state, spec.FINALIZED_ROOT_INDEX) yield "object", state
finality_branch = \
spec.compute_merkle_proof_for_state(state, spec.FINALIZED_ROOT_INDEX)
yield "proof", { yield "proof", {
"leaf": "0x" + state.finalized_checkpoint.root.hex(), "leaf": "0x" + state.finalized_checkpoint.root.hex(),
"leaf_index": spec.FINALIZED_ROOT_INDEX, "leaf_index": spec.FINALIZED_ROOT_INDEX,

View File

@ -5,13 +5,19 @@ generation and verification of merkle proofs based on static data.
## Test case format ## Test case format
### `state.ssz_snappy` ### `meta.yaml`
An SSZ-snappy encoded `BeaconState` object from which other data is generated. ```yaml
object_class: string -- 'BeaconState'
```
### `object.yaml`
A SSZ-snappy encoded object of type `object_class` from which other data is generated.
### `proof.yaml` ### `proof.yaml`
A proof of the leaf value (a merkle root) at generalized-index `leaf_index` in the given `state`. A proof of the leaf value (a merkle root) at generalized-index `leaf_index` in the given `object`.
```yaml ```yaml
leaf: Bytes32 # string, hex encoded, with 0x prefix leaf: Bytes32 # string, hex encoded, with 0x prefix
@ -23,6 +29,6 @@ branch: list of Bytes32 # list, each element is a string, hex encoded, with 0x
A test-runner can implement the following assertions: A test-runner can implement the following assertions:
- Check that `is_valid_merkle_branch` confirms `leaf` at `leaf_index` to verify - Check that `is_valid_merkle_branch` confirms `leaf` at `leaf_index` to verify
against `has_tree_root(state)` and `proof`. against `hash_tree_root(object)` and `branch`.
- If the implementation supports generating merkle proofs, check that the - If the implementation supports generating merkle proofs, check that the
self-generated proof matches the `proof` provided with the test. self-generated proof matches the `branch` provided with the test.