2022-12-06 16:43:11 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2022-2024 Status Research & Development GmbH
|
2022-12-06 16:43:11 +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-06 16:43:11 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
# Status internals
|
|
|
|
chronicles,
|
|
|
|
# Beacon chain internals
|
2024-05-23 21:51:09 +00:00
|
|
|
../../../beacon_chain/spec/[presets, state_transition_epoch],
|
2023-02-25 01:03:34 +00:00
|
|
|
../../../beacon_chain/spec/datatypes/[altair, deneb],
|
2022-12-06 16:43:11 +00:00
|
|
|
# Test utilities
|
|
|
|
../../testutil,
|
2023-02-10 20:59:38 +00:00
|
|
|
../fixtures_utils, ../os_ops,
|
2022-12-06 16:43:11 +00:00
|
|
|
./test_fixture_rewards,
|
|
|
|
../../helpers/debug_state
|
|
|
|
|
|
|
|
from std/sequtils import mapIt, toSeq
|
|
|
|
from std/strutils import rsplit
|
|
|
|
|
|
|
|
const
|
2023-02-21 12:58:08 +00:00
|
|
|
RootDir = SszTestsDir/const_preset/"deneb"/"epoch_processing"
|
2022-12-06 16:43:11 +00:00
|
|
|
|
|
|
|
JustificationFinalizationDir = RootDir/"justification_and_finalization"
|
|
|
|
InactivityDir = RootDir/"inactivity_updates"
|
|
|
|
RegistryUpdatesDir = RootDir/"registry_updates"
|
|
|
|
SlashingsDir = RootDir/"slashings"
|
|
|
|
Eth1DataResetDir = RootDir/"eth1_data_reset"
|
|
|
|
EffectiveBalanceUpdatesDir = RootDir/"effective_balance_updates"
|
|
|
|
SlashingsResetDir = RootDir/"slashings_reset"
|
|
|
|
RandaoMixesResetDir = RootDir/"randao_mixes_reset"
|
|
|
|
ParticipationFlagDir = RootDir/"participation_flag_updates"
|
|
|
|
SyncCommitteeDir = RootDir/"sync_committee_updates"
|
|
|
|
RewardsAndPenaltiesDir = RootDir/"rewards_and_penalties"
|
2023-01-09 14:15:43 +00:00
|
|
|
HistoricalSummariesUpdateDir = RootDir/"historical_summaries_update"
|
2022-12-06 16:43:11 +00:00
|
|
|
|
|
|
|
doAssert (toHashSet(mapIt(toSeq(walkDir(RootDir, relative = false)), it.path)) -
|
|
|
|
toHashSet([SyncCommitteeDir])) ==
|
|
|
|
toHashSet([
|
|
|
|
JustificationFinalizationDir, InactivityDir, RegistryUpdatesDir,
|
|
|
|
SlashingsDir, Eth1DataResetDir, EffectiveBalanceUpdatesDir,
|
2023-01-09 14:15:43 +00:00
|
|
|
SlashingsResetDir, RandaoMixesResetDir, ParticipationFlagDir,
|
|
|
|
RewardsAndPenaltiesDir, HistoricalSummariesUpdateDir])
|
2022-12-06 16:43:11 +00:00
|
|
|
|
|
|
|
template runSuite(
|
|
|
|
suiteDir, testName: string, transitionProc: untyped): untyped =
|
2023-02-14 13:32:43 +00:00
|
|
|
suite "EF - Deneb - Epoch Processing - " & testName & preset():
|
2022-12-06 16:43:11 +00:00
|
|
|
for testDir in walkDirRec(
|
|
|
|
suiteDir / "pyspec_tests", yieldFilter = {pcDir}, checkDir = true):
|
|
|
|
let unitTestName = testDir.rsplit(DirSep, 1)[1]
|
|
|
|
test testName & " - " & unitTestName & preset():
|
|
|
|
# BeaconState objects are stored on the heap to avoid stack overflow
|
2023-02-21 12:58:08 +00:00
|
|
|
type T = deneb.BeaconState
|
2022-12-06 16:43:11 +00:00
|
|
|
let preState {.inject.} = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, T))
|
|
|
|
var cache {.inject, used.} = StateCache()
|
|
|
|
template state: untyped {.inject, used.} = preState[]
|
|
|
|
template cfg: untyped {.inject, used.} = defaultRuntimeConfig
|
|
|
|
|
|
|
|
if transitionProc.isOk:
|
|
|
|
let postState =
|
|
|
|
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, T))
|
|
|
|
check: hash_tree_root(preState[]) == hash_tree_root(postState[])
|
|
|
|
reportDiff(preState, postState)
|
|
|
|
else:
|
|
|
|
check: not fileExists(testDir/"post.ssz_snappy")
|
|
|
|
|
|
|
|
# Justification & Finalization
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
runSuite(JustificationFinalizationDir, "Justification & Finalization"):
|
|
|
|
let info = altair.EpochInfo.init(state)
|
|
|
|
process_justification_and_finalization(state, info.balances)
|
|
|
|
Result[void, cstring].ok()
|
|
|
|
|
|
|
|
# Inactivity updates
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
runSuite(InactivityDir, "Inactivity"):
|
|
|
|
let info = altair.EpochInfo.init(state)
|
|
|
|
process_inactivity_updates(cfg, state, info)
|
|
|
|
Result[void, cstring].ok()
|
|
|
|
|
|
|
|
# Rewards & Penalties
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
runSuite(RewardsAndPenaltiesDir, "Rewards and penalties"):
|
|
|
|
var info = altair.EpochInfo.init(state)
|
|
|
|
process_rewards_and_penalties(cfg, state, info)
|
|
|
|
Result[void, cstring].ok()
|
|
|
|
|
|
|
|
# rest in test_fixture_rewards
|
|
|
|
|
|
|
|
# Registry updates
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
runSuite(RegistryUpdatesDir, "Registry updates"):
|
|
|
|
process_registry_updates(cfg, state, cache)
|
|
|
|
|
|
|
|
# Slashings
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
runSuite(SlashingsDir, "Slashings"):
|
|
|
|
let info = altair.EpochInfo.init(state)
|
|
|
|
process_slashings(state, info.balances.current_epoch)
|
|
|
|
Result[void, cstring].ok()
|
|
|
|
|
|
|
|
# Eth1 data reset
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
runSuite(Eth1DataResetDir, "Eth1 data reset"):
|
|
|
|
process_eth1_data_reset(state)
|
|
|
|
Result[void, cstring].ok()
|
|
|
|
|
|
|
|
# Effective balance updates
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
runSuite(EffectiveBalanceUpdatesDir, "Effective balance updates"):
|
|
|
|
process_effective_balance_updates(state)
|
|
|
|
Result[void, cstring].ok()
|
|
|
|
|
|
|
|
# Slashings reset
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
runSuite(SlashingsResetDir, "Slashings reset"):
|
|
|
|
process_slashings_reset(state)
|
|
|
|
Result[void, cstring].ok()
|
|
|
|
|
|
|
|
# RANDAO mixes reset
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
runSuite(RandaoMixesResetDir, "RANDAO mixes reset"):
|
|
|
|
process_randao_mixes_reset(state)
|
|
|
|
Result[void, cstring].ok()
|
|
|
|
|
|
|
|
# Historical roots update
|
|
|
|
# ---------------------------------------------------------------
|
2023-01-09 14:15:43 +00:00
|
|
|
runSuite(HistoricalSummariesUpdateDir, "Historical summaries update"):
|
|
|
|
process_historical_summaries_update(state)
|
2022-12-06 16:43:11 +00:00
|
|
|
|
|
|
|
# Participation flag updates
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
runSuite(ParticipationFlagDir, "Participation flag updates"):
|
|
|
|
process_participation_flag_updates(state)
|
|
|
|
Result[void, cstring].ok()
|
|
|
|
|
|
|
|
# Sync committee updates
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
|
|
|
# These are only for minimal, not mainnet
|
|
|
|
when const_preset == "minimal":
|
|
|
|
runSuite(SyncCommitteeDir, "Sync committee updates"):
|
|
|
|
process_sync_committee_updates(state)
|
|
|
|
Result[void, cstring].ok()
|
|
|
|
else:
|
|
|
|
doAssert not dirExists(SyncCommitteeDir)
|