2022-12-15 22:51:04 +00:00
|
|
|
# beacon_chain
|
2024-01-06 06:18:28 +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.
|
|
|
|
|
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
yaml,
|
2023-02-10 20:59:38 +00:00
|
|
|
../../beacon_chain/spec/[state_transition, forks],
|
|
|
|
./os_ops
|
2022-12-15 22:51:04 +00:00
|
|
|
|
|
|
|
from std/sequtils import toSeq
|
2024-01-06 06:18:28 +00:00
|
|
|
from std/streams import close, openFileStream
|
2022-12-15 22:51:04 +00:00
|
|
|
from ../testutil import preset, suite, test
|
|
|
|
from ./fixtures_utils import SszTestsDir, parseTest
|
|
|
|
|
|
|
|
type
|
|
|
|
TransitionInfo = object
|
|
|
|
post_fork: string
|
|
|
|
fork_epoch: int
|
|
|
|
blocks_count: int
|
|
|
|
fork_block {.defaultVal: -1.}: int
|
|
|
|
bls_setting {.defaultVal: 1.}: int
|
|
|
|
|
|
|
|
proc getTransitionInfo(testPath: string): TransitionInfo =
|
|
|
|
var transitionInfo: TransitionInfo
|
|
|
|
let s = openFileStream(testPath/"meta.yaml")
|
|
|
|
defer: close(s)
|
|
|
|
yaml.load(s, transitionInfo)
|
|
|
|
transitionInfo
|
|
|
|
|
|
|
|
proc runTest(
|
|
|
|
AnteBeaconState, PostBeaconState, AnteBeaconBlock, PostBeaconBlock: type,
|
|
|
|
cfg: RuntimeConfig, testName, testDir: static[string],
|
2023-09-04 13:05:11 +00:00
|
|
|
suiteName, unitTestName: string, fork_block: int) =
|
2022-12-15 22:51:04 +00:00
|
|
|
let testPath = testDir / unitTestName
|
|
|
|
|
2023-09-04 13:05:11 +00:00
|
|
|
test testName & " - " & unitTestName & preset():
|
|
|
|
let preState =
|
|
|
|
newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, AnteBeaconState))
|
|
|
|
var
|
|
|
|
fhPreState = ForkedHashedBeaconState.new(preState[])
|
|
|
|
cache = StateCache()
|
|
|
|
info = ForkedEpochInfo()
|
|
|
|
|
|
|
|
# In test cases with more than 10 blocks the first 10 aren't 0-prefixed,
|
|
|
|
# so purely lexicographic sorting wouldn't sort properly.
|
|
|
|
let numBlocks = toSeq(walkPattern(testPath/"blocks_*.ssz_snappy")).len
|
|
|
|
for i in 0 ..< numBlocks:
|
|
|
|
if i <= fork_block:
|
|
|
|
let
|
|
|
|
blck = parseTest(
|
|
|
|
testPath/"blocks_" & $i & ".ssz_snappy", SSZ, AnteBeaconBlock)
|
|
|
|
res = state_transition(
|
|
|
|
cfg, fhPreState[], blck, cache, info,
|
|
|
|
flags = {skipStateRootValidation}, noRollback)
|
|
|
|
|
|
|
|
res.expect("no failure when applying block " & $i)
|
|
|
|
else:
|
|
|
|
let
|
|
|
|
blck = parseTest(
|
|
|
|
testPath/"blocks_" & $i & ".ssz_snappy", SSZ, PostBeaconBlock)
|
|
|
|
res = state_transition(
|
|
|
|
cfg, fhPreState[], blck, cache, info,
|
|
|
|
flags = {skipStateRootValidation}, noRollback)
|
|
|
|
|
|
|
|
res.expect("no failure when applying block " & $i)
|
|
|
|
|
|
|
|
let postState = newClone(
|
|
|
|
parseTest(testPath/"post.ssz_snappy", SSZ, PostBeaconState))
|
|
|
|
when false:
|
|
|
|
reportDiff(fhPreState.data, postState)
|
|
|
|
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
2022-12-15 22:51:04 +00:00
|
|
|
|
|
|
|
from ../../beacon_chain/spec/datatypes/phase0 import
|
|
|
|
BeaconState, SignedBeaconBlock
|
|
|
|
from ../../beacon_chain/spec/datatypes/altair import
|
|
|
|
BeaconState, SignedBeaconBlock
|
|
|
|
|
|
|
|
suite "EF - Altair - Transition " & preset():
|
|
|
|
const TransitionDir =
|
|
|
|
SszTestsDir/const_preset/"altair"/"transition"/"core"/"pyspec_tests"
|
|
|
|
|
|
|
|
for kind, path in walkDir(TransitionDir, relative = true, checkDir = true):
|
|
|
|
let transitionInfo = getTransitionInfo(TransitionDir / path)
|
|
|
|
var cfg = defaultRuntimeConfig
|
|
|
|
cfg.ALTAIR_FORK_EPOCH = transitionInfo.fork_epoch.Epoch
|
|
|
|
runTest(
|
|
|
|
phase0.BeaconState, altair.BeaconState, phase0.SignedBeaconBlock,
|
|
|
|
altair.SignedBeaconBlock, cfg, "EF - Altair - Transition", TransitionDir,
|
2023-09-04 13:05:11 +00:00
|
|
|
suiteName, path, transitionInfo.fork_block)
|
2022-12-15 22:51:04 +00:00
|
|
|
|
|
|
|
from ../../beacon_chain/spec/datatypes/bellatrix import
|
|
|
|
BeaconState, SignedBeaconBlock
|
|
|
|
|
|
|
|
suite "EF - Bellatrix - Transition " & preset():
|
|
|
|
const TransitionDir =
|
|
|
|
SszTestsDir/const_preset/"bellatrix"/"transition"/"core"/"pyspec_tests"
|
|
|
|
|
|
|
|
for kind, path in walkDir(TransitionDir, relative = true, checkDir = true):
|
|
|
|
let transitionInfo = getTransitionInfo(TransitionDir / path)
|
|
|
|
var cfg = defaultRuntimeConfig
|
|
|
|
cfg.BELLATRIX_FORK_EPOCH = transitionInfo.fork_epoch.Epoch
|
|
|
|
runTest(
|
|
|
|
altair.BeaconState, bellatrix.BeaconState, altair.SignedBeaconBlock,
|
|
|
|
bellatrix.SignedBeaconBlock, cfg, "EF - Bellatrix - Transition",
|
2023-09-04 13:05:11 +00:00
|
|
|
TransitionDir, suiteName, path, transitionInfo.fork_block)
|
2022-12-15 22:51:04 +00:00
|
|
|
|
|
|
|
from ../../beacon_chain/spec/datatypes/capella import
|
|
|
|
BeaconState, SignedBeaconBlock
|
|
|
|
|
|
|
|
suite "EF - Capella - Transition " & preset():
|
|
|
|
const TransitionDir =
|
|
|
|
SszTestsDir/const_preset/"capella"/"transition"/"core"/"pyspec_tests"
|
|
|
|
|
|
|
|
for kind, path in walkDir(TransitionDir, relative = true, checkDir = true):
|
|
|
|
let transitionInfo = getTransitionInfo(TransitionDir / path)
|
|
|
|
var cfg = defaultRuntimeConfig
|
|
|
|
cfg.CAPELLA_FORK_EPOCH = transitionInfo.fork_epoch.Epoch
|
|
|
|
runTest(
|
|
|
|
bellatrix.BeaconState, capella.BeaconState, bellatrix.SignedBeaconBlock,
|
|
|
|
capella.SignedBeaconBlock, cfg, "EF - Capella - Transition",
|
2023-09-04 13:05:11 +00:00
|
|
|
TransitionDir, suiteName, path, transitionInfo.fork_block)
|
2022-12-15 22:51:04 +00:00
|
|
|
|
2023-02-21 12:58:08 +00:00
|
|
|
from ../../beacon_chain/spec/datatypes/deneb import
|
2022-12-15 22:51:04 +00:00
|
|
|
BeaconState, SignedBeaconBlock
|
|
|
|
|
2023-02-14 13:32:43 +00:00
|
|
|
suite "EF - Deneb - Transition " & preset():
|
2022-12-15 22:51:04 +00:00
|
|
|
const TransitionDir =
|
2023-02-21 12:58:08 +00:00
|
|
|
SszTestsDir/const_preset/"deneb"/"transition"/"core"/"pyspec_tests"
|
2022-12-15 22:51:04 +00:00
|
|
|
|
|
|
|
for kind, path in walkDir(TransitionDir, relative = true, checkDir = true):
|
|
|
|
let transitionInfo = getTransitionInfo(TransitionDir / path)
|
|
|
|
var cfg = defaultRuntimeConfig
|
2023-02-15 14:44:09 +00:00
|
|
|
cfg.DENEB_FORK_EPOCH = transitionInfo.fork_epoch.Epoch
|
2022-12-15 22:51:04 +00:00
|
|
|
runTest(
|
2023-02-21 12:58:08 +00:00
|
|
|
capella.BeaconState, deneb.BeaconState, capella.SignedBeaconBlock,
|
2023-03-10 17:12:46 +00:00
|
|
|
deneb.SignedBeaconBlock, cfg, "EF - Deneb - Transition",
|
2023-09-04 13:05:11 +00:00
|
|
|
TransitionDir, suiteName, path, transitionInfo.fork_block)
|