From 3c5d347cdc66e3cb40f248ce1dfe4def4b7c6ad8 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Fri, 15 Jul 2022 13:13:33 +0200 Subject: [PATCH] Emit checks after each individual test step Co-authored-by: Hsiao-Wei Wang --- .../sync_protocol/test_light_client_sync.py | 25 ++++++++++--- .../sync_protocol/light_client_sync.md | 37 ++++++++++++------- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/sync_protocol/test_light_client_sync.py b/tests/core/pyspec/eth2spec/test/altair/sync_protocol/test_light_client_sync.py index 0df77cda4..d2eed0627 100644 --- a/tests/core/pyspec/eth2spec/test/altair/sync_protocol/test_light_client_sync.py +++ b/tests/core/pyspec/eth2spec/test/altair/sync_protocol/test_light_client_sync.py @@ -45,8 +45,6 @@ def setup_test(spec, state): def finish_test(test): yield "steps", test.steps - yield "expected_finalized_header", test.store.finalized_header - yield "expected_optimistic_header", test.store.optimistic_header def get_update_file_name(spec, update): @@ -61,15 +59,30 @@ def get_update_file_name(spec, update): return f"update_{encode_hex(update.attested_header.hash_tree_root())}_{suffix1}{suffix2}" +def get_checks(store): + return { + "finalized_header": { + 'slot': int(store.finalized_header.slot), + 'root': encode_hex(store.finalized_header.hash_tree_root()), + }, + "optimistic_header": { + 'slot': int(store.optimistic_header.slot), + 'root': encode_hex(store.optimistic_header.hash_tree_root()), + }, + } + + def emit_slot(test, spec, state): current_slot = state.slot - yield from [] + spec.process_slot_for_light_client_store(test.store, current_slot) + + yield from [] # Consistently enable `yield from` syntax in calling tests test.steps.append({ "process_slot": { "current_slot": int(current_slot), + "checks": get_checks(test.store), } }) - spec.process_slot_for_light_client_store(test.store, current_slot) def emit_update(test, spec, state, block, attested_state, finalized_block, with_next_sync_committee=True): @@ -79,14 +92,16 @@ def emit_update(test, spec, state, block, attested_state, finalized_block, with_ update.next_sync_committee_branch = \ [spec.Bytes32() for _ in range(spec.floorlog2(spec.NEXT_SYNC_COMMITTEE_INDEX))] current_slot = state.slot + spec.process_light_client_update(test.store, update, current_slot, test.genesis_validators_root) + yield get_update_file_name(spec, update), update test.steps.append({ "process_update": { "update": get_update_file_name(spec, update), "current_slot": int(current_slot), + "checks": get_checks(test.store), } }) - spec.process_light_client_update(test.store, update, current_slot, test.genesis_validators_root) return update diff --git a/tests/formats/sync_protocol/light_client_sync.md b/tests/formats/sync_protocol/light_client_sync.md index 1d1506936..6940ced87 100644 --- a/tests/formats/sync_protocol/light_client_sync.md +++ b/tests/formats/sync_protocol/light_client_sync.md @@ -17,7 +17,22 @@ An SSZ-snappy encoded `bootstrap` object of type `LightClientBootstrap` to initi ### `steps.yaml` -The steps to execute in sequence. There may be multiple items of the following types: +The steps to execute in sequence. + +#### `checks` execution step + +Each step includes checks to verify the expected impact on the `store` object. + +```yaml +finalized_header: { + slot: int, -- Integer value from store.finalized_header.slot + root: string, -- Encoded 32-byte value from store.finalized_header.hash_tree_root() +} +optimistic_header: { + slot: int, -- Integer value from store.optimistic_header.slot + root: string, -- Encoded 32-byte value from store.optimistic_header.hash_tree_root() +} +``` #### `process_slot` execution step @@ -26,7 +41,8 @@ should be executed with the specified parameters: ```yaml { - current_slot: int -- integer, decimal + current_slot: int -- integer, decimal + checks: {: value} -- the assertions. } ``` @@ -38,22 +54,15 @@ The function `process_light_client_update(store, update, current_slot, genesis_v ```yaml { - update: string -- name of the `*.ssz_snappy` file to load - as a `LightClientUpdate` object - current_slot: int -- integer, decimal + update: string -- name of the `*.ssz_snappy` file to load + as a `LightClientUpdate` object + current_slot: int -- integer, decimal + checks: {: value} -- the assertions. } ``` After this step, the `store` object may have been updated. -### `expected_finalized_header.ssz_snappy` - -An SSZ-snappy encoded `expected_finalized_header` object of type `BeaconBlockHeader` that represents the expected `store.finalized_header` after applying all the test steps. - -### `expected_optimistic_header.ssz_snappy` - -An SSZ-snappy encoded `expected_optimistic_header` object of type `BeaconBlockHeader` that represents the expected `store.finalized_header` after applying all the test steps. - ## Condition -A test-runner should initialize a local `LightClientStore` using the provided `bootstrap` object. It should then proceed to execute all the test steps in sequence. Finally, it should verify that the resulting `store` refers to the provided `expected_finalized_header` and `expected_optimistic_header`. +A test-runner should initialize a local `LightClientStore` using the provided `bootstrap` object. It should then proceed to execute all the test steps in sequence. After each step, it should verify that the resulting `store` verifies against the provided `checks`.