2019-09-03 18:02:21 +00:00
|
|
|
# beacon_chain
|
|
|
|
# Copyright (c) 2018-Present Status Research & Development GmbH
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# 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 18:02:21 +00:00
|
|
|
import
|
|
|
|
# Standard library
|
2019-11-14 10:47:55 +00:00
|
|
|
os, unittest,
|
2019-09-03 18:02:21 +00:00
|
|
|
# Beacon chain internals
|
|
|
|
../../beacon_chain/spec/datatypes,
|
|
|
|
../../beacon_chain/state_transition,
|
|
|
|
# Test utilities
|
|
|
|
../testutil,
|
|
|
|
./fixtures_utils,
|
|
|
|
../helpers/debug_state
|
|
|
|
|
|
|
|
const SanitySlotsDir = SszTestsDir/const_preset/"phase0"/"sanity"/"slots"/"pyspec_tests"
|
|
|
|
|
|
|
|
template runTest(testName: string, identifier: untyped, num_slots: uint64): 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
|
|
|
|
|
|
|
|
const testDir = SanitySlotsDir / astToStr(identifier)
|
|
|
|
|
|
|
|
proc `testImpl _ slots _ identifier`() =
|
|
|
|
test "Slots - " & testName & " (" & astToStr(identifier) & ")":
|
|
|
|
var stateRef, postRef: ref BeaconState
|
|
|
|
new stateRef
|
|
|
|
new postRef
|
|
|
|
stateRef[] = parseTest(testDir/"pre.ssz", SSZ, BeaconState)
|
|
|
|
postRef[] = parseTest(testDir/"post.ssz", SSZ, BeaconState)
|
|
|
|
|
|
|
|
process_slots(stateRef[], stateRef.slot + num_slots)
|
|
|
|
# check: stateRef.hash_tree_root() == postRef.hash_tree_root()
|
2019-11-08 10:30:22 +00:00
|
|
|
|
|
|
|
var sr_pre, sr_post: ref BeaconStateNew
|
|
|
|
new sr_pre
|
|
|
|
new sr_post
|
|
|
|
sr_pre[] = GetNewBeaconState(stateRef[])
|
|
|
|
sr_post[] = GetNewBeaconState(postRef[])
|
|
|
|
reportDiff(sr_pre, sr_post)
|
2019-09-03 18:02:21 +00:00
|
|
|
|
|
|
|
`testImpl _ slots _ identifier`()
|
|
|
|
|
|
|
|
# 1 slot
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
|
|
|
suite "Official - Sanity - Slots " & preset():
|
|
|
|
runTest("Advance 1 slot", slots_1, 1)
|
|
|
|
runTest("Advance 2 slots", slots_2, 2)
|
2019-09-12 21:28:33 +00:00
|
|
|
runTest("Advance an empty epoch", empty_epoch, SLOTS_PER_EPOCH)
|
2019-09-03 18:02:21 +00:00
|
|
|
|
2019-09-12 21:28:33 +00:00
|
|
|
const DoubleEpoch = SLOTS_PER_EPOCH.uint64*2 # workaround undeclared identifier "double_empty_epoch"
|
|
|
|
runTest("Advance 2 empty epochs", double_empty_epoch, DoubleEpoch)
|
2019-09-03 18:02:21 +00:00
|
|
|
|
2019-09-12 21:28:33 +00:00
|
|
|
# This starts in the middle of an epoch
|
|
|
|
runTest("Advance over an epoch boundary", over_epoch_boundary, SLOTS_PER_EPOCH)
|