2022-07-23 05:54:01 +00:00
|
|
|
# beacon_chain
|
2023-01-29 03:34:26 +00:00
|
|
|
# Copyright (c) 2022-2023 Status Research & Development GmbH
|
2022-07-23 05:54:01 +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
|
2023-02-10 20:59:38 +00:00
|
|
|
std/[algorithm, streams],
|
2022-07-23 05:54:01 +00:00
|
|
|
# Status libraries
|
|
|
|
stew/base10,
|
|
|
|
# Third-party
|
|
|
|
yaml,
|
|
|
|
# Beacon chain internals
|
|
|
|
../../../beacon_chain/spec/helpers,
|
|
|
|
# Test utilities
|
|
|
|
../testutil,
|
2023-02-10 20:59:38 +00:00
|
|
|
./fixtures_utils, ./os_ops
|
2022-07-23 05:54:01 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
TestMeta = object
|
|
|
|
updates_count: uint64
|
|
|
|
|
2023-01-29 03:34:26 +00:00
|
|
|
proc runTest(path: string, lcDataFork: static LightClientDataFork) =
|
2022-07-23 05:54:01 +00:00
|
|
|
test "Light client - Update ranking - " & path.relativePath(SszTestsDir):
|
|
|
|
let meta = block:
|
|
|
|
var s = openFileStream(path/"meta.yaml")
|
|
|
|
defer: close(s)
|
|
|
|
var res: TestMeta
|
|
|
|
yaml.load(s, res)
|
|
|
|
res
|
|
|
|
|
2023-01-29 03:34:26 +00:00
|
|
|
var updates = newSeqOfCap[lcDataFork.LightClientUpdate](meta.updates_count)
|
2022-07-23 05:54:01 +00:00
|
|
|
for i in 0 ..< meta.updates_count:
|
|
|
|
updates.add parseTest(
|
|
|
|
path/"updates_" & Base10.toString(i) & ".ssz_snappy",
|
2023-01-29 03:34:26 +00:00
|
|
|
SSZ, lcDataFork.LightClientUpdate)
|
2022-07-23 05:54:01 +00:00
|
|
|
|
2023-01-29 03:34:26 +00:00
|
|
|
proc cmp(a, b: lcDataFork.LightClientUpdate): int =
|
2022-07-23 05:54:01 +00:00
|
|
|
if a.is_better_update(b):
|
|
|
|
check: not b.is_better_update(a)
|
|
|
|
-1
|
|
|
|
elif b.is_better_update(a):
|
|
|
|
1
|
|
|
|
else:
|
|
|
|
0
|
|
|
|
check: updates.isSorted(cmp)
|
|
|
|
|
|
|
|
suite "EF - Light client - Update ranking" & preset():
|
|
|
|
const presetPath = SszTestsDir/const_preset
|
|
|
|
for kind, path in walkDir(presetPath, relative = true, checkDir = true):
|
2023-01-29 03:34:26 +00:00
|
|
|
let testsPath =
|
2022-07-23 05:54:01 +00:00
|
|
|
presetPath/path/"light_client"/"update_ranking"/"pyspec_tests"
|
2023-01-29 03:34:26 +00:00
|
|
|
if kind != pcDir or not dirExists(testsPath):
|
|
|
|
continue
|
|
|
|
let fork = forkForPathComponent(path).valueOr:
|
|
|
|
test "Light client - Update ranking - " & path:
|
|
|
|
skip()
|
2022-07-23 05:54:01 +00:00
|
|
|
continue
|
2023-01-29 03:34:26 +00:00
|
|
|
for kind, path in walkDir(testsPath, relative = true, checkDir = true):
|
2023-03-11 14:39:29 +00:00
|
|
|
withConsensusFork(fork):
|
2023-03-11 20:09:21 +00:00
|
|
|
const lcDataFork = lcDataForkAtConsensusFork(consensusFork)
|
2023-01-29 03:34:26 +00:00
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
runTest(testsPath/path, lcDataFork)
|
|
|
|
else: raiseAssert "Unreachable"
|