Files
lodestar/packages/beacon-node/test/e2e/api/impl/config.test.ts
Nico Flaig 598c1ec54e feat: update networking config to match CL spec (#8510)
**Motivation**

Conform to CL spec

**Description**

- move networking constants to config
- remove constants no longer part of spec
- enable "p2p-interface.md" in config test

Closes https://github.com/ChainSafe/lodestar/issues/6351
Closes https://github.com/ChainSafe/lodestar/issues/7529
2025-10-13 14:44:41 +01:00

69 lines
2.3 KiB
TypeScript

import {describe, it} from "vitest";
import {chainConfig} from "@lodestar/config/default";
import {ForkName, activePreset} from "@lodestar/params";
import {fetch} from "@lodestar/utils";
import {specConstants} from "../../../../src/api/impl/config/constants.js";
import {ethereumConsensusSpecsTests} from "../../../spec/specTestVersioning.js";
const CONSTANT_NAMES_SKIP_LIST = new Set([
// This constant is an array, so it's skipped due to not being just a string.
// This constant can also be derived from existing constants so it's not critical.
// PARTICIPATION_FLAG_WEIGHTS = [TIMELY_SOURCE_WEIGHT, TIMELY_TARGET_WEIGHT, TIMELY_HEAD_WEIGHT]
"PARTICIPATION_FLAG_WEIGHTS",
]);
describe("api / impl / config", () => {
it("Ensure all constants are exposed", async () => {
const constantNames = await downloadRemoteConstants(ethereumConsensusSpecsTests.specVersion);
const constantsInCode = new Set([
// Constants for API only
...Object.keys(specConstants),
// Full preset
...Object.keys(activePreset),
// Full config
...Object.keys(chainConfig),
]);
const missingConstants: string[] = [];
for (const constantName of constantNames) {
if (!constantsInCode.has(constantName) && !CONSTANT_NAMES_SKIP_LIST.has(constantName)) {
missingConstants.push(constantName);
}
}
if (missingConstants.length > 0) {
throw Error(
"Some constants declared in consensus-specs repo are not exposed in API:\n" + missingConstants.join("\n")
);
}
});
});
async function downloadRemoteConstants(commit: string): Promise<string[]> {
const downloadedSpecs: Promise<string>[] = [];
for (const forkName of Object.values(ForkName)) {
// If some future fork does not specify one of this docs, refactor to fetch some docs only on some forks
for (const docName of ["beacon-chain.md", "validator.md", "p2p-interface.md"]) {
downloadedSpecs.push(
fetch(`https://raw.githubusercontent.com/ethereum/consensus-specs/${commit}/specs/${forkName}/${docName}`).then(
(res) => res.text()
)
);
}
}
const constantNames: string[] = [];
for (const spec of await Promise.all(downloadedSpecs)) {
const matches = spec.matchAll(/\|\s`*([A-Z_]+)`\s+\|/g);
for (const match of matches) {
constantNames.push(match[1]);
}
}
return constantNames;
}