consolidate block sanity tests across forks (#4422)
This commit is contained in:
parent
2440954555
commit
ebca6879c6
|
@ -11,7 +11,6 @@ import
|
|||
./test_fixture_fork,
|
||||
./test_fixture_light_client_sync_protocol,
|
||||
./test_fixture_operations,
|
||||
./test_fixture_sanity_blocks,
|
||||
./test_fixture_ssz_consensus_objects,
|
||||
./test_fixture_state_transition_epoch,
|
||||
./test_fixture_transition
|
||||
|
|
|
@ -1,77 +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, sequtils, chronicles,
|
||||
# Beacon chain internals
|
||||
../../../beacon_chain/spec/[forks, state_transition],
|
||||
../../../beacon_chain/spec/datatypes/altair,
|
||||
# Test utilities
|
||||
../../testutil,
|
||||
../fixtures_utils
|
||||
|
||||
const
|
||||
FinalityDir = SszTestsDir/const_preset/"altair"/"finality"/"finality"/"pyspec_tests"
|
||||
RandomDir = SszTestsDir/const_preset/"altair"/"random"/"random"/"pyspec_tests"
|
||||
SanityBlocksDir = SszTestsDir/const_preset/"altair"/"sanity"/"blocks"/"pyspec_tests"
|
||||
|
||||
proc runTest(testName, testDir, unitTestName: string) =
|
||||
let testPath = testDir / unitTestName
|
||||
|
||||
proc `testImpl _ blck _ testName`() =
|
||||
let
|
||||
hasPostState = fileExists(testPath/"post.ssz_snappy")
|
||||
prefix = if hasPostState: "[Valid] " else: "[Invalid] "
|
||||
|
||||
test prefix & 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()
|
||||
|
||||
# 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:
|
||||
let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, altair.SignedBeaconBlock)
|
||||
|
||||
if hasPostState:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
res.expect("block should apply: " & $i)
|
||||
else:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
doAssert (i + 1 < numBlocks) or not res.isOk(),
|
||||
"We didn't expect these invalid blocks to be processed"
|
||||
|
||||
if hasPostState:
|
||||
let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, altair.BeaconState))
|
||||
when false:
|
||||
reportDiff(fhPreState.altairData.data, postState)
|
||||
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
|
||||
`testImpl _ blck _ testName`()
|
||||
|
||||
suite "EF - Altair - Sanity - Blocks " & preset():
|
||||
for kind, path in walkDir(SanityBlocksDir, relative = true, checkDir = true):
|
||||
runTest("EF - Altair - Sanity - Blocks", SanityBlocksDir, path)
|
||||
|
||||
suite "EF - Altair - Finality " & preset():
|
||||
for kind, path in walkDir(FinalityDir, relative = true, checkDir = true):
|
||||
runTest("EF - Altair - Finality", FinalityDir, path)
|
||||
|
||||
suite "EF - Altair - Random" & preset():
|
||||
for kind, path in walkDir(RandomDir, relative = true, checkDir = true):
|
||||
runTest("EF - Altair - Random", RandomDir, path)
|
|
@ -8,6 +8,7 @@
|
|||
{.used.}
|
||||
|
||||
import
|
||||
chronicles,
|
||||
yaml,
|
||||
# Standard library
|
||||
os, sequtils,
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
import
|
||||
./test_fixture_fork,
|
||||
./test_fixture_operations,
|
||||
./test_fixture_sanity_blocks,
|
||||
./test_fixture_ssz_consensus_objects,
|
||||
./test_fixture_state_transition_epoch,
|
||||
./test_fixture_transition
|
||||
|
|
|
@ -1,88 +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
|
||||
std/[os, sequtils],
|
||||
# Nimble
|
||||
chronicles,
|
||||
# Beacon chain internals
|
||||
../../../beacon_chain/spec/[forks, state_transition],
|
||||
../../../beacon_chain/spec/datatypes/bellatrix,
|
||||
# Test utilities
|
||||
../../testutil,
|
||||
../../helpers/debug_state,
|
||||
../fixtures_utils
|
||||
|
||||
const
|
||||
FinalityDir = SszTestsDir/const_preset/"bellatrix"/"finality"/"finality"/"pyspec_tests"
|
||||
RandomDir = SszTestsDir/const_preset/"bellatrix"/"random"/"random"/"pyspec_tests"
|
||||
SanityBlocksDir = SszTestsDir/const_preset/"bellatrix"/"sanity"/"blocks"/"pyspec_tests"
|
||||
|
||||
proc runTest(testName, testDir, unitTestName: string) =
|
||||
let testPath = testDir / unitTestName
|
||||
|
||||
proc `testImpl _ blck _ testName`() =
|
||||
let
|
||||
hasPostState = fileExists(testPath/"post.ssz_snappy")
|
||||
prefix = if hasPostState: "[Valid] " else: "[Invalid] "
|
||||
|
||||
test prefix & testName & " - " & unitTestName & preset():
|
||||
var
|
||||
preState = newClone(parseTest(
|
||||
testPath/"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()
|
||||
|
||||
# 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
|
||||
if numBlocks > 1:
|
||||
return
|
||||
for i in 0 ..< numBlocks:
|
||||
let blck = parseTest(
|
||||
testPath/"blocks_" & $i & ".ssz_snappy", SSZ,
|
||||
bellatrix.SignedBeaconBlock)
|
||||
|
||||
if hasPostState:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
res.expect("no failure when applying block " & $i)
|
||||
else:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
doAssert (i + 1 < numBlocks) or not res.isOk,
|
||||
"We didn't expect these invalid blocks to be processed"
|
||||
|
||||
if hasPostState:
|
||||
let postState = newClone(parseTest(
|
||||
testPath/"post.ssz_snappy", SSZ, bellatrix.BeaconState))
|
||||
when false:
|
||||
reportDiff(fhPreState.bellatrixData.data, postState)
|
||||
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
|
||||
`testImpl _ blck _ testName`()
|
||||
|
||||
suite "EF - Bellatrix - Sanity - Blocks " & preset():
|
||||
for kind, path in walkDir(SanityBlocksDir, relative = true, checkDir = true):
|
||||
runTest("EF - Bellatrix - Sanity - Blocks", SanityBlocksDir, path)
|
||||
|
||||
suite "EF - Bellatrix - Random " & preset():
|
||||
for kind, path in walkDir(RandomDir, relative = true, checkDir = true):
|
||||
runTest("EF - Bellatrix - Random", RandomDir, path)
|
||||
|
||||
suite "EF - Bellatrix - Finality " & preset():
|
||||
for kind, path in walkDir(FinalityDir, relative = true, checkDir = true):
|
||||
runTest("EF - Bellatrix - Finality", FinalityDir, path)
|
|
@ -8,6 +8,7 @@
|
|||
{.used.}
|
||||
|
||||
import
|
||||
chronicles,
|
||||
yaml,
|
||||
# Standard library
|
||||
std/[os, sequtils, strutils],
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
import
|
||||
./test_fixture_fork,
|
||||
./test_fixture_operations,
|
||||
./test_fixture_sanity_blocks,
|
||||
./test_fixture_ssz_consensus_objects,
|
||||
./test_fixture_state_transition_epoch,
|
||||
./test_fixture_transition
|
||||
|
|
|
@ -1,88 +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
|
||||
std/[os, sequtils],
|
||||
# Nimble
|
||||
chronicles,
|
||||
# Beacon chain internals
|
||||
../../../beacon_chain/spec/[forks, state_transition],
|
||||
../../../beacon_chain/spec/datatypes/capella,
|
||||
# Test utilities
|
||||
../../testutil,
|
||||
../../helpers/debug_state,
|
||||
../fixtures_utils
|
||||
|
||||
const
|
||||
FinalityDir = SszTestsDir/const_preset/"capella"/"finality"/"finality"/"pyspec_tests"
|
||||
RandomDir = SszTestsDir/const_preset/"capella"/"random"/"random"/"pyspec_tests"
|
||||
SanityBlocksDir = SszTestsDir/const_preset/"capella"/"sanity"/"blocks"/"pyspec_tests"
|
||||
|
||||
proc runTest(testName, testDir, unitTestName: string) =
|
||||
let testPath = testDir / unitTestName
|
||||
|
||||
proc `testImpl _ blck _ testName`() =
|
||||
let
|
||||
hasPostState = fileExists(testPath/"post.ssz_snappy")
|
||||
prefix = if hasPostState: "[Valid] " else: "[Invalid] "
|
||||
|
||||
test prefix & testName & " - " & unitTestName & preset():
|
||||
var
|
||||
preState = newClone(parseTest(
|
||||
testPath/"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()
|
||||
|
||||
# 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
|
||||
if numBlocks > 1:
|
||||
return
|
||||
for i in 0 ..< numBlocks:
|
||||
let blck = parseTest(
|
||||
testPath/"blocks_" & $i & ".ssz_snappy", SSZ,
|
||||
capella.SignedBeaconBlock)
|
||||
|
||||
if hasPostState:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
res.expect("no failure when applying block " & $i)
|
||||
else:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
doAssert (i + 1 < numBlocks) or not res.isOk,
|
||||
"We didn't expect these invalid blocks to be processed"
|
||||
|
||||
if hasPostState:
|
||||
let postState = newClone(parseTest(
|
||||
testPath/"post.ssz_snappy", SSZ, capella.BeaconState))
|
||||
when false:
|
||||
reportDiff(fhPreState.capellaData.data, postState)
|
||||
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
|
||||
`testImpl _ blck _ testName`()
|
||||
|
||||
suite "EF - Capella - Sanity - Blocks " & preset():
|
||||
for kind, path in walkDir(SanityBlocksDir, relative = true, checkDir = true):
|
||||
runTest("EF - Capella - Sanity - Blocks", SanityBlocksDir, path)
|
||||
|
||||
suite "EF - Capella - Random " & preset():
|
||||
for kind, path in walkDir(RandomDir, relative = true, checkDir = true):
|
||||
runTest("EF - Capella - Random", RandomDir, path)
|
||||
|
||||
suite "EF - Capella - Finality " & preset():
|
||||
for kind, path in walkDir(FinalityDir, relative = true, checkDir = true):
|
||||
runTest("EF - Capella - Finality", FinalityDir, path)
|
|
@ -8,6 +8,7 @@
|
|||
{.used.}
|
||||
|
||||
import
|
||||
chronicles,
|
||||
yaml,
|
||||
# Standard library
|
||||
std/[os, sequtils, strutils],
|
||||
|
|
|
@ -20,6 +20,7 @@ import
|
|||
./test_fixture_light_client_single_merkle_proof,
|
||||
./test_fixture_light_client_sync,
|
||||
./test_fixture_light_client_update_ranking,
|
||||
./test_fixture_sanity_blocks,
|
||||
./test_fixture_sanity_slots
|
||||
|
||||
summarizeLongTests("ConsensusSpecPreset")
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
import
|
||||
./test_fixture_fork,
|
||||
./test_fixture_operations,
|
||||
./test_fixture_sanity_blocks,
|
||||
./test_fixture_ssz_consensus_objects,
|
||||
./test_fixture_state_transition_epoch,
|
||||
./test_fixture_transition
|
||||
|
|
|
@ -1,88 +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
|
||||
std/[os, sequtils],
|
||||
# Nimble
|
||||
chronicles,
|
||||
# Beacon chain internals
|
||||
../../../beacon_chain/spec/[forks, state_transition],
|
||||
../../../beacon_chain/spec/datatypes/eip4844,
|
||||
# Test utilities
|
||||
../../testutil,
|
||||
../../helpers/debug_state,
|
||||
../fixtures_utils
|
||||
|
||||
const
|
||||
FinalityDir = SszTestsDir/const_preset/"eip4844"/"finality"/"finality"/"pyspec_tests"
|
||||
RandomDir = SszTestsDir/const_preset/"eip4844"/"random"/"random"/"pyspec_tests"
|
||||
SanityBlocksDir = SszTestsDir/const_preset/"eip4844"/"sanity"/"blocks"/"pyspec_tests"
|
||||
|
||||
proc runTest(testName, testDir, unitTestName: string) =
|
||||
let testPath = testDir / unitTestName
|
||||
|
||||
proc `testImpl _ blck _ testName`() =
|
||||
let
|
||||
hasPostState = fileExists(testPath/"post.ssz_snappy")
|
||||
prefix = if hasPostState: "[Valid] " else: "[Invalid] "
|
||||
|
||||
test prefix & testName & " - " & unitTestName & preset():
|
||||
var
|
||||
preState = newClone(parseTest(
|
||||
testPath/"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()
|
||||
|
||||
# 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
|
||||
if numBlocks > 1:
|
||||
return
|
||||
for i in 0 ..< numBlocks:
|
||||
let blck = parseTest(
|
||||
testPath/"blocks_" & $i & ".ssz_snappy", SSZ,
|
||||
eip4844.SignedBeaconBlock)
|
||||
|
||||
if hasPostState:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
res.expect("no failure when applying block " & $i)
|
||||
else:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
doAssert (i + 1 < numBlocks) or not res.isOk,
|
||||
"We didn't expect these invalid blocks to be processed"
|
||||
|
||||
if hasPostState:
|
||||
let postState = newClone(parseTest(
|
||||
testPath/"post.ssz_snappy", SSZ, eip4844.BeaconState))
|
||||
when false:
|
||||
reportDiff(fhPreState.eip4844Data.data, postState)
|
||||
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
|
||||
`testImpl _ blck _ testName`()
|
||||
|
||||
suite "EF - EIP4844 - Sanity - Blocks " & preset():
|
||||
for kind, path in walkDir(SanityBlocksDir, relative = true, checkDir = true):
|
||||
runTest("EF - EIP4844 - Sanity - Blocks", SanityBlocksDir, path)
|
||||
|
||||
suite "EF - EIP4844 - Random " & preset():
|
||||
for kind, path in walkDir(RandomDir, relative = true, checkDir = true):
|
||||
runTest("EF - EIP4844 - Random", RandomDir, path)
|
||||
|
||||
suite "EF - EIP4844 - Finality " & preset():
|
||||
for kind, path in walkDir(FinalityDir, relative = true, checkDir = true):
|
||||
runTest("EF - EIP4844 - Finality", FinalityDir, path)
|
|
@ -8,6 +8,7 @@
|
|||
{.used.}
|
||||
|
||||
import
|
||||
chronicles,
|
||||
yaml,
|
||||
# Standard library
|
||||
std/[os, sequtils, strutils],
|
||||
|
|
|
@ -9,6 +9,5 @@
|
|||
|
||||
import
|
||||
./test_fixture_operations,
|
||||
./test_fixture_sanity_blocks,
|
||||
./test_fixture_ssz_consensus_objects,
|
||||
./test_fixture_state_transition_epoch
|
||||
|
|
|
@ -1,76 +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, sequtils, chronicles,
|
||||
# Beacon chain internals
|
||||
../../../beacon_chain/spec/[forks, state_transition],
|
||||
../../../beacon_chain/spec/datatypes/phase0,
|
||||
# Test utilities
|
||||
../../testutil,
|
||||
../fixtures_utils
|
||||
|
||||
const
|
||||
FinalityDir = SszTestsDir/const_preset/"phase0"/"finality"/"finality"/"pyspec_tests"
|
||||
RandomDir = SszTestsDir/const_preset/"phase0"/"random"/"random"/"pyspec_tests"
|
||||
SanityBlocksDir = SszTestsDir/const_preset/"phase0"/"sanity"/"blocks"/"pyspec_tests"
|
||||
|
||||
proc runTest(testName, testDir, unitTestName: string) =
|
||||
let testPath = testDir / unitTestName
|
||||
|
||||
proc `testImpl _ blck _ testName`() =
|
||||
let
|
||||
hasPostState = fileExists(testPath/"post.ssz_snappy")
|
||||
prefix = if hasPostState: "[Valid] " else: "[Invalid] "
|
||||
|
||||
test prefix & testName & " - " & unitTestName & preset():
|
||||
var
|
||||
preState = newClone(parseTest(testPath/"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()
|
||||
|
||||
# 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:
|
||||
let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, phase0.SignedBeaconBlock)
|
||||
|
||||
if hasPostState:
|
||||
state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback).expect("should apply block")
|
||||
else:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
doAssert (i + 1 < numBlocks) or not res.isOk(),
|
||||
"We didn't expect these invalid blocks to be processed"
|
||||
|
||||
if hasPostState:
|
||||
let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, phase0.BeaconState))
|
||||
when false:
|
||||
reportDiff(hashedPreState.phase0Data.data, postState)
|
||||
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
|
||||
`testImpl _ blck _ testName`()
|
||||
|
||||
suite "EF - Phase 0 - Sanity - Blocks " & preset():
|
||||
for kind, path in walkDir(SanityBlocksDir, relative = true, checkDir = true):
|
||||
runTest("EF - Phase 0 - Sanity - Blocks", SanityBlocksDir, path)
|
||||
|
||||
suite "EF - Phase 0 - Finality " & preset():
|
||||
for kind, path in walkDir(FinalityDir, relative = true, checkDir = true):
|
||||
runTest("EF - Phase 0 - Finality", FinalityDir, path)
|
||||
|
||||
suite "EF - Phase 0 - Random " & preset():
|
||||
for kind, path in walkDir(RandomDir, relative = true, checkDir = true):
|
||||
runTest("EF - Phase 0 - Random", RandomDir, path)
|
|
@ -0,0 +1,115 @@
|
|||
# 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/datatypes/phase0,
|
||||
../../beacon_chain/spec/state_transition,
|
||||
../testutil
|
||||
|
||||
from std/os import fileExists, walkDir, walkPattern, `/`
|
||||
from std/sequtils import toSeq
|
||||
from ../../../beacon_chain/spec/forks import
|
||||
ForkedEpochInfo, ForkedHashedBeaconState, fromSszBytes, getStateRoot, new
|
||||
from ../../../beacon_chain/spec/presets import
|
||||
const_preset, defaultRuntimeConfig
|
||||
from ./fixtures_utils import
|
||||
SSZ, SszTestsDir, hash_tree_root, parseTest, readSszBytes, toSszType
|
||||
|
||||
proc runTest(
|
||||
BS, SBB: type, testName, testDir: static[string], unitTestName: string) =
|
||||
let testPath = testDir / unitTestName
|
||||
|
||||
proc `testImpl _ blck _ testName`() =
|
||||
let
|
||||
hasPostState = fileExists(testPath/"post.ssz_snappy")
|
||||
prefix = if hasPostState: "[Valid] " else: "[Invalid] "
|
||||
|
||||
test prefix & testName & " - " & unitTestName & preset():
|
||||
let preState = newClone(parseTest(testPath/"pre.ssz_snappy", SSZ, BS))
|
||||
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:
|
||||
let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy", SSZ, SBB)
|
||||
|
||||
if hasPostState:
|
||||
state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback).expect("should apply block")
|
||||
else:
|
||||
let res = state_transition(
|
||||
defaultRuntimeConfig, fhPreState[], blck, cache, info, flags = {},
|
||||
noRollback)
|
||||
doAssert (i + 1 < numBlocks) or not res.isOk(),
|
||||
"We didn't expect these invalid blocks to be processed"
|
||||
|
||||
if hasPostState:
|
||||
let postState = newClone(parseTest(testPath/"post.ssz_snappy", SSZ, BS))
|
||||
when false:
|
||||
reportDiff(hashedPreState.phase0Data.data, postState)
|
||||
doAssert getStateRoot(fhPreState[]) == postState[].hash_tree_root()
|
||||
|
||||
`testImpl _ blck _ testName`()
|
||||
|
||||
template runForkBlockTests(
|
||||
forkDirName, forkHumanName: static[string], BeaconStateType,
|
||||
BeaconBlockType: untyped) =
|
||||
const
|
||||
FinalityDir =
|
||||
SszTestsDir/const_preset/forkDirName/"finality"/"finality"/"pyspec_tests"
|
||||
RandomDir =
|
||||
SszTestsDir/const_preset/forkDirName/"random"/"random"/"pyspec_tests"
|
||||
SanityBlocksDir =
|
||||
SszTestsDir/const_preset/forkDirName/"sanity"/"blocks"/"pyspec_tests"
|
||||
|
||||
suite "EF - " & forkHumanName & " - Sanity - Blocks " & preset():
|
||||
for kind, path in walkDir(SanityBlocksDir, relative = true, checkDir = true):
|
||||
runTest(
|
||||
BeaconStateType, BeaconBlockType,
|
||||
"EF - " & forkHumanName & " - Sanity - Blocks", SanityBlocksDir, path)
|
||||
|
||||
suite "EF - " & forkHumanName & " - Finality " & preset():
|
||||
for kind, path in walkDir(FinalityDir, relative = true, checkDir = true):
|
||||
runTest(
|
||||
BeaconStateType, BeaconBlockType,
|
||||
"EF - " & forkHumanName & " - Finality", FinalityDir, path)
|
||||
|
||||
suite "EF - " & forkHumanName & " - Random " & preset():
|
||||
for kind, path in walkDir(RandomDir, relative = true, checkDir = true):
|
||||
runTest(
|
||||
BeaconStateType, BeaconBlockType,
|
||||
"EF - " & forkHumanName & " - Random", RandomDir, path)
|
||||
|
||||
runForkBlockTests(
|
||||
"phase0", "Phase 0", phase0.BeaconState, phase0.SignedBeaconBlock)
|
||||
|
||||
from ../../../beacon_chain/spec/datatypes/altair import
|
||||
BeaconState, SignedBeaconBlock
|
||||
runForkBlockTests(
|
||||
"altair", "Altair", altair.BeaconState, altair.SignedBeaconBlock)
|
||||
|
||||
from ../../../beacon_chain/spec/datatypes/bellatrix import
|
||||
BeaconState, SignedBeaconBlock
|
||||
runForkBlockTests(
|
||||
"bellatrix", "Bellatrix", bellatrix.BeaconState, bellatrix.SignedBeaconBlock)
|
||||
|
||||
from ../../../beacon_chain/spec/datatypes/capella import
|
||||
BeaconState, SignedBeaconBlock
|
||||
runForkBlockTests(
|
||||
"capella", "Capella", capella.BeaconState, capella.SignedBeaconBlock)
|
||||
|
||||
from ../../../beacon_chain/spec/datatypes/eip4844 import
|
||||
BeaconState, SignedBeaconBlock
|
||||
runForkBlockTests(
|
||||
"eip4844", "EIP4844", eip4844.BeaconState, eip4844.SignedBeaconBlock)
|
Loading…
Reference in New Issue