2019-09-03 03:12:09 +00:00
|
|
|
# beacon_chain
|
2024-02-29 13:24:08 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2019-09-03 03:12:09 +00:00
|
|
|
# Licensed and distributed under either of
|
2019-11-25 15:30:02 +00:00
|
|
|
# * 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).
|
2019-09-03 03:12:09 +00:00
|
|
|
# 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: [].}
|
2019-11-14 10:47:55 +00:00
|
|
|
{.used.}
|
|
|
|
|
2019-09-03 03:12:09 +00:00
|
|
|
import
|
|
|
|
# Beacon chain internals
|
2021-10-13 14:24:36 +00:00
|
|
|
chronicles,
|
2021-05-28 20:32:26 +00:00
|
|
|
../../../beacon_chain/spec/state_transition_epoch,
|
|
|
|
../../../beacon_chain/spec/datatypes/phase0,
|
2019-09-03 03:12:09 +00:00
|
|
|
# Test utilities
|
2021-05-28 20:32:26 +00:00
|
|
|
../../testutil,
|
2023-02-10 20:59:38 +00:00
|
|
|
../fixtures_utils, ../os_ops,
|
2021-10-18 14:54:17 +00:00
|
|
|
./test_fixture_rewards,
|
2021-05-28 20:32:26 +00:00
|
|
|
../../helpers/debug_state
|
2019-09-03 03:12:09 +00:00
|
|
|
|
2022-10-28 08:02:33 +00:00
|
|
|
from std/sequtils import mapIt, toSeq
|
|
|
|
from std/strutils import rsplit
|
|
|
|
|
|
|
|
const
|
|
|
|
RootDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"
|
|
|
|
|
|
|
|
JustificationFinalizationDir = RootDir/"justification_and_finalization"
|
|
|
|
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"
|
|
|
|
HistoricalRootsUpdateDir = RootDir/"historical_roots_update"
|
|
|
|
RewardsAndPenaltiesDir = RootDir/"rewards_and_penalties"
|
|
|
|
ParticipationRecordsDir = RootDir/"participation_record_updates"
|
|
|
|
|
|
|
|
doAssert toHashSet(mapIt(toSeq(walkDir(RootDir, relative = false)), it.path)) ==
|
|
|
|
toHashSet([
|
|
|
|
JustificationFinalizationDir, RegistryUpdatesDir, SlashingsDir,
|
|
|
|
Eth1DataResetDir, EffectiveBalanceUpdatesDir, SlashingsResetDir,
|
|
|
|
RandaoMixesResetDir, HistoricalRootsUpdateDir, ParticipationRecordsDir,
|
|
|
|
RewardsAndPenaltiesDir])
|
2021-10-13 14:24:36 +00:00
|
|
|
|
|
|
|
template runSuite(suiteDir, testName: string, transitionProc: untyped): untyped =
|
2022-01-05 08:42:56 +00:00
|
|
|
suite "EF - Phase 0 - Epoch Processing - " & testName & preset():
|
2022-10-28 08:02:33 +00:00
|
|
|
for testDir in walkDirRec(
|
|
|
|
suiteDir / "pyspec_tests", yieldFilter = {pcDir}, checkDir = true):
|
2021-04-28 16:41:02 +00:00
|
|
|
|
|
|
|
let unitTestName = testDir.rsplit(DirSep, 1)[1]
|
|
|
|
test testName & " - " & unitTestName & preset():
|
|
|
|
# BeaconState objects are stored on the heap to avoid stack overflow
|
2021-08-12 13:08:20 +00:00
|
|
|
type T = phase0.BeaconState
|
2022-02-20 20:13:06 +00:00
|
|
|
let preState {.inject.} = newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, T))
|
2021-10-13 14:24:36 +00:00
|
|
|
var cache {.inject, used.} = StateCache()
|
2023-02-24 19:50:46 +00:00
|
|
|
var info {.inject.}: phase0.EpochInfo
|
2021-10-13 14:24:36 +00:00
|
|
|
template state: untyped {.inject, used.} = preState[]
|
|
|
|
template cfg: untyped {.inject, used.} = defaultRuntimeConfig
|
|
|
|
init(info, preState[])
|
|
|
|
|
2022-05-25 13:49:29 +00:00
|
|
|
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")
|
2019-09-03 03:12:09 +00:00
|
|
|
|
|
|
|
# Justification & Finalization
|
|
|
|
# ---------------------------------------------------------------
|
2021-10-13 14:24:36 +00:00
|
|
|
runSuite(JustificationFinalizationDir, "Justification & Finalization"):
|
|
|
|
info.process_attestations(state, cache)
|
2021-11-25 12:20:36 +00:00
|
|
|
process_justification_and_finalization(state, info.balances)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2019-09-03 03:12:09 +00:00
|
|
|
|
|
|
|
# Rewards & Penalties
|
|
|
|
# ---------------------------------------------------------------
|
2022-10-28 08:02:33 +00:00
|
|
|
runSuite(RewardsAndPenaltiesDir, "Rewards and penalties"):
|
|
|
|
var info: phase0.EpochInfo
|
|
|
|
var cache: StateCache
|
|
|
|
info.init(state)
|
|
|
|
info.process_attestations(state, cache)
|
|
|
|
process_rewards_and_penalties(state, info)
|
|
|
|
Result[void, cstring].ok()
|
2019-09-03 03:12:09 +00:00
|
|
|
|
2022-10-28 08:02:33 +00:00
|
|
|
# rest in test_fixture_rewards
|
2019-09-03 03:12:09 +00:00
|
|
|
|
|
|
|
# Registry updates
|
|
|
|
# ---------------------------------------------------------------
|
2021-10-13 14:24:36 +00:00
|
|
|
runSuite(RegistryUpdatesDir, "Registry updates"):
|
|
|
|
process_registry_updates(cfg, state, cache)
|
2019-09-03 03:12:09 +00:00
|
|
|
|
|
|
|
# Slashings
|
|
|
|
# ---------------------------------------------------------------
|
2021-10-13 14:24:36 +00:00
|
|
|
runSuite(SlashingsDir, "Slashings"):
|
|
|
|
info.process_attestations(state, cache)
|
2021-11-25 12:20:36 +00:00
|
|
|
process_slashings(state, info.balances.current_epoch)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2019-09-03 03:12:09 +00:00
|
|
|
|
2019-09-05 10:27:26 +00:00
|
|
|
# Final updates
|
|
|
|
# ---------------------------------------------------------------
|
2021-10-13 14:24:36 +00:00
|
|
|
runSuite(Eth1DataResetDir, "Eth1 data reset"):
|
|
|
|
process_eth1_data_reset(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-05-24 08:42:40 +00:00
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
runSuite(EffectiveBalanceUpdatesDir, "Effective balance updates"):
|
|
|
|
process_effective_balance_updates(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-05-24 08:42:40 +00:00
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
runSuite(SlashingsResetDir, "Slashings reset"):
|
|
|
|
process_slashings_reset(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-05-24 08:42:40 +00:00
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
runSuite(RandaoMixesResetDir, "RANDAO mixes reset"):
|
|
|
|
process_randao_mixes_reset(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-05-24 08:42:40 +00:00
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
runSuite(HistoricalRootsUpdateDir, "Historical roots update"):
|
|
|
|
process_historical_roots_update(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-05-24 08:42:40 +00:00
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
runSuite(ParticipationRecordsDir, "Participation record updates"):
|
|
|
|
process_participation_record_updates(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|