2022-12-13 15:58:59 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2022-12-13 15:58:59 +00:00
|
|
|
# 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.
|
|
|
|
|
2024-02-29 10:28:32 +00:00
|
|
|
{.push raises: [].}
|
2022-12-13 15:58:59 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import ../../beacon_chain/spec/forks
|
2023-02-10 20:59:38 +00:00
|
|
|
import os_ops
|
2022-12-13 15:58:59 +00:00
|
|
|
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
|
|
|
|
|
2024-02-29 10:28:32 +00:00
|
|
|
proc runTest(
|
|
|
|
T: type,
|
|
|
|
testDir, forkName: static[string],
|
|
|
|
suiteName, identifier: string) {.raises: [IOError, ValueError].} =
|
2022-12-13 15:58:59 +00:00
|
|
|
let
|
|
|
|
testDir = testDir / identifier
|
|
|
|
num_slots = readLines(testDir / "slots.yaml", 2)[0].parseInt.uint64
|
|
|
|
|
2023-09-04 13:05:11 +00:00
|
|
|
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[])
|
2022-12-13 15:58:59 +00:00
|
|
|
|
|
|
|
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):
|
2023-09-04 13:05:11 +00:00
|
|
|
runTest(phase0.BeaconState, phase0SanitySlotsDir, "Phase 0", suiteName, path)
|
2022-12-13 15:58:59 +00:00
|
|
|
|
|
|
|
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):
|
2023-09-04 13:05:11 +00:00
|
|
|
runTest(altair.BeaconState, altairSanitySlotsDir, "Altair", suiteName, path)
|
2022-12-13 15:58:59 +00:00
|
|
|
|
|
|
|
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):
|
2023-09-04 13:05:11 +00:00
|
|
|
runTest(bellatrix.BeaconState, bellatrixSanitySlotsDir, "Bellatrix", suiteName, path)
|
2022-12-13 15:58:59 +00:00
|
|
|
|
2023-09-06 08:17:59 +00:00
|
|
|
from ../../beacon_chain/spec/datatypes/capella import BeaconState
|
2022-12-13 15:58:59 +00:00
|
|
|
|
|
|
|
suite "EF - Capella - Sanity - Slots " & preset():
|
|
|
|
const capellaSanitySlotsDir = sanitySlotsDir("capella")
|
|
|
|
for kind, path in walkDir(
|
|
|
|
capellaSanitySlotsDir, relative = true, checkDir = true):
|
2023-09-04 13:05:11 +00:00
|
|
|
runTest(capella.BeaconState, capellaSanitySlotsDir, "Capella", suiteName, path)
|
2022-12-13 15:58:59 +00:00
|
|
|
|
2023-09-06 08:17:59 +00:00
|
|
|
from ../../beacon_chain/spec/datatypes/deneb import BeaconState
|
2022-12-13 15:58:59 +00:00
|
|
|
|
2023-02-14 13:32:43 +00:00
|
|
|
suite "EF - Deneb - Sanity - Slots " & preset():
|
2023-02-21 12:58:08 +00:00
|
|
|
const denebSanitySlotsDir = sanitySlotsDir("deneb")
|
2022-12-13 15:58:59 +00:00
|
|
|
for kind, path in walkDir(
|
2023-02-21 12:58:08 +00:00
|
|
|
denebSanitySlotsDir, relative = true, checkDir = true):
|
2023-09-04 13:05:11 +00:00
|
|
|
runTest(deneb.BeaconState, denebSanitySlotsDir, "Deneb", suiteName, path)
|
2024-04-23 07:58:32 +00:00
|
|
|
|
|
|
|
from ../../beacon_chain/spec/datatypes/electra import BeaconState
|
|
|
|
|
|
|
|
suite "EF - Electra - Sanity - Slots " & preset():
|
|
|
|
const electraSanitySlotsDir = sanitySlotsDir("electra")
|
|
|
|
for kind, path in walkDir(
|
|
|
|
electraSanitySlotsDir, relative = true, checkDir = true):
|
|
|
|
runTest(
|
|
|
|
electra.BeaconState, electraSanitySlotsDir, "Electra", suiteName, path)
|