2021-09-27 14:22:58 +00:00
|
|
|
# beacon_chain
|
2022-01-05 08:42:56 +00:00
|
|
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
2021-09-27 14:22:58 +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
|
|
|
|
# Standard library
|
2022-05-25 13:49:29 +00:00
|
|
|
std/[os, strutils],
|
2021-09-27 14:22:58 +00:00
|
|
|
# Beacon chain internals
|
2021-10-12 11:36:52 +00:00
|
|
|
../../../beacon_chain/spec/[beaconstate, presets, state_transition_epoch],
|
2022-01-12 14:50:30 +00:00
|
|
|
../../../beacon_chain/spec/datatypes/[altair, bellatrix],
|
2021-09-27 14:22:58 +00:00
|
|
|
# Test utilities
|
|
|
|
../../testutil,
|
|
|
|
../fixtures_utils,
|
2021-10-18 14:54:17 +00:00
|
|
|
./test_fixture_rewards,
|
2021-09-27 14:22:58 +00:00
|
|
|
../../helpers/debug_state
|
|
|
|
|
2022-01-03 17:43:00 +00:00
|
|
|
const RootDir = SszTestsDir/const_preset/"bellatrix"/"epoch_processing"
|
2021-10-13 14:24:36 +00:00
|
|
|
|
2021-09-27 14:22:58 +00:00
|
|
|
template runSuite(
|
2021-10-13 14:24:36 +00:00
|
|
|
suiteDir, testName: string, transitionProc: untyped): untyped =
|
2022-01-05 08:42:56 +00:00
|
|
|
suite "EF - Bellatrix - Epoch Processing - " & testName & preset():
|
2021-09-27 14:22:58 +00:00
|
|
|
for testDir in walkDirRec(suiteDir, 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
|
2022-01-12 14:50:30 +00:00
|
|
|
type T = bellatrix.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()
|
|
|
|
template state: untyped {.inject, used.} = preState[]
|
|
|
|
template cfg: untyped {.inject, used.} = defaultRuntimeConfig
|
|
|
|
|
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")
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
# Justification & Finalization
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
const JustificationFinalizationDir = RootDir/"justification_and_finalization"/"pyspec_tests"
|
|
|
|
runSuite(JustificationFinalizationDir, "Justification & Finalization"):
|
|
|
|
let info = altair.EpochInfo.init(state)
|
|
|
|
process_justification_and_finalization(state, info.balances)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
# Inactivity updates
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
const InactivityDir = RootDir/"inactivity_updates"/"pyspec_tests"
|
|
|
|
runSuite(InactivityDir, "Inactivity"):
|
|
|
|
let info = altair.EpochInfo.init(state)
|
|
|
|
process_inactivity_updates(cfg, state, info)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
# Rewards & Penalties
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
|
|
|
# in test_fixture_rewards
|
|
|
|
|
|
|
|
# Registry updates
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
const RegistryUpdatesDir = RootDir/"registry_updates"/"pyspec_tests"
|
|
|
|
runSuite(RegistryUpdatesDir, "Registry updates"):
|
|
|
|
process_registry_updates(cfg, state, cache)
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
# Slashings
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
const SlashingsDir = RootDir/"slashings"/"pyspec_tests"
|
|
|
|
runSuite(SlashingsDir, "Slashings"):
|
|
|
|
let info = altair.EpochInfo.init(state)
|
|
|
|
process_slashings(state, info.balances.current_epoch)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
# Eth1 data reset
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
const Eth1DataResetDir = RootDir/"eth1_data_reset/"/"pyspec_tests"
|
|
|
|
runSuite(Eth1DataResetDir, "Eth1 data reset"):
|
|
|
|
process_eth1_data_reset(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
# Effective balance updates
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
const EffectiveBalanceUpdatesDir = RootDir/"effective_balance_updates"/"pyspec_tests"
|
|
|
|
runSuite(EffectiveBalanceUpdatesDir, "Effective balance updates"):
|
|
|
|
process_effective_balance_updates(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
# Slashings reset
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
const SlashingsResetDir = RootDir/"slashings_reset"/"pyspec_tests"
|
|
|
|
runSuite(SlashingsResetDir, "Slashings reset"):
|
|
|
|
process_slashings_reset(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
# RANDAO mixes reset
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
const RandaoMixesResetDir = RootDir/"randao_mixes_reset"/"pyspec_tests"
|
|
|
|
runSuite(RandaoMixesResetDir, "RANDAO mixes reset"):
|
|
|
|
process_randao_mixes_reset(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
# Historical roots update
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
const HistoricalRootsUpdateDir = RootDir/"historical_roots_update"/"pyspec_tests"
|
|
|
|
runSuite(HistoricalRootsUpdateDir, "Historical roots update"):
|
|
|
|
process_historical_roots_update(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
# Participation flag updates
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
const ParticipationFlagDir = RootDir/"participation_flag_updates"/"pyspec_tests"
|
|
|
|
runSuite(ParticipationFlagDir, "Participation flag updates"):
|
|
|
|
process_participation_flag_updates(state)
|
2022-05-25 13:49:29 +00:00
|
|
|
Result[void, cstring].ok()
|
2021-09-27 14:22:58 +00:00
|
|
|
|
|
|
|
# Sync committee updates
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2022-05-25 13:49:29 +00:00
|
|
|
# These are only for minimal, not mainnet
|
2021-10-13 14:24:36 +00:00
|
|
|
const SyncCommitteeDir = RootDir/"sync_committee_updates"/"pyspec_tests"
|
2022-05-25 13:49:29 +00:00
|
|
|
when const_preset == "minimal":
|
|
|
|
runSuite(SyncCommitteeDir, "Sync committee updates"):
|
|
|
|
process_sync_committee_updates(state)
|
|
|
|
Result[void, cstring].ok()
|
|
|
|
else:
|
|
|
|
doAssert not dirExists(SyncCommitteeDir)
|