Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve ssz tests consistency #6776

Merged
merged 2 commits into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions packages/beacon-node/test/spec/presets/ssz_static.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "node:fs";
import path from "node:path";
import {it, vi} from "vitest";
import {expect, it, vi} from "vitest";
import {Type} from "@chainsafe/ssz";
import {ssz} from "@lodestar/types";
import {ACTIVE_PRESET, ForkName, ForkLightClient, ForkExecution} from "@lodestar/params";
Expand Down Expand Up @@ -56,23 +56,26 @@ const sszStatic =
(ssz.bellatrix as Types)[typeName] ||
(ssz.altair as Types)[typeName] ||
(ssz.phase0 as Types)[typeName];
if (!sszType) {
throw Error(`No type for ${typeName}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this just result in strange errors downstream if we don't throw here and exit the test run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I updated so that when sszType is null, associated tests are not run at all; also improved the error message to be more meaningfull.
Compared to the original Error based approach, a missing SSZ type will not prevent further tests to be run (the Error would short-circuit the logic)

}

const sszTypeNoUint = replaceUintTypeWithUintBigintType(sszType);
if (!sszType) {
expect.fail(
`Missing SSZ type definition for ${typeName}; this will prevent associated ssz_static tests to be executed`
);
} else {
const sszTypeNoUint = replaceUintTypeWithUintBigintType(sszType);

for (const testCase of fs.readdirSync(testSuiteDirpath)) {
// Do not manually skip tests here, do it in packages/beacon-node/test/spec/presets/index.test.ts
it(testCase, function () {
// Mainnet must deal with big full states and hash each one multiple times
if (ACTIVE_PRESET === "mainnet") {
vi.setConfig({testTimeout: 30 * 1000});
}
for (const testCase of fs.readdirSync(testSuiteDirpath)) {
// Do not manually skip tests here, do it in packages/beacon-node/test/spec/presets/index.test.ts
it(testCase, function () {
// Mainnet must deal with big full states and hash each one multiple times
if (ACTIVE_PRESET === "mainnet") {
vi.setConfig({testTimeout: 30 * 1000});
}

const testData = parseSszStaticTestcase(path.join(testSuiteDirpath, testCase));
runValidSszTest(sszTypeNoUint, testData);
});
const testData = parseSszStaticTestcase(path.join(testSuiteDirpath, testCase));
runValidSszTest(sszTypeNoUint, testData);
});
}
}
};

Expand Down
Loading