2019-09-03 03:12:09 +00:00
|
|
|
# beacon_chain
|
|
|
|
# Copyright (c) 2018-Present Status Research & Development GmbH
|
|
|
|
# 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.
|
|
|
|
|
2019-11-14 10:47:55 +00:00
|
|
|
{.used.}
|
|
|
|
|
2019-09-03 03:12:09 +00:00
|
|
|
import
|
|
|
|
# Standard library
|
|
|
|
os, unittest, strutils,
|
|
|
|
# Beacon chain internals
|
2020-07-15 10:44:18 +00:00
|
|
|
../../beacon_chain/spec/[datatypes, state_transition_epoch],
|
2019-09-03 03:12:09 +00:00
|
|
|
# Test utilities
|
|
|
|
../testutil,
|
2019-09-03 18:02:21 +00:00
|
|
|
./fixtures_utils,
|
2020-08-17 01:09:27 +00:00
|
|
|
./test_fixture_rewards,
|
2019-09-03 18:02:21 +00:00
|
|
|
../helpers/debug_state
|
2019-09-03 03:12:09 +00:00
|
|
|
|
|
|
|
from ../../beacon_chain/spec/beaconstate import process_registry_updates
|
|
|
|
# XXX: move to state_transition_epoch?
|
|
|
|
|
|
|
|
template runSuite(suiteDir, testName: string, transitionProc: untyped{ident}, useCache: static bool): untyped =
|
|
|
|
# We wrap the tests in a proc to avoid running out of globals
|
|
|
|
# in the future: Nim supports up to 3500 globals
|
|
|
|
# but unittest with the macro/templates put everything as globals
|
|
|
|
# https://github.com/nim-lang/Nim/issues/12084#issue-486866402
|
|
|
|
|
|
|
|
proc `suiteImpl _ transitionProc`() =
|
2020-03-10 04:00:19 +00:00
|
|
|
suiteReport "Official - Epoch Processing - " & testName & preset():
|
2020-11-13 21:16:56 +00:00
|
|
|
doAssert dirExists(suiteDir)
|
2019-09-03 03:12:09 +00:00
|
|
|
for testDir in walkDirRec(suiteDir, yieldFilter = {pcDir}):
|
|
|
|
|
|
|
|
let unitTestName = testDir.rsplit(DirSep, 1)[1]
|
2019-12-05 10:27:00 +00:00
|
|
|
timedTest testName & " - " & unitTestName & preset():
|
2020-11-10 18:41:04 +00:00
|
|
|
# BeaconState objects are stored on the heap to avoid stack overflow
|
2020-04-29 20:12:07 +00:00
|
|
|
var preState = newClone(parseTest(testDir/"pre.ssz", SSZ, BeaconState))
|
|
|
|
let postState = newClone(parseTest(testDir/"post.ssz", SSZ, BeaconState))
|
2019-09-03 03:12:09 +00:00
|
|
|
|
|
|
|
when useCache:
|
2020-07-15 10:44:18 +00:00
|
|
|
var cache = StateCache()
|
2020-04-23 18:58:54 +00:00
|
|
|
transitionProc(preState[], cache)
|
2019-09-03 03:12:09 +00:00
|
|
|
else:
|
2020-04-23 18:58:54 +00:00
|
|
|
transitionProc(preState[])
|
2019-09-03 03:12:09 +00:00
|
|
|
|
2020-04-22 23:35:55 +00:00
|
|
|
reportDiff(preState, postState)
|
2019-09-03 03:12:09 +00:00
|
|
|
|
|
|
|
`suiteImpl _ transitionProc`()
|
|
|
|
|
|
|
|
# Justification & Finalization
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
|
|
|
const JustificationFinalizationDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"/"justification_and_finalization"/"pyspec_tests"
|
2020-10-22 11:08:46 +00:00
|
|
|
runSuite(JustificationFinalizationDir, "Justification & Finalization", process_justification_and_finalization, useCache = false)
|
2019-09-03 03:12:09 +00:00
|
|
|
|
|
|
|
# Rewards & Penalties
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
2020-08-17 01:09:27 +00:00
|
|
|
# in test_fixture_rewards
|
2019-09-03 03:12:09 +00:00
|
|
|
|
|
|
|
# Registry updates
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
|
|
|
const RegistryUpdatesDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"/"registry_updates"/"pyspec_tests"
|
2020-06-03 05:42:08 +00:00
|
|
|
runSuite(RegistryUpdatesDir, "Registry updates", process_registry_updates, useCache = true)
|
2019-09-03 03:12:09 +00:00
|
|
|
|
|
|
|
# Slashings
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
|
|
|
const SlashingsDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"/"slashings"/"pyspec_tests"
|
2020-10-22 11:08:46 +00:00
|
|
|
runSuite(SlashingsDir, "Slashings", process_slashings, useCache = false)
|
2019-09-03 03:12:09 +00:00
|
|
|
|
2019-09-05 10:27:26 +00:00
|
|
|
# Final updates
|
|
|
|
# ---------------------------------------------------------------
|
2019-09-03 03:12:09 +00:00
|
|
|
|
2019-09-05 10:27:26 +00:00
|
|
|
const FinalUpdatesDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"/"final_updates"/"pyspec_tests"
|
|
|
|
runSuite(FinalUpdatesDir, "Final updates", process_final_updates, useCache = false)
|