Emit checks after each individual test step

Co-authored-by: Hsiao-Wei Wang <hsiaowei.eth@gmail.com>
This commit is contained in:
Etan Kissling 2022-07-15 13:13:33 +02:00
parent 73279f8382
commit 3c5d347cdc
No known key found for this signature in database
GPG Key ID: B21DA824C5A3D03D
2 changed files with 43 additions and 19 deletions

View File

@ -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

View File

@ -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: {<store_attibute>: 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: {<store_attibute>: 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`.