2022-07-23 05:54:01 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2022-2024 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.
|
|
|
|
|
2024-02-29 10:28:32 +00:00
|
|
|
{.push raises: [].}
|
2022-07-23 05:54:01 +00:00
|
|
|
{.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
|
2023-09-06 08:17:59 +00:00
|
|
|
../../beacon_chain/spec/helpers,
|
2022-07-23 05:54:01 +00:00
|
|
|
# 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-09-04 13:05:11 +00:00
|
|
|
proc runTest(suiteName, path: string, lcDataFork: static LightClientDataFork) =
|
2024-02-29 10:28:32 +00:00
|
|
|
let relativePathComponent = path.relativeTestPathComponent()
|
|
|
|
test "Light client - Update ranking - " & relativePathComponent:
|
2022-07-23 05:54:01 +00:00
|
|
|
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:
|
2023-09-04 13:05:11 +00:00
|
|
|
runTest(suiteName, testsPath/path, lcDataFork)
|
2023-01-29 03:34:26 +00:00
|
|
|
else: raiseAssert "Unreachable"
|