1+ import fs from "node:fs" ;
12import path from "node:path" ;
3+ import { expect , it } from "vitest" ;
24import { config } from "@lodestar/config/default" ;
35import { ACTIVE_PRESET } from "@lodestar/params" ;
4- import { InputType } from "@lodestar/spec-test-util" ;
5- import { bigIntToBytes } from "@lodestar/utils" ;
6+ import { bigIntToBytes , loadYaml } from "@lodestar/utils" ;
67import { computeColumnsForCustodyGroup , getCustodyGroups } from "../../../src/util/dataColumns.js" ;
78import { ethereumConsensusSpecsTests } from "../specTestVersioning.js" ;
8- import { specTestIterator } from "../utils/specTestIterator.js" ;
9- import { RunnerType , TestRunnerFn } from "../utils/types.js" ;
9+ import { isGossipValidationHandler , runGossipValidationTest } from "../utils/gossipValidation.js" ;
10+ import { readdirSyncSpec , specTestIterator } from "../utils/specTestIterator.js" ;
11+ import { RunnerType , TestRunnerCustom } from "../utils/types.js" ;
1012
1113type ComputeColumnForCustodyGroupInput = {
1214 custody_group : number ;
@@ -28,30 +30,50 @@ const networkingFns: Record<string, NetworkFn> = {
2830 } ,
2931} ;
3032
31- const networking : TestRunnerFn < NetworkingTestCase , unknown > = ( _fork , testName ) => {
32- return {
33- testFunction : ( testcase ) => {
34- const networkingFn = networkingFns [ testName ] ;
35- if ( networkingFn === undefined ) {
36- throw Error ( `No networkingFn for ${ testName } ` ) ;
37- }
38-
39- return networkingFn ( testcase . meta ) ;
40- } ,
41- options : {
42- inputTypes : { meta : InputType . YAML } ,
43- getExpected : ( testCase ) => testCase . meta . result . map ( Number ) ,
44- // Do not manually skip tests here, do it in packages/beacon-node/test/spec/presets/index.test.ts
45- } ,
46- } ;
47- } ;
48-
4933type NetworkingTestCase = {
5034 meta : {
5135 result : number [ ] ;
5236 } ;
5337} ;
5438
39+ function loadNetworkingTestMeta ( testCaseDir : string ) : NetworkingTestCase [ "meta" ] {
40+ return loadYaml < NetworkingTestCase [ "meta" ] > ( fs . readFileSync ( path . join ( testCaseDir , "meta.yaml" ) , "utf8" ) ) ;
41+ }
42+
43+ function runNetworkingFnTests ( testHandler : string , testSuite : string , testSuiteDirpath : string ) : void {
44+ const networkingFn = networkingFns [ testHandler ] ;
45+ if ( networkingFn === undefined ) {
46+ throw Error ( `No networkingFn for ${ testHandler } ` ) ;
47+ }
48+
49+ for ( const testCaseName of readdirSyncSpec ( testSuiteDirpath ) ) {
50+ const testCaseDir = path . join ( testSuiteDirpath , testCaseName ) ;
51+ it ( testCaseName , ( ) => {
52+ const meta = loadNetworkingTestMeta ( testCaseDir ) ;
53+ const actual = networkingFn ( meta ) ;
54+ expect ( actual ) . toEqualWithMessage (
55+ meta . result . map ( Number ) ,
56+ `Unexpected networking result for ${ testHandler } /${ testSuite } /${ testCaseName } `
57+ ) ;
58+ } ) ;
59+ }
60+ }
61+
62+ const networking : TestRunnerCustom = ( fork , testHandler , testSuite , testSuiteDirpath ) => {
63+ if ( isGossipValidationHandler ( testHandler ) ) {
64+ for ( const testCaseName of readdirSyncSpec ( testSuiteDirpath ) ) {
65+ const testCaseDir = path . join ( testSuiteDirpath , testCaseName ) ;
66+ it ( testCaseName , async ( ) => {
67+ await runGossipValidationTest ( fork , testHandler , testCaseDir ) ;
68+ } , 30_000 ) ;
69+ }
70+ } else if ( networkingFns [ testHandler ] !== undefined ) {
71+ runNetworkingFnTests ( testHandler , testSuite , testSuiteDirpath ) ;
72+ } else {
73+ throw new Error ( `No runner for networking handler ${ testHandler } ` ) ;
74+ }
75+ } ;
76+
5577specTestIterator ( path . join ( ethereumConsensusSpecsTests . outputDir , "tests" , ACTIVE_PRESET ) , {
56- networking : { type : RunnerType . default , fn : networking } ,
78+ networking : { type : RunnerType . custom , fn : networking } ,
5779} ) ;
0 commit comments