From 7a34998c659ddfa5c8d437371404a2b656e6aeb1 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Tue, 14 May 2024 16:49:22 +0300 Subject: [PATCH 1/2] test: improve ssz tests consistency --- packages/beacon-node/test/spec/presets/ssz_static.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/beacon-node/test/spec/presets/ssz_static.test.ts b/packages/beacon-node/test/spec/presets/ssz_static.test.ts index 47808f76ccae..97896659934b 100644 --- a/packages/beacon-node/test/spec/presets/ssz_static.test.ts +++ b/packages/beacon-node/test/spec/presets/ssz_static.test.ts @@ -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"; @@ -56,9 +56,9 @@ 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}`); - } + it(`SSZ type for ${typeName}`, function () { + expect(sszType).toBeDefined(); + }); const sszTypeNoUint = replaceUintTypeWithUintBigintType(sszType); From 8a708111d2526b3552d1594af1493814dfbcd129 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Tue, 14 May 2024 18:18:45 +0300 Subject: [PATCH 2/2] chore: address comments --- .../test/spec/presets/ssz_static.test.ts | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/beacon-node/test/spec/presets/ssz_static.test.ts b/packages/beacon-node/test/spec/presets/ssz_static.test.ts index 97896659934b..3c81bd823e82 100644 --- a/packages/beacon-node/test/spec/presets/ssz_static.test.ts +++ b/packages/beacon-node/test/spec/presets/ssz_static.test.ts @@ -56,23 +56,26 @@ const sszStatic = (ssz.bellatrix as Types)[typeName] || (ssz.altair as Types)[typeName] || (ssz.phase0 as Types)[typeName]; - it(`SSZ type for ${typeName}`, function () { - expect(sszType).toBeDefined(); - }); - 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); + }); + } } };