2021-05-28 15:25:58 +00:00
|
|
|
# beacon_chain
|
2021-09-30 16:28:02 +00:00
|
|
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
2021-05-28 15:25: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
|
|
|
|
os,
|
|
|
|
# Utilities
|
|
|
|
stew/results,
|
|
|
|
# Beacon chain internals
|
2021-05-28 20:32:26 +00:00
|
|
|
../../../beacon_chain/spec/state_transition_block,
|
|
|
|
../../../beacon_chain/spec/datatypes/altair,
|
2021-05-28 15:25:58 +00:00
|
|
|
# Test utilities
|
2021-05-28 20:32:26 +00:00
|
|
|
../../testutil,
|
|
|
|
../fixtures_utils,
|
|
|
|
../../helpers/debug_state
|
2021-05-28 15:25:58 +00:00
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
import chronicles # or some random compile error happens...
|
|
|
|
|
2021-06-14 17:42:46 +00:00
|
|
|
const OpSyncAggregateDir = SszTestsDir/const_preset/"altair"/"operations"/"sync_aggregate"/"pyspec_tests"
|
2021-05-28 15:25:58 +00:00
|
|
|
|
2021-06-14 17:42:46 +00:00
|
|
|
proc runTest(dir, identifier: string) =
|
2021-05-28 15:25:58 +00:00
|
|
|
# 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
|
|
|
|
|
2021-06-14 17:42:46 +00:00
|
|
|
let testDir = dir / identifier
|
2021-05-28 15:25:58 +00:00
|
|
|
|
|
|
|
proc `testImpl_sync_committee _ identifier`() =
|
|
|
|
|
2021-09-27 14:22:58 +00:00
|
|
|
let prefix =
|
|
|
|
if existsFile(testDir/"post.ssz_snappy"):
|
|
|
|
"[Valid] "
|
|
|
|
else:
|
|
|
|
"[Invalid] "
|
2021-05-28 15:25:58 +00:00
|
|
|
|
|
|
|
test prefix & identifier:
|
|
|
|
let syncAggregate = parseTest(
|
|
|
|
testDir/"sync_aggregate.ssz_snappy", SSZ, SyncAggregate)
|
|
|
|
var
|
|
|
|
preState =
|
2021-08-12 13:08:20 +00:00
|
|
|
newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState))
|
2021-05-28 15:25:58 +00:00
|
|
|
cache = StateCache()
|
|
|
|
|
|
|
|
if existsFile(testDir/"post.ssz_snappy"):
|
|
|
|
let
|
|
|
|
postState =
|
2021-08-12 13:08:20 +00:00
|
|
|
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState))
|
2021-06-14 17:42:46 +00:00
|
|
|
done = process_sync_aggregate(
|
2021-05-28 15:25:58 +00:00
|
|
|
preState[], syncAggregate, cache).isOk
|
|
|
|
doAssert done, "Valid sync aggregate not processed"
|
|
|
|
check: preState[].hash_tree_root() == postState[].hash_tree_root()
|
|
|
|
reportDiff(preState, postState)
|
|
|
|
else:
|
2021-06-14 17:42:46 +00:00
|
|
|
let done = process_sync_aggregate(preState[], syncAggregate, cache).isOk
|
2021-07-27 14:04:41 +00:00
|
|
|
doAssert done == false, "We didn't expect this invalid sync aggregate to be processed."
|
2021-05-28 15:25:58 +00:00
|
|
|
|
|
|
|
`testImpl_sync_committee _ identifier`()
|
|
|
|
|
2021-08-27 06:30:30 +00:00
|
|
|
suite "Ethereum Foundation - Altair - Operations - Sync Aggregate" & preset():
|
2021-07-02 17:33:59 +00:00
|
|
|
for kind, path in walkDir(
|
|
|
|
OpSyncAggregateDir, relative = true, checkDir = true):
|
2021-06-14 17:42:46 +00:00
|
|
|
runTest(OpSyncAggregateDir, path)
|