diff --git a/specs/test_formats/genesis/README.md b/specs/test_formats/genesis/README.md new file mode 100644 index 000000000..25761e2f6 --- /dev/null +++ b/specs/test_formats/genesis/README.md @@ -0,0 +1,8 @@ +# Genesis tests + +The aim of the genesis tests is to provide a baseline to test genesis-state initialization and test + if the proposed genesis-validity conditions are working. + +There are two handlers, documented individually: +- [`validity`](./validity.md): Tests if a genesis state is valid, i.e. if it counts as trigger to launch. +- [`initialization`](./initialization.md): Tests the initialization of a genesis state based on Eth1 data. diff --git a/specs/test_formats/genesis/initialization.md b/specs/test_formats/genesis/initialization.md new file mode 100644 index 000000000..437dd91a3 --- /dev/null +++ b/specs/test_formats/genesis/initialization.md @@ -0,0 +1,22 @@ +# Genesis creation testing + +Tests the initialization of a genesis state based on Eth1 data. + +## Test case format + +```yaml +description: string -- description of test case, purely for debugging purposes +bls_setting: int -- see general test-format spec. +eth1_block_hash: Bytes32 -- the root of the Eth-1 block, hex encoded, with prefix 0x +eth1_timestamp: int -- the timestamp of the block, in seconds. +deposits: [Deposit] -- list of deposits to build the genesis state with +state: BeaconState -- the expected genesis state. +``` + +To process this test, build a genesis state with the provided `eth1_block_hash`, `eth1_timestamp` and `deposits`: +`initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits)`, + as described in the Beacon Chain specification. + +## Condition + +The resulting state should match the expected `state`. diff --git a/specs/test_formats/genesis/validity.md b/specs/test_formats/genesis/validity.md new file mode 100644 index 000000000..792923e3a --- /dev/null +++ b/specs/test_formats/genesis/validity.md @@ -0,0 +1,19 @@ +# Genesis validity testing + +Tests if a genesis state is valid, i.e. if it counts as trigger to launch. + +## Test case format + +```yaml +description: string -- description of test case, purely for debugging purposes +bls_setting: int -- see general test-format spec. +genesis: BeaconState -- state to validate. +is_valid: bool -- true if the genesis state is deemed valid as to launch with, false otherwise. +``` + +To process the data, call `is_valid_genesis_state(genesis)`. + + +## Condition + +The result of calling `is_valid_genesis_state(genesis)` should match the expected `is_valid` boolean. diff --git a/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py b/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py index 4ad509200..2dc9eb7fd 100644 --- a/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py +++ b/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py @@ -16,13 +16,13 @@ def create_valid_beacon_state(spec): def run_is_valid_genesis_state(spec, state, valid=True): """ Run ``is_valid_genesis_state``, yielding: - - state ('state') + - genesis ('state') - is_valid ('is_valid') - If ``valid == False``, run expecting ``AssertionError`` """ - yield state + yield 'genesis', state is_valid = spec.is_valid_genesis_state(state) yield 'is_valid', is_valid + assert is_valid == valid @with_phases(['phase0'])