Skip to content

Commit

Permalink
Merge 6d9a696 into 8edee10
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion authored Aug 25, 2021
2 parents 8edee10 + 6d9a696 commit 160170c
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 151 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ jobs:
# Run them in different steps to quickly identifying which command failed
# Otherwise just doing `yarn test:spec` you can't tell which specific suite failed
# many of the suites have identical names for minimal and mainnet
- name: Spec tests ssz
run: yarn test:ssz
- name: Spec tests general
run: yarn test:general
working-directory: packages/spec-test-runner
- name: Spec tests bls
run: yarn test:bls
Expand Down
8 changes: 3 additions & 5 deletions packages/spec-test-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
"check-types": "tsc --noEmit",
"download-test-cases": "node -r ts-node/register test/downloadTests.ts",
"check-tests": "mocha test/checkTests.test.ts",
"test:ssz-generic": "mocha 'test/spec/ssz/generic/index.test.ts'",
"test:ssz-minimal": "LODESTAR_PRESET=minimal mocha 'test/spec/ssz/**/*minimal.test.ts'",
"test:ssz-mainnet": "mocha 'test/spec/ssz/**/*mainnet.test.ts'",
"test:ssz": "yarn test:ssz-generic && yarn test:ssz-minimal && yarn test:ssz-mainnet",
"test:bls": "mocha 'test/spec/bls/**/*.test.ts'",
"test:spec": "yarn test:ssz && yarn test:bls && yarn test:spec-phase0 && yarn test:spec-altair",
"test:ssz-generic": "mocha 'test/spec/ssz/generic/index.test.ts'",
"test:spec-general": "yarn test:bls && yarn test:ssz-generic",
"test:spec": "yarn test:spec-general && yarn test:bls && yarn test:spec-phase0 && yarn test:spec-altair",
"test:spec-altair-minimal": "LODESTAR_PRESET=minimal mocha 'test/spec/altair/**/*.test.ts'",
"test:spec-altair-mainnet": "LODESTAR_PRESET=mainnet mocha 'test/spec/altair/**/*.test.ts'",
"test:spec-phase0-minimal": "LODESTAR_PRESET=minimal mocha 'test/spec/phase0/**/*.test.ts'",
Expand Down
3 changes: 0 additions & 3 deletions packages/spec-test-runner/test/checkTests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {SPEC_TEST_LOCATION} from "./utils/specTestCases";

// TEMP TEMP
const forksToIgnore = new Set(["merge"]);
const testsToIgnore = new Set(["ssz_static"]);

// This test ensures that we are covering all available spec tests.
// The directory structure is organized first by preset, then by fork.
Expand Down Expand Up @@ -89,8 +88,6 @@ describe("Check tests", () => {
// ├── shuffling
// └── ssz_static
for (const testGroup of fs.readdirSync(path.join(rootTestDir, testRelDir))) {
if (testsToIgnore.has(testGroup)) continue;

const testDir = path.join(lodestarTests, testRelDir, testGroup);
const testFile = testDir + ".test.ts";
if (existsDir(testDir)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
import fs from "fs";
import path from "path";
import {describeDirectorySpecTest, InputType, safeType} from "@chainsafe/lodestar-spec-test-util";
import {Bytes32, ssz} from "@chainsafe/lodestar-types";
import {join} from "path";
import {expect} from "chai";
import {CompositeType} from "@chainsafe/ssz";
import {IBaseSSZStaticTestCase} from "../type";
import {SPEC_TEST_LOCATION} from "../../../utils/specTestCases";
import {ForkName, PresetName} from "@chainsafe/lodestar-params";
import {CompositeType, ContainerType, Type} from "@chainsafe/ssz";
import {IBaseSSZStaticTestCase} from "../ssz/type";
import {SPEC_TEST_LOCATION} from "../../utils/specTestCases";
import {ACTIVE_PRESET, ForkName, PresetName} from "@chainsafe/lodestar-params";

/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, no-console */
/* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, no-console */

interface IResult {
root: Bytes32;
serialized: Uint8Array;
}
// eslint-disable-next-line
type Types = Record<string, Type<any>>;

export function testStaticPhase0(type: keyof typeof ssz["phase0"], preset: PresetName): void {
const sszType = safeType(ssz.phase0[type]) as CompositeType<any>;
testStatic(type, sszType, ForkName.phase0, preset);
}

type NewAltairTypes = {
fork: ForkName.altair;
type: keyof typeof ssz["altair"];
const extraTypes = {
Eth1Block: new ContainerType({
fields: {
timestamp: ssz.Number64,
depositRoot: ssz.Root,
depositCount: ssz.Number64,
},
}),
};

type AltairTypesFromPhase0 = {
fork: ForkName.phase0;
type: keyof typeof ssz["phase0"];
};
export function sszStatic(fork: ForkName): void {
const rootDir = path.join(SPEC_TEST_LOCATION, `tests/${ACTIVE_PRESET}/phase0/ssz_static`);
for (const typeName of fs.readdirSync(rootDir)) {
const type =
(ssz[fork] as Types)[typeName] ||
(ssz.altair as Types)[typeName] ||
(ssz.phase0 as Types)[typeName] ||
(extraTypes as Types)[typeName];
if (!type) {
throw Error(`No type for ${typeName}`);
}

export function testStaticAltair(typeWithFork: NewAltairTypes | AltairTypesFromPhase0, preset: PresetName): void {
let sszType: CompositeType<any> | undefined;
if (typeWithFork.fork === ForkName.phase0) {
sszType = safeType(ssz.phase0[typeWithFork.type]) as CompositeType<any>;
} else if (typeWithFork.fork === ForkName.altair) {
sszType = safeType(ssz.altair[typeWithFork.type]) as CompositeType<any>;
const sszType = safeType(type) as CompositeType<any>;
testStatic(typeName, sszType, fork, ACTIVE_PRESET);
}
if (!sszType) {
throw new Error(`Not found type for fork ${typeWithFork.fork} and type ${typeWithFork.type}`);
}
testStatic(typeWithFork.type, sszType, ForkName.altair, preset);
}

function testStatic(type: string, sszType: CompositeType<any>, forkName: ForkName, preset: PresetName): void {
const caseNames =
preset === PresetName.mainnet
? ["ssz_random"]
: ["ssz_lengthy", "ssz_max", "ssz_one", "ssz_nil", "ssz_random", "ssz_random_chaos", "ssz_zero"];
for (const caseName of caseNames) {
interface IResult {
root: Bytes32;
serialized: Uint8Array;
}

function testStatic(typeName: string, sszType: CompositeType<any>, forkName: ForkName, preset: PresetName): void {
const typeDir = path.join(SPEC_TEST_LOCATION, `tests/${preset}/${forkName}/ssz_static/${typeName}`);

for (const caseName of fs.readdirSync(typeDir)) {
describeDirectorySpecTest<IBaseSSZStaticTestCase<any>, IResult>(
`SSZ ${forkName} - ${type} ${caseName} ${preset}`,
join(SPEC_TEST_LOCATION, `tests/${preset}/${forkName}/ssz_static/${type}/${caseName}`),
`${preset}/${forkName}/ssz_static/${typeName}/${caseName}`,
path.join(typeDir, caseName),
(testcase) => {
//debugger;
const serialized = sszType.serialize(testcase.serialized);
Expand Down
4 changes: 4 additions & 0 deletions packages/spec-test-runner/test/spec/altair/ssz_static.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {ForkName} from "@chainsafe/lodestar-params";
import {sszStatic} from "../allForks/ssz_static";

sszStatic(ForkName.altair);
4 changes: 4 additions & 0 deletions packages/spec-test-runner/test/spec/phase0/ssz_static.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {ForkName} from "@chainsafe/lodestar-params";
import {sszStatic} from "../allForks/ssz_static";

sszStatic(ForkName.phase0);
52 changes: 0 additions & 52 deletions packages/spec-test-runner/test/spec/ssz/static/altair/altair.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

33 changes: 0 additions & 33 deletions packages/spec-test-runner/test/spec/ssz/static/phase0/phase0.ts

This file was deleted.

0 comments on commit 160170c

Please sign in to comment.