2022-12-15 22:51:04 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2021-2024 Status Research & Development GmbH
|
2022-12-15 22:51:04 +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 13:24:08 +00:00
|
|
|
{.push raises: [].}
|
2022-12-15 22:51:04 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
# Beacon chain internals
|
|
|
|
../../beacon_chain/spec/beaconstate,
|
|
|
|
../../beacon_chain/spec/datatypes/phase0,
|
|
|
|
# Test utilities
|
|
|
|
../testutil,
|
2023-02-10 20:59:38 +00:00
|
|
|
./fixtures_utils, ./os_ops,
|
2022-12-15 22:51:04 +00:00
|
|
|
../helpers/debug_state
|
|
|
|
|
|
|
|
proc runTest(
|
2023-09-04 13:05:11 +00:00
|
|
|
BeaconStateAnte, BeaconStatePost: type, forkName, forkDir: static[string],
|
|
|
|
upgrade_func: auto, suiteName, unitTestName: string) =
|
2022-12-15 22:51:04 +00:00
|
|
|
let testDir = forkDir / unitTestName
|
|
|
|
|
2023-09-04 13:05:11 +00:00
|
|
|
test "EF - " & forkName & " - Fork - " & unitTestName & preset():
|
|
|
|
let
|
|
|
|
preState = newClone(
|
|
|
|
parseTest(testDir/"pre.ssz_snappy", SSZ, BeaconStateAnte))
|
|
|
|
postState = newClone(
|
|
|
|
parseTest(testDir/"post.ssz_snappy", SSZ, BeaconStatePost))
|
2022-12-15 22:51:04 +00:00
|
|
|
|
2024-04-28 14:13:17 +00:00
|
|
|
var
|
|
|
|
cfg = defaultRuntimeConfig
|
|
|
|
cache: StateCache
|
2023-09-04 13:05:11 +00:00
|
|
|
when BeaconStateAnte is phase0.BeaconState:
|
|
|
|
cfg.ALTAIR_FORK_EPOCH = preState[].slot.epoch
|
2022-12-15 22:51:04 +00:00
|
|
|
|
2024-04-28 14:13:17 +00:00
|
|
|
when compiles(upgrade_func(cfg, preState[], cache)):
|
|
|
|
let upgradedState = upgrade_func(cfg, preState[], cache)
|
|
|
|
else:
|
|
|
|
let upgradedState = upgrade_func(cfg, preState[])
|
2023-09-04 13:05:11 +00:00
|
|
|
check: upgradedState[].hash_tree_root() == postState[].hash_tree_root()
|
|
|
|
reportDiff(upgradedState, postState)
|
2022-12-15 22:51:04 +00:00
|
|
|
|
|
|
|
from ../../beacon_chain/spec/datatypes/altair import BeaconState
|
|
|
|
|
2023-02-14 13:32:43 +00:00
|
|
|
suite "EF - Altair - Fork " & preset():
|
2022-12-15 22:51:04 +00:00
|
|
|
const OpForkDir =
|
|
|
|
SszTestsDir/const_preset/"altair"/"fork"/"fork"/"pyspec_tests"
|
|
|
|
for kind, path in walkDir(OpForkDir, relative = true, checkDir = true):
|
|
|
|
runTest(phase0.BeaconState, altair.BeaconState, "Altair", OpForkDir,
|
2023-09-04 13:05:11 +00:00
|
|
|
upgrade_to_altair, suiteName, path)
|
2022-12-15 22:51:04 +00:00
|
|
|
|
|
|
|
from ../../beacon_chain/spec/datatypes/bellatrix import BeaconState
|
|
|
|
|
2023-02-14 13:32:43 +00:00
|
|
|
suite "EF - Bellatrix - Fork " & preset():
|
2022-12-15 22:51:04 +00:00
|
|
|
const OpForkDir =
|
|
|
|
SszTestsDir/const_preset/"bellatrix"/"fork"/"fork"/"pyspec_tests"
|
|
|
|
for kind, path in walkDir(OpForkDir, relative = true, checkDir = true):
|
|
|
|
runTest(altair.BeaconState, bellatrix.BeaconState, "Bellatrix", OpForkDir,
|
2023-09-04 13:05:11 +00:00
|
|
|
upgrade_to_bellatrix, suiteName, path)
|
2022-12-15 22:51:04 +00:00
|
|
|
|
|
|
|
from ../../beacon_chain/spec/datatypes/capella import BeaconState
|
|
|
|
|
2023-02-14 13:32:43 +00:00
|
|
|
suite "EF - Capella - Fork " & preset():
|
2022-12-15 22:51:04 +00:00
|
|
|
const OpForkDir =
|
|
|
|
SszTestsDir/const_preset/"capella"/"fork"/"fork"/"pyspec_tests"
|
|
|
|
for kind, path in walkDir(OpForkDir, relative = true, checkDir = true):
|
|
|
|
runTest(bellatrix.BeaconState, capella.BeaconState, "Capella", OpForkDir,
|
2023-09-04 13:05:11 +00:00
|
|
|
upgrade_to_capella, suiteName, path)
|
2022-12-15 22:51:04 +00:00
|
|
|
|
2023-02-21 12:58:08 +00:00
|
|
|
from ../../beacon_chain/spec/datatypes/deneb import BeaconState
|
2022-12-15 22:51:04 +00:00
|
|
|
|
2023-02-14 13:32:43 +00:00
|
|
|
suite "EF - Deneb - Fork " & preset():
|
2022-12-15 22:51:04 +00:00
|
|
|
const OpForkDir =
|
2023-02-21 12:58:08 +00:00
|
|
|
SszTestsDir/const_preset/"deneb"/"fork"/"fork"/"pyspec_tests"
|
2022-12-15 22:51:04 +00:00
|
|
|
for kind, path in walkDir(OpForkDir, relative = true, checkDir = true):
|
2023-02-21 12:58:08 +00:00
|
|
|
runTest(capella.BeaconState, deneb.BeaconState, "Deneb", OpForkDir,
|
2023-09-04 13:05:11 +00:00
|
|
|
upgrade_to_deneb, suiteName, path)
|
2024-04-28 14:13:17 +00:00
|
|
|
|
|
|
|
from ../../beacon_chain/spec/datatypes/electra import BeaconState
|
|
|
|
|
|
|
|
suite "EF - Electra - Fork " & preset():
|
|
|
|
const OpForkDir =
|
|
|
|
SszTestsDir/const_preset/"electra"/"fork"/"fork"/"pyspec_tests"
|
|
|
|
for kind, path in walkDir(OpForkDir, relative = true, checkDir = true):
|
|
|
|
runTest(deneb.BeaconState, electra.BeaconState, "Electra", OpForkDir,
|
|
|
|
upgrade_to_electra, suiteName, path)
|