2022-01-05 08:42:56 +00:00
|
|
|
# beacon_chain
|
|
|
|
# Copyright (c) 2021-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
|
|
|
|
yaml,
|
|
|
|
# Standard library
|
|
|
|
std/[os, sequtils, strutils],
|
|
|
|
# Status internal
|
|
|
|
chronicles,
|
|
|
|
faststreams, streams,
|
|
|
|
# Beacon chain internals
|
|
|
|
../../../beacon_chain/spec/[state_transition, forks, helpers],
|
2022-01-12 14:50:30 +00:00
|
|
|
../../../beacon_chain/spec/datatypes/[altair, bellatrix],
|
2022-01-05 08:42:56 +00:00
|
|
|
# Test utilities
|
|
|
|
../../testutil,
|
|
|
|
../fixtures_utils
|
|
|
|
|
|
|
|
const
|
|
|
|
TransitionDir = SszTestsDir/const_preset/"bellatrix"/"transition"/"core"/"pyspec_tests"
|
|
|
|
|
|
|
|
type
|
|
|
|
TransitionInfo = object
|
|
|
|
post_fork: string
|
|
|
|
fork_epoch: int
|
|
|
|
blocks_count: int
|
|
|
|
fork_block {.defaultVal: -1.}: int
|
|
|
|
bls_setting {.defaultVal: 1.}: int
|
|
|
|
|
|
|
|
proc runTest(testName, testDir, unitTestName: string) =
|
|
|
|
let testPath = testDir / unitTestName
|
|
|
|
|
|
|
|
var transitionInfo: TransitionInfo
|
2022-02-20 20:13:06 +00:00
|
|
|
let s = openFileStream(testPath/"meta.yaml")
|
2022-01-05 08:42:56 +00:00
|
|
|
defer: close(s)
|
|
|
|
yaml.load(s, transitionInfo)
|
|
|
|
|
|
|
|
proc `testImpl _ blck _ testName`() =
|
|
|
|
test testName & " - " & unitTestName & preset():
|
|
|
|
var
|
|
|
|
preState = newClone(parseTest(testPath/"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()
|
|
|
|
cfg = defaultRuntimeConfig
|
2022-02-02 13:06:55 +00:00
|
|
|
cfg.BELLATRIX_FORK_EPOCH = transitionInfo.fork_epoch.Epoch
|
2022-01-05 08:42:56 +00:00
|
|
|
|
|
|
|
# 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 <= transitionInfo.fork_block:
|
2022-01-12 14:50:30 +00:00
|
|
|
let blck = parseTest(
|
|
|
|
testPath/"blocks_" & $i & ".ssz_snappy", SSZ,
|
|
|
|
altair.SignedBeaconBlock)
|
2022-01-05 08:42:56 +00:00
|
|
|
|
2022-01-17 11:19:58 +00:00
|
|
|
let res = state_transition(
|
2022-01-05 08:42:56 +00:00
|
|
|
cfg, fhPreState[], blck, cache, info,
|
|
|
|
flags = {skipStateRootValidation}, noRollback)
|
2022-01-17 11:19:58 +00:00
|
|
|
res.expect("no failure when applying block " & $i)
|
2022-01-05 08:42:56 +00:00
|
|
|
else:
|
2022-01-12 14:50:30 +00:00
|
|
|
let blck = parseTest(
|
|
|
|
testPath/"blocks_" & $i & ".ssz_snappy", SSZ,
|
|
|
|
bellatrix.SignedBeaconBlock)
|
2022-01-05 08:42:56 +00:00
|
|
|
|
2022-01-17 11:19:58 +00:00
|
|
|
let res = state_transition(
|
2022-01-05 08:42:56 +00:00
|
|
|
cfg, fhPreState[], blck, cache, info,
|
|
|
|
flags = {skipStateRootValidation}, noRollback)
|
2022-01-17 11:19:58 +00:00
|
|
|
res.expect("no failure when applying block " & $i)
|
2022-01-05 08:42:56 +00:00
|
|
|
|
2022-01-12 14:50:30 +00:00
|
|
|
let postState = newClone(parseTest(
|
|
|
|
testPath/"post.ssz_snappy", SSZ, bellatrix.BeaconState))
|
2022-01-05 08:42:56 +00:00
|
|
|
when false:
|
|
|
|
reportDiff(fhPreState.data, postState)
|
|
|
|
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
|
|
|
|
|
|
|
`testImpl _ blck _ testName`()
|
|
|
|
|
|
|
|
suite "EF - Bellatrix - Transition " & preset():
|
|
|
|
for kind, path in walkDir(TransitionDir, relative = true, checkDir = true):
|
|
|
|
runTest("EF - Bellatrix - Transition", TransitionDir, path)
|