consolidate slot sanity checks across forks (#4418)

* consolidate slot sanity checks across forks

* use `new` rather than `init` for constructor of `ref`s
This commit is contained in:
tersec 2022-12-13 15:58:59 +00:00 committed by GitHub
parent bc996623e0
commit cd993ca418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 168 additions and 303 deletions

View File

@ -36,6 +36,11 @@ ConsensusSpecPreset-mainnet
+ EF - Altair - Rewards - with_not_yet_activated_validators_leak [Preset: mainnet] OK
+ EF - Altair - Rewards - with_slashed_validators [Preset: mainnet] OK
+ EF - Altair - Rewards - with_slashed_validators_leak [Preset: mainnet] OK
+ EF - Altair - Slots - double_empty_epoch [Preset: mainnet] OK
+ EF - Altair - Slots - empty_epoch [Preset: mainnet] OK
+ EF - Altair - Slots - over_epoch_boundary [Preset: mainnet] OK
+ EF - Altair - Slots - slots_1 [Preset: mainnet] OK
+ EF - Altair - Slots - slots_2 [Preset: mainnet] OK
+ EF - Altair - Transition - normal_transition [Preset: mainnet] OK
+ EF - Altair - Transition - simple_transition [Preset: mainnet] OK
+ EF - Altair - Transition - transition_missing_first_post_block [Preset: mainnet] OK
@ -91,6 +96,11 @@ ConsensusSpecPreset-mainnet
+ EF - Bellatrix - Rewards - with_not_yet_activated_validators_leak [Preset: mainnet] OK
+ EF - Bellatrix - Rewards - with_slashed_validators [Preset: mainnet] OK
+ EF - Bellatrix - Rewards - with_slashed_validators_leak [Preset: mainnet] OK
+ EF - Bellatrix - Slots - double_empty_epoch [Preset: mainnet] OK
+ EF - Bellatrix - Slots - empty_epoch [Preset: mainnet] OK
+ EF - Bellatrix - Slots - over_epoch_boundary [Preset: mainnet] OK
+ EF - Bellatrix - Slots - slots_1 [Preset: mainnet] OK
+ EF - Bellatrix - Slots - slots_2 [Preset: mainnet] OK
+ EF - Bellatrix - Transition - normal_transition [Preset: mainnet] OK
+ EF - Bellatrix - Transition - simple_transition [Preset: mainnet] OK
+ EF - Bellatrix - Transition - transition_missing_first_post_block [Preset: mainnet] OK
@ -146,6 +156,11 @@ ConsensusSpecPreset-mainnet
+ EF - Capella - Rewards - with_not_yet_activated_validators_leak [Preset: mainnet] OK
+ EF - Capella - Rewards - with_slashed_validators [Preset: mainnet] OK
+ EF - Capella - Rewards - with_slashed_validators_leak [Preset: mainnet] OK
+ EF - Capella - Slots - double_empty_epoch [Preset: mainnet] OK
+ EF - Capella - Slots - empty_epoch [Preset: mainnet] OK
+ EF - Capella - Slots - over_epoch_boundary [Preset: mainnet] OK
+ EF - Capella - Slots - slots_1 [Preset: mainnet] OK
+ EF - Capella - Slots - slots_2 [Preset: mainnet] OK
+ EF - Capella - Transition - normal_transition [Preset: mainnet] OK
+ EF - Capella - Transition - simple_transition [Preset: mainnet] OK
+ EF - Capella - Transition - transition_missing_first_post_block [Preset: mainnet] OK
@ -201,6 +216,11 @@ ConsensusSpecPreset-mainnet
+ EF - EIP4844 - Rewards - with_not_yet_activated_validators_leak [Preset: mainnet] OK
+ EF - EIP4844 - Rewards - with_slashed_validators [Preset: mainnet] OK
+ EF - EIP4844 - Rewards - with_slashed_validators_leak [Preset: mainnet] OK
+ EF - EIP4844 - Slots - double_empty_epoch [Preset: mainnet] OK
+ EF - EIP4844 - Slots - empty_epoch [Preset: mainnet] OK
+ EF - EIP4844 - Slots - over_epoch_boundary [Preset: mainnet] OK
+ EF - EIP4844 - Slots - slots_1 [Preset: mainnet] OK
+ EF - EIP4844 - Slots - slots_2 [Preset: mainnet] OK
+ EF - EIP4844 - Transition - normal_transition [Preset: mainnet] OK
+ EF - EIP4844 - Transition - simple_transition [Preset: mainnet] OK
+ EF - EIP4844 - Transition - transition_missing_first_post_block [Preset: mainnet] OK
@ -271,6 +291,11 @@ ConsensusSpecPreset-mainnet
+ EF - Phase 0 - Rewards - with_not_yet_activated_validators_leak [Preset: mainnet] OK
+ EF - Phase 0 - Rewards - with_slashed_validators [Preset: mainnet] OK
+ EF - Phase 0 - Rewards - with_slashed_validators_leak [Preset: mainnet] OK
+ EF - Phase 0 - Slots - double_empty_epoch [Preset: mainnet] OK
+ EF - Phase 0 - Slots - empty_epoch [Preset: mainnet] OK
+ EF - Phase 0 - Slots - over_epoch_boundary [Preset: mainnet] OK
+ EF - Phase 0 - Slots - slots_1 [Preset: mainnet] OK
+ EF - Phase 0 - Slots - slots_2 [Preset: mainnet] OK
+ ForkChoice - mainnet/altair/fork_choice/ex_ante/pyspec_tests/ex_ante_attestations_is_great OK
+ ForkChoice - mainnet/altair/fork_choice/ex_ante/pyspec_tests/ex_ante_sandwich_with_boost_n OK
+ ForkChoice - mainnet/altair/fork_choice/ex_ante/pyspec_tests/ex_ante_sandwich_with_honest_ OK
@ -351,11 +376,6 @@ ConsensusSpecPreset-mainnet
+ Light client - Single merkle proof - mainnet/eip4844/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - mainnet/eip4844/light_client/single_merkle_proof/Beac OK
+ Light client - Single merkle proof - mainnet/eip4844/light_client/single_merkle_proof/Beac OK
+ Slots - double_empty_epoch OK
+ Slots - empty_epoch OK
+ Slots - over_epoch_boundary OK
+ Slots - slots_1 OK
+ Slots - slots_2 OK
+ Sync - mainnet/bellatrix/sync/optimistic/pyspec_tests/from_syncing_to_invalid OK
+ Sync - mainnet/capella/sync/optimistic/pyspec_tests/from_syncing_to_invalid OK
+ [Invalid] EF - Altair - Sanity - Blocks - expected_deposit_in_block [Preset: mainnet] OK
@ -744,7 +764,7 @@ ConsensusSpecPreset-mainnet
+ fork_random_low_balances OK
+ fork_random_misc_balances OK
```
OK: 733/741 Fail: 0/741 Skip: 8/741
OK: 753/761 Fail: 0/761 Skip: 8/761
## Attestation
```diff
+ [Invalid] EF - Altair - Operations - Attestation - after_epoch_slots OK
@ -2419,4 +2439,4 @@ OK: 63/63 Fail: 0/63 Skip: 0/63
OK: 51/51 Fail: 0/51 Skip: 0/51
---TOTAL---
OK: 2125/2133 Fail: 0/2133 Skip: 8/2133
OK: 2145/2153 Fail: 0/2153 Skip: 8/2153

View File

@ -36,6 +36,11 @@ ConsensusSpecPreset-minimal
+ EF - Altair - Rewards - with_not_yet_activated_validators_leak [Preset: minimal] OK
+ EF - Altair - Rewards - with_slashed_validators [Preset: minimal] OK
+ EF - Altair - Rewards - with_slashed_validators_leak [Preset: minimal] OK
+ EF - Altair - Slots - double_empty_epoch [Preset: minimal] OK
+ EF - Altair - Slots - empty_epoch [Preset: minimal] OK
+ EF - Altair - Slots - over_epoch_boundary [Preset: minimal] OK
+ EF - Altair - Slots - slots_1 [Preset: minimal] OK
+ EF - Altair - Slots - slots_2 [Preset: minimal] OK
+ EF - Altair - Transition - normal_transition [Preset: minimal] OK
+ EF - Altair - Transition - simple_transition [Preset: minimal] OK
+ EF - Altair - Transition - transition_missing_first_post_block [Preset: minimal] OK
@ -95,6 +100,11 @@ ConsensusSpecPreset-minimal
+ EF - Bellatrix - Rewards - with_not_yet_activated_validators_leak [Preset: minimal] OK
+ EF - Bellatrix - Rewards - with_slashed_validators [Preset: minimal] OK
+ EF - Bellatrix - Rewards - with_slashed_validators_leak [Preset: minimal] OK
+ EF - Bellatrix - Slots - double_empty_epoch [Preset: minimal] OK
+ EF - Bellatrix - Slots - empty_epoch [Preset: minimal] OK
+ EF - Bellatrix - Slots - over_epoch_boundary [Preset: minimal] OK
+ EF - Bellatrix - Slots - slots_1 [Preset: minimal] OK
+ EF - Bellatrix - Slots - slots_2 [Preset: minimal] OK
+ EF - Bellatrix - Transition - normal_transition [Preset: minimal] OK
+ EF - Bellatrix - Transition - simple_transition [Preset: minimal] OK
+ EF - Bellatrix - Transition - transition_missing_first_post_block [Preset: minimal] OK
@ -154,6 +164,11 @@ ConsensusSpecPreset-minimal
+ EF - Capella - Rewards - with_not_yet_activated_validators_leak [Preset: minimal] OK
+ EF - Capella - Rewards - with_slashed_validators [Preset: minimal] OK
+ EF - Capella - Rewards - with_slashed_validators_leak [Preset: minimal] OK
+ EF - Capella - Slots - double_empty_epoch [Preset: minimal] OK
+ EF - Capella - Slots - empty_epoch [Preset: minimal] OK
+ EF - Capella - Slots - over_epoch_boundary [Preset: minimal] OK
+ EF - Capella - Slots - slots_1 [Preset: minimal] OK
+ EF - Capella - Slots - slots_2 [Preset: minimal] OK
+ EF - Capella - Transition - normal_transition [Preset: minimal] OK
+ EF - Capella - Transition - simple_transition [Preset: minimal] OK
+ EF - Capella - Transition - transition_missing_first_post_block [Preset: minimal] OK
@ -213,6 +228,11 @@ ConsensusSpecPreset-minimal
+ EF - EIP4844 - Rewards - with_not_yet_activated_validators_leak [Preset: minimal] OK
+ EF - EIP4844 - Rewards - with_slashed_validators [Preset: minimal] OK
+ EF - EIP4844 - Rewards - with_slashed_validators_leak [Preset: minimal] OK
+ EF - EIP4844 - Slots - double_empty_epoch [Preset: minimal] OK
+ EF - EIP4844 - Slots - empty_epoch [Preset: minimal] OK
+ EF - EIP4844 - Slots - over_epoch_boundary [Preset: minimal] OK
+ EF - EIP4844 - Slots - slots_1 [Preset: minimal] OK
+ EF - EIP4844 - Slots - slots_2 [Preset: minimal] OK
+ EF - EIP4844 - Transition - normal_transition [Preset: minimal] OK
+ EF - EIP4844 - Transition - simple_transition [Preset: minimal] OK
+ EF - EIP4844 - Transition - transition_missing_first_post_block [Preset: minimal] OK
@ -287,6 +307,11 @@ ConsensusSpecPreset-minimal
+ EF - Phase 0 - Rewards - with_not_yet_activated_validators_leak [Preset: minimal] OK
+ EF - Phase 0 - Rewards - with_slashed_validators [Preset: minimal] OK
+ EF - Phase 0 - Rewards - with_slashed_validators_leak [Preset: minimal] OK
+ EF - Phase 0 - Slots - double_empty_epoch [Preset: minimal] OK
+ EF - Phase 0 - Slots - empty_epoch [Preset: minimal] OK
+ EF - Phase 0 - Slots - over_epoch_boundary [Preset: minimal] OK
+ EF - Phase 0 - Slots - slots_1 [Preset: minimal] OK
+ EF - Phase 0 - Slots - slots_2 [Preset: minimal] OK
+ ForkChoice - minimal/altair/fork_choice/ex_ante/pyspec_tests/ex_ante_sandwich_with_honest_ OK
+ ForkChoice - minimal/altair/fork_choice/ex_ante/pyspec_tests/ex_ante_sandwich_without_atte OK
+ ForkChoice - minimal/altair/fork_choice/ex_ante/pyspec_tests/ex_ante_vanilla OK
@ -415,11 +440,6 @@ ConsensusSpecPreset-minimal
+ Light client - Update ranking - minimal/bellatrix/light_client/update_ranking/pyspec_tests OK
+ Light client - Update ranking - minimal/capella/light_client/update_ranking/pyspec_tests/u OK
+ Light client - Update ranking - minimal/eip4844/light_client/update_ranking/pyspec_tests/u OK
+ Slots - double_empty_epoch OK
+ Slots - empty_epoch OK
+ Slots - over_epoch_boundary OK
+ Slots - slots_1 OK
+ Slots - slots_2 OK
+ Sync - minimal/bellatrix/sync/optimistic/pyspec_tests/from_syncing_to_invalid OK
+ Sync - minimal/capella/sync/optimistic/pyspec_tests/from_syncing_to_invalid OK
+ [Invalid] EF - Altair - Sanity - Blocks - expected_deposit_in_block [Preset: minimal] OK
@ -838,7 +858,7 @@ ConsensusSpecPreset-minimal
+ fork_random_low_balances OK
+ fork_random_misc_balances OK
```
OK: 827/835 Fail: 0/835 Skip: 8/835
OK: 847/855 Fail: 0/855 Skip: 8/855
## Attestation
```diff
+ [Invalid] EF - Altair - Operations - Attestation - after_epoch_slots OK
@ -2591,4 +2611,4 @@ OK: 68/68 Fail: 0/68 Skip: 0/68
OK: 52/52 Fail: 0/52 Skip: 0/52
---TOTAL---
OK: 2281/2289 Fail: 0/2289 Skip: 8/2289
OK: 2301/2309 Fail: 0/2309 Skip: 8/2309

View File

@ -266,17 +266,28 @@ template toFork*[T: eip4844.BeaconState | eip4844.HashedBeaconState](
t: type T): BeaconStateFork =
BeaconStateFork.EIP4844
# TODO these cause stack overflows due to large temporaries getting allocated
# template init*(T: type ForkedHashedBeaconState, data: phase0.HashedBeaconState): T =
# T(kind: BeaconStateFork.Phase0, phase0Data: data)
# template init*(T: type ForkedHashedBeaconState, data: altair.HashedBeaconState): T =
# T(kind: BeaconStateFork.Altair, altairData: data)
# template init*(T: type ForkedHashedBeaconState, data: bellatrix.HashedBeaconState): T =
# T(kind: BeaconStateFork.Bellatrix, bellatrixData: data)
# template init*(T: type ForkedHashedBeaconState, data: capella.HashedBeaconState): T =
# T(kind: BeaconStateFork.Capella, capellaData: data)
# template init*(T: type ForkedHashedBeaconState, data: eip4844.HashedBeaconState): T =
# T(kind: BeaconStateFork.EIP4844, eip4844Data: data)
# TODO when https://github.com/nim-lang/Nim/issues/21086 fixed, use return type
# `ref T`
func new*(T: type ForkedHashedBeaconState, data: phase0.BeaconState):
ref ForkedHashedBeaconState =
(ref T)(kind: BeaconStateFork.Phase0, phase0Data: phase0.HashedBeaconState(
data: data, root: hash_tree_root(data)))
func new*(T: type ForkedHashedBeaconState, data: altair.BeaconState):
ref ForkedHashedBeaconState =
(ref T)(kind: BeaconStateFork.Altair, altairData: altair.HashedBeaconState(
data: data, root: hash_tree_root(data)))
func new*(T: type ForkedHashedBeaconState, data: bellatrix.BeaconState):
ref ForkedHashedBeaconState =
(ref T)(kind: BeaconStateFork.Bellatrix, bellatrixData: bellatrix.HashedBeaconState(
data: data, root: hash_tree_root(data)))
func new*(T: type ForkedHashedBeaconState, data: capella.BeaconState):
ref ForkedHashedBeaconState =
(ref T)(kind: BeaconStateFork.Capella, capellaData: capella.HashedBeaconState(
data: data, root: hash_tree_root(data)))
func new*(T: type ForkedHashedBeaconState, data: eip4844.BeaconState):
ref ForkedHashedBeaconState =
(ref T)(kind: BeaconStateFork.EIP4844, eip4844Data: eip4844.HashedBeaconState(
data: data, root: hash_tree_root(data)))
template init*(T: type ForkedBeaconBlock, blck: phase0.BeaconBlock): T =
T(kind: BeaconBlockFork.Phase0, phase0Data: blck)

View File

@ -205,8 +205,6 @@ func maybeUpgradeStateToCapella(
capellaData: capella.HashedBeaconState(
root: hash_tree_root(newState[]), data: newState[]))[]
from ./datatypes/eip4844 import HashedBeaconState
func maybeUpgradeStateToEIP4844(
cfg: RuntimeConfig, state: var ForkedHashedBeaconState) =
# Both process_slots() and state_transition_block() call this, so only run it

View File

@ -12,7 +12,6 @@ import
./test_fixture_light_client_sync_protocol,
./test_fixture_operations,
./test_fixture_sanity_blocks,
./test_fixture_sanity_slots,
./test_fixture_ssz_consensus_objects,
./test_fixture_state_transition_epoch,
./test_fixture_transition

View File

@ -1,53 +0,0 @@
# beacon_chain
# Copyright (c) 2018-2022 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.used.}
import
# Standard library
os, strutils,
# Beacon chain internals
../../../beacon_chain/spec/[forks, state_transition],
../../../beacon_chain/spec/datatypes/altair,
# Test utilities
../../testutil,
../fixtures_utils,
../../helpers/debug_state
const SanitySlotsDir = SszTestsDir/const_preset/"altair"/"sanity"/"slots"/"pyspec_tests"
proc runTest(identifier: string) =
let
testDir = SanitySlotsDir / identifier
num_slots = readLines(testDir / "slots.yaml", 2)[0].parseInt.uint64
proc `testImpl _ slots _ identifier`() =
test "Slots - " & identifier:
var
preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState))
fhPreState = (ref ForkedHashedBeaconState)(
altairData: altair.HashedBeaconState(
data: preState[], root: hash_tree_root(preState[])),
kind: BeaconStateFork.Altair)
cache = StateCache()
info: ForkedEpochInfo
let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState))
check:
process_slots(
defaultRuntimeConfig, fhPreState[],
getStateField(fhPreState[], slot) + num_slots, cache, info, {}).isOk()
getStateRoot(fhPreState[]) == postState[].hash_tree_root()
let newPreState = newClone(fhPreState.altairData.data)
reportDiff(newPreState, postState)
`testImpl _ slots _ identifier`()
suite "EF - Altair - Sanity - Slots " & preset():
for kind, path in walkDir(SanitySlotsDir, relative = true, checkDir = true):
runTest(path)

View File

@ -11,7 +11,6 @@ import
./test_fixture_fork,
./test_fixture_operations,
./test_fixture_sanity_blocks,
./test_fixture_sanity_slots,
./test_fixture_ssz_consensus_objects,
./test_fixture_state_transition_epoch,
./test_fixture_transition

View File

@ -1,55 +0,0 @@
# beacon_chain
# Copyright (c) 2018-2022 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.used.}
import
# Standard library
os, strutils,
# Beacon chain internals
../../../beacon_chain/spec/[forks, state_transition],
../../../beacon_chain/spec/datatypes/bellatrix,
# Test utilities
../../testutil,
../fixtures_utils,
../../helpers/debug_state
const SanitySlotsDir = SszTestsDir/const_preset/"bellatrix"/"sanity"/"slots"/"pyspec_tests"
proc runTest(identifier: string) =
let
testDir = SanitySlotsDir / identifier
num_slots = readLines(testDir / "slots.yaml", 2)[0].parseInt.uint64
proc `testImpl _ slots _ identifier`() =
test "Slots - " & identifier:
var
preState = newClone(parseTest(
testDir/"pre.ssz_snappy", SSZ, bellatrix.BeaconState))
fhPreState = (ref ForkedHashedBeaconState)(
bellatrixData: bellatrix.HashedBeaconState(
data: preState[], root: hash_tree_root(preState[])),
kind: BeaconStateFork.Bellatrix)
cache = StateCache()
info = ForkedEpochInfo()
let postState = newClone(parseTest(
testDir/"post.ssz_snappy", SSZ, bellatrix.BeaconState))
check:
process_slots(
defaultRuntimeConfig, fhPreState[],
getStateField(fhPreState[], slot) + num_slots, cache, info, {}).isOk()
getStateRoot(fhPreState[]) == postState[].hash_tree_root()
let newPreState = newClone(fhPreState.bellatrixData.data)
reportDiff(newPreState, postState)
`testImpl _ slots _ identifier`()
suite "EF - Bellatrix - Sanity - Slots " & preset():
for kind, path in walkDir(SanitySlotsDir, relative = true, checkDir = true):
runTest(path)

View File

@ -11,7 +11,6 @@ import
./test_fixture_fork,
./test_fixture_operations,
./test_fixture_sanity_blocks,
./test_fixture_sanity_slots,
./test_fixture_ssz_consensus_objects,
./test_fixture_state_transition_epoch,
./test_fixture_transition

View File

@ -1,55 +0,0 @@
# beacon_chain
# Copyright (c) 2022 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.used.}
import
# Standard library
os, strutils,
# Beacon chain internals
../../../beacon_chain/spec/[forks, state_transition],
../../../beacon_chain/spec/datatypes/capella,
# Test utilities
../../testutil,
../fixtures_utils,
../../helpers/debug_state
const SanitySlotsDir = SszTestsDir/const_preset/"capella"/"sanity"/"slots"/"pyspec_tests"
proc runTest(identifier: string) =
let
testDir = SanitySlotsDir / identifier
num_slots = readLines(testDir / "slots.yaml", 2)[0].parseInt.uint64
proc `testImpl _ slots _ identifier`() =
test "Slots - " & identifier:
var
preState = newClone(parseTest(
testDir/"pre.ssz_snappy", SSZ, capella.BeaconState))
fhPreState = (ref ForkedHashedBeaconState)(
capellaData: capella.HashedBeaconState(
data: preState[], root: hash_tree_root(preState[])),
kind: BeaconStateFork.Capella)
cache = StateCache()
info = ForkedEpochInfo()
let postState = newClone(parseTest(
testDir/"post.ssz_snappy", SSZ, capella.BeaconState))
check:
process_slots(
defaultRuntimeConfig, fhPreState[],
getStateField(fhPreState[], slot) + num_slots, cache, info, {}).isOk()
getStateRoot(fhPreState[]) == postState[].hash_tree_root()
let newPreState = newClone(fhPreState.capellaData.data)
reportDiff(newPreState, postState)
`testImpl _ slots _ identifier`()
suite "EF - Capella - Sanity - Slots " & preset():
for kind, path in walkDir(SanitySlotsDir, relative = true, checkDir = true):
runTest(path)

View File

@ -19,6 +19,7 @@ import
./test_fixture_fork_choice,
./test_fixture_light_client_single_merkle_proof,
./test_fixture_light_client_sync,
./test_fixture_light_client_update_ranking
./test_fixture_light_client_update_ranking,
./test_fixture_sanity_slots
summarizeLongTests("ConsensusSpecPreset")

View File

@ -11,7 +11,6 @@ import
./test_fixture_fork,
./test_fixture_operations,
./test_fixture_sanity_blocks,
./test_fixture_sanity_slots,
./test_fixture_ssz_consensus_objects,
./test_fixture_state_transition_epoch,
./test_fixture_transition

View File

@ -1,55 +0,0 @@
# beacon_chain
# Copyright (c) 2022 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.used.}
import
# Standard library
os, strutils,
# Beacon chain internals
../../../beacon_chain/spec/[forks, state_transition],
../../../beacon_chain/spec/datatypes/eip4844,
# Test utilities
../../testutil,
../fixtures_utils,
../../helpers/debug_state
const SanitySlotsDir = SszTestsDir/const_preset/"eip4844"/"sanity"/"slots"/"pyspec_tests"
proc runTest(identifier: string) =
let
testDir = SanitySlotsDir / identifier
num_slots = readLines(testDir / "slots.yaml", 2)[0].parseInt.uint64
proc `testImpl _ slots _ identifier`() =
test "Slots - " & identifier:
var
preState = newClone(parseTest(
testDir/"pre.ssz_snappy", SSZ, eip4844.BeaconState))
fhPreState = (ref ForkedHashedBeaconState)(
eip4844Data: eip4844.HashedBeaconState(
data: preState[], root: hash_tree_root(preState[])),
kind: BeaconStateFork.EIP4844)
cache = StateCache()
info = ForkedEpochInfo()
let postState = newClone(parseTest(
testDir/"post.ssz_snappy", SSZ, eip4844.BeaconState))
check:
process_slots(
defaultRuntimeConfig, fhPreState[],
getStateField(fhPreState[], slot) + num_slots, cache, info, {}).isOk()
getStateRoot(fhPreState[]) == postState[].hash_tree_root()
let newPreState = newClone(fhPreState.eip4844Data.data)
reportDiff(newPreState, postState)
`testImpl _ slots _ identifier`()
suite "EF - EIP4844 - Sanity - Slots " & preset():
for kind, path in walkDir(SanitySlotsDir, relative = true, checkDir = true):
runTest(path)

View File

@ -10,6 +10,5 @@
import
./test_fixture_operations,
./test_fixture_sanity_blocks,
./test_fixture_sanity_slots,
./test_fixture_ssz_consensus_objects,
./test_fixture_state_transition_epoch

View File

@ -1,52 +0,0 @@
# beacon_chain
# Copyright (c) 2018-2022 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.used.}
import
# Standard library
os, strutils,
# Beacon chain internals
../../../beacon_chain/spec/[forks, state_transition],
../../../beacon_chain/spec/datatypes/phase0,
# Test utilities
../../testutil,
../fixtures_utils,
../../helpers/debug_state
const SanitySlotsDir = SszTestsDir/const_preset/"phase0"/"sanity"/"slots"/"pyspec_tests"
proc runTest(identifier: string) =
let
testDir = SanitySlotsDir / identifier
num_slots = readLines(testDir / "slots.yaml", 2)[0].parseInt.uint64
proc `testImpl _ slots _ identifier`() =
test "Slots - " & identifier:
var
preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, phase0.BeaconState))
fhPreState = (ref ForkedHashedBeaconState)(phase0Data: phase0.HashedBeaconState(
data: preState[], root: hash_tree_root(preState[])), kind: BeaconStateFork.Phase0)
cache = StateCache()
info: ForkedEpochInfo
let postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, phase0.BeaconState))
check:
process_slots(
defaultRuntimeConfig,
fhPreState[], getStateField(fhPreState[], slot) + num_slots, cache,
info, {}).isOk()
getStateRoot(fhPreState[]) == postState[].hash_tree_root()
let newPreState = newClone(fhPreState.phase0Data.data)
reportDiff(newPreState, postState)
`testImpl _ slots _ identifier`()
suite "EF - Phase 0 - Sanity - Slots " & preset():
for kind, path in walkDir(SanitySlotsDir, relative = true, checkDir = true):
runTest(path)

View File

@ -0,0 +1,90 @@
# beacon_chain
# Copyright (c) 2018-2022 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.used.}
import ../../beacon_chain/spec/forks
from std/os import walkDir, `/`
from std/strutils import parseInt
from ./fixtures_utils import SszTestsDir, parseTest
from ../testutil import check, preset, suite, test
from ../../beacon_chain/spec/state_transition import process_slots
from ../helpers/debug_state import reportDiff
proc runTest(T: type, testDir, forkName: static[string], identifier: string) =
let
testDir = testDir / identifier
num_slots = readLines(testDir / "slots.yaml", 2)[0].parseInt.uint64
proc `testImpl _ slots _ identifier`() =
test "EF - " & forkName & " - Slots - " & identifier & " [Preset: " & const_preset & "]":
let
preState = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, T))
postState = newClone(parseTest(testDir/"post.ssz_snappy", SSZ, T))
var
fhPreState = ForkedHashedBeaconState.new(preState[])
cache = StateCache()
info: ForkedEpochInfo
check:
process_slots(
defaultRuntimeConfig,
fhPreState[], getStateField(fhPreState[], slot) + num_slots, cache,
info, {}).isOk()
getStateRoot(fhPreState[]) == postState[].hash_tree_root()
withState(fhPreState[]):
when forkyState.data isnot typeof(postState[]):
doAssert false, "mismatched pre/post forks"
else:
reportDiff(forkyState.data, postState[])
`testImpl _ slots _ identifier`()
func sanitySlotsDir(preset_dir: string): string {.compileTime.} =
SszTestsDir/const_preset/preset_dir/"sanity"/"slots"/"pyspec_tests"
from ../../beacon_chain/spec/datatypes/phase0 import BeaconState
suite "EF - Phase 0 - Sanity - Slots " & preset():
const phase0SanitySlotsDir = sanitySlotsDir("phase0")
for kind, path in walkDir(
phase0SanitySlotsDir, relative = true, checkDir = true):
runTest(phase0.BeaconState, phase0SanitySlotsDir, "Phase 0", path)
from ../../beacon_chain/spec/datatypes/altair import BeaconState
suite "EF - Altair - Sanity - Slots " & preset():
const altairSanitySlotsDir = sanitySlotsDir("altair")
for kind, path in walkDir(
altairSanitySlotsDir, relative = true, checkDir = true):
runTest(altair.BeaconState, altairSanitySlotsDir, "Altair", path)
from ../../beacon_chain/spec/datatypes/bellatrix import BeaconState
suite "EF - Bellatrix - Sanity - Slots " & preset():
const bellatrixSanitySlotsDir = sanitySlotsDir("bellatrix")
for kind, path in walkDir(
bellatrixSanitySlotsDir, relative = true, checkDir = true):
runTest(bellatrix.BeaconState, bellatrixSanitySlotsDir, "Bellatrix", path)
from ../../../beacon_chain/spec/datatypes/capella import BeaconState
suite "EF - Capella - Sanity - Slots " & preset():
const capellaSanitySlotsDir = sanitySlotsDir("capella")
for kind, path in walkDir(
capellaSanitySlotsDir, relative = true, checkDir = true):
runTest(capella.BeaconState, capellaSanitySlotsDir, "Capella", path)
from ../../../beacon_chain/spec/datatypes/eip4844 import BeaconState
suite "EF - EIP4844 - Sanity - Slots " & preset():
const eip4844SanitySlotsDir = sanitySlotsDir("eip4844")
for kind, path in walkDir(
eip4844SanitySlotsDir, relative = true, checkDir = true):
runTest(eip4844.BeaconState, eip4844SanitySlotsDir, "EIP4844", path)