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,
|
2021-10-13 14:24:36 +00:00
|
|
|
chronicles,
|
2021-05-28 15:25:58 +00:00
|
|
|
# Beacon chain internals
|
2021-10-12 11:36:52 +00:00
|
|
|
../../../beacon_chain/spec/[beaconstate, state_transition_block],
|
2021-05-28 20:32:26 +00:00
|
|
|
../../../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
|
|
|
|
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) =
|
|
|
|
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:
|
|
|
|
var
|
2021-10-12 11:36:52 +00:00
|
|
|
cache = StateCache()
|
2021-05-28 15:25:58 +00:00
|
|
|
preState =
|
2021-08-12 13:08:20 +00:00
|
|
|
newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, altair.BeaconState))
|
2021-10-12 11:36:52 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
syncAggregate = parseTest(
|
|
|
|
testDir/"sync_aggregate.ssz_snappy", SSZ, SyncAggregate)
|
2021-10-13 14:24:36 +00:00
|
|
|
total_active_balance = get_total_active_balance(preState[], cache)
|
2021-10-12 11:36:52 +00:00
|
|
|
done = process_sync_aggregate(
|
2021-10-13 14:24:36 +00:00
|
|
|
preState[], syncAggregate, total_active_balance, cache)
|
2021-05-28 15:25:58 +00:00
|
|
|
|
|
|
|
if existsFile(testDir/"post.ssz_snappy"):
|
2021-10-12 11:36:52 +00:00
|
|
|
let postState =
|
|
|
|
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, altair.BeaconState))
|
|
|
|
|
|
|
|
check:
|
|
|
|
done.isOk()
|
|
|
|
preState[].hash_tree_root() == postState[].hash_tree_root()
|
2021-05-28 15:25:58 +00:00
|
|
|
reportDiff(preState, postState)
|
|
|
|
else:
|
2021-10-12 11:36:52 +00:00
|
|
|
check: done.isErr() # No post state = processing should fail
|
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)
|