Skip to content

Commit

Permalink
Merge d64cfd2 into 4cec93e
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech authored Feb 14, 2023
2 parents 4cec93e + d64cfd2 commit d238cdf
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 47 deletions.
41 changes: 10 additions & 31 deletions packages/beacon-node/test/spec/presets/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import path from "node:path";
import {ACTIVE_PRESET} from "@lodestar/params";
import {Type} from "@chainsafe/ssz";
import {ssz} from "@lodestar/types";

import {RunnerType} from "../utils/types.js";
import {SkipOpts, specTestIterator} from "../utils/specTestIterator.js";
Expand Down Expand Up @@ -31,37 +29,18 @@ import {transition} from "./transition.js";
// "eip4844/operations/bls_to_execution_change",
// ],
// ```
const skipOpts: SkipOpts = {};
const skipOpts: SkipOpts = {
// TODO: capella
// BeaconBlockBody proof in lightclient is the new addition in v1.3.0-rc.2-hotfix
// Skip them for now to enable subsequently
skippedPrefixes: [
"capella/light_client/single_merkle_proof/BeaconBlockBody",
"deneb/light_client/single_merkle_proof/BeaconBlockBody",
],
};

/* eslint-disable @typescript-eslint/naming-convention */

// TODO: capella
// Map all lightclient types to altair for addressing the specs
// which are are to be updated in separate PR
const overrideSSZTypes: Record<string, Record<string, Type<any>>> = {
deneb: {
LightClientHeader: ssz.altair.LightClientHeader,
LightClientUpdate: ssz.altair.LightClientUpdate,
LightClientOptimisticUpdate: ssz.altair.LightClientOptimisticUpdate,
LightClientFinalityUpdate: ssz.altair.LightClientFinalityUpdate,
LightClientBootstrap: ssz.altair.LightClientBootstrap,
},
capella: {
LightClientHeader: ssz.altair.LightClientHeader,
LightClientUpdate: ssz.altair.LightClientUpdate,
LightClientOptimisticUpdate: ssz.altair.LightClientOptimisticUpdate,
LightClientFinalityUpdate: ssz.altair.LightClientFinalityUpdate,
LightClientBootstrap: ssz.altair.LightClientBootstrap,
},
bellatrix: {
LightClientHeader: ssz.altair.LightClientHeader,
LightClientUpdate: ssz.altair.LightClientUpdate,
LightClientOptimisticUpdate: ssz.altair.LightClientOptimisticUpdate,
LightClientFinalityUpdate: ssz.altair.LightClientFinalityUpdate,
LightClientBootstrap: ssz.altair.LightClientBootstrap,
},
};

specTestIterator(
path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET),
{
Expand All @@ -87,7 +66,7 @@ specTestIterator(
shuffling: {type: RunnerType.default, fn: shuffling},
ssz_static: {
type: RunnerType.custom,
fn: sszStatic(undefined, overrideSSZTypes),
fn: sszStatic(),
},
sync: {type: RunnerType.default, fn: forkChoiceTest({onlyPredefinedResponses: true})},
transition: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function getObjectType(fork: ForkName, objectName: string): Type<unknown> {
switch (objectName) {
case "BeaconState":
return ssz[fork].BeaconState;
case "BeaconBlockBody":
return ssz[fork].BeaconBlockBody;
default:
throw Error(`Unknown objectName ${objectName}`);
}
Expand Down
22 changes: 15 additions & 7 deletions packages/beacon-node/test/spec/presets/light_client/sync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {expect} from "chai";
import {isForkLightClient} from "@lodestar/params";
import {altair, phase0, RootHex, Slot, ssz} from "@lodestar/types";
import {init} from "@chainsafe/bls/switchable";
import {InputType} from "@lodestar/spec-test-util";
Expand Down Expand Up @@ -31,7 +32,8 @@ type SyncTestCase = {
};

// Injected after parsing
updates: Map<string, altair.LightClientUpdate>;
// However updates are multifork and need config and step access to deserialize inside test
updates: Map<string, Uint8Array>;
};

type CheckHeader = {
Expand Down Expand Up @@ -73,7 +75,7 @@ type LightclientSyncSteps = ProcessUpdateStep | ForceUpdateStep;
const logger = testLogger("spec-test");
const UPDATE_FILE_NAME = "^(update)_([0-9a-zA-Z_]+)$";

export const sync: TestRunnerFn<SyncTestCase, void> = () => {
export const sync: TestRunnerFn<SyncTestCase, void> = (fork) => {
return {
testFunction: async (testcase) => {
await init("blst-native");
Expand Down Expand Up @@ -125,11 +127,14 @@ export const sync: TestRunnerFn<SyncTestCase, void> = () => {
const currentSlot = Number(step.process_update.current_slot as bigint);
logger.debug(`Step ${i}/${stepsLen} process_update`, renderSlot(currentSlot));

const update = testcase.updates.get(step.process_update.update);
if (!update) {
const updateBytes = testcase.updates.get(step.process_update.update);
if (!updateBytes) {
throw Error(`update ${step.process_update.update} not found`);
}

const headerSlot = Number(step.process_update.checks.optimistic_header.slot);
const update = config.getLightClientForkTypes(headerSlot)["LightClientUpdate"].deserialize(updateBytes);

logger.debug(`LightclientUpdateSummary: ${JSON.stringify(toLightClientUpdateSummary(update))}`);

lightClient.onUpdate(currentSlot, update);
Expand Down Expand Up @@ -165,12 +170,15 @@ export const sync: TestRunnerFn<SyncTestCase, void> = () => {
config: InputType.YAML,
},
sszTypes: {
bootstrap: ssz.altair.LightClientBootstrap,
[UPDATE_FILE_NAME]: ssz.altair.LightClientUpdate,
bootstrap: isForkLightClient(fork)
? ssz.allForksLightClient[fork].LightClientBootstrap
: ssz.altair.LightClientBootstrap,
// The updates are multifork and need config and step info to be deserialized within the test
[UPDATE_FILE_NAME]: {typeName: "LightClientUpdate", deserialize: (bytes: Uint8Array) => bytes},
},
mapToTestCase: (t: Record<string, any>) => {
// t has input file name as key
const updates = new Map<string, altair.LightClientUpdate>();
const updates = new Map<string, Uint8Array>();
for (const key in t) {
const updateMatch = key.match(UPDATE_FILE_NAME);
if (updateMatch) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {expect} from "chai";
import {altair, ssz} from "@lodestar/types";
import {altair, ssz, allForks} from "@lodestar/types";
import {isForkLightClient} from "@lodestar/params";
import {InputType} from "@lodestar/spec-test-util";
import {isBetterUpdate, LightClientUpdateSummary, toLightClientUpdateSummary} from "@lodestar/light-client/spec";
import {TestRunnerFn} from "../../utils/types.js";
Expand All @@ -16,12 +17,12 @@ type UpdateRankingTestCase = {
// updates_<index>.ssz_snappy
const UPDATES_FILE_NAME = "^updates_([0-9]+)$";

export const updateRanking: TestRunnerFn<UpdateRankingTestCase, void> = () => {
export const updateRanking: TestRunnerFn<UpdateRankingTestCase, void> = (fork) => {
return {
testFunction: (testcase) => {
// Parse update files
const updatesCount = Number(testcase.meta.updates_count as bigint);
const updates: altair.LightClientUpdate[] = [];
const updates: allForks.LightClientUpdate[] = [];

for (let i = 0; i < updatesCount; i++) {
const update = ((testcase as unknown) as Record<string, altair.LightClientUpdate>)[`updates_${i}`];
Expand Down Expand Up @@ -52,7 +53,9 @@ newUpdate = ${renderUpdate(newUpdate)}
meta: InputType.YAML,
},
sszTypes: {
[UPDATES_FILE_NAME]: ssz.altair.LightClientUpdate,
[UPDATES_FILE_NAME]: isForkLightClient(fork)
? ssz.allForksLightClient[fork].LightClientUpdate
: ssz.altair.LightClientUpdate,
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
expectFunc: () => {},
Expand Down
8 changes: 5 additions & 3 deletions packages/beacon-node/test/spec/presets/ssz_static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from "node:fs";
import path from "node:path";
import {ssz} from "@lodestar/types";
import {Type} from "@chainsafe/ssz";
import {ACTIVE_PRESET, ForkName} from "@lodestar/params";
import {ACTIVE_PRESET, ForkName, ForkLightClient} from "@lodestar/params";
import {replaceUintTypeWithUintBigintType} from "../utils/replaceUintTypeWithUintBigintType.js";
import {parseSszStaticTestcase} from "../utils/sszTestCaseParser.js";
import {runValidSszTest} from "../utils/runValidSszTest.js";
Expand All @@ -26,7 +26,7 @@ type Types = Record<string, Type<any>>;
// tests / mainnet / altair / ssz_static / Validator / ssz_random / case_0/roots.yaml
//

export const sszStatic = (skippedTypes?: string[], overrideSSZTypes?: Record<string, Types>) => (
export const sszStatic = (skippedTypes?: string[]) => (
fork: ForkName,
typeName: string,
testSuite: string,
Expand All @@ -39,7 +39,9 @@ export const sszStatic = (skippedTypes?: string[], overrideSSZTypes?: Record<str

/* eslint-disable @typescript-eslint/strict-boolean-expressions */
const sszType =
(((overrideSSZTypes ?? {})[fork] ?? {}) as Types)[typeName] ||
// Since lightclient types are not updated/declared at all forks, this allForksLightClient
// will help us get the right type for lightclient objects
((ssz.allForksLightClient[fork as ForkLightClient] || {}) as Types)[typeName] ||
(ssz[fork] as Types)[typeName] ||
(ssz.capella as Types)[typeName] ||
(ssz.bellatrix as Types)[typeName] ||
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/spec/specTestVersioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {IDownloadTestsOptions} from "@lodestar/spec-test-util";
const __dirname = path.dirname(fileURLToPath(import.meta.url));

export const ethereumConsensusSpecsTests: IDownloadTestsOptions = {
specVersion: "v1.3.0-rc.1",
specVersion: "v1.3.0-rc.2-hotfix",
// Target directory is the host package root: 'packages/*/spec-tests'
outputDir: path.join(__dirname, "../../spec-tests"),
specTestsRepoUrl: "https://github.com/ethereum/consensus-spec-tests",
Expand Down
1 change: 1 addition & 0 deletions packages/params/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export {BeaconPreset} from "./interface.js";
export {
ForkName,
ForkSeq,
ForkLightClient,
ForkExecution,
ForkBlobs,
isForkExecution,
Expand Down
2 changes: 1 addition & 1 deletion packages/params/test/e2e/ensure-config-is-synced.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {loadConfigYaml} from "../yaml.js";
// Not e2e, but slow. Run with e2e tests

/** https://github.com/ethereum/consensus-specs/releases */
const specConfigCommit = "v1.3.0-alpha.2";
const specConfigCommit = "v1.3.0-rc.2";

describe("Ensure config is synced", function () {
this.timeout(60 * 1000);
Expand Down

0 comments on commit d238cdf

Please sign in to comment.