chore: restructure tests (#7793)

Follow up to https://github.com/ChainSafe/lodestar/pull/7610 with a few
restructuring suggestions, see comments below for detailed changes,
revives constants tests we are no longer running in CI and makes each
package executable separately again, ie. `cd packages/<package-name>`
into `yarn test:unit` works for all packages again.

One major change is that unit tests default should be written with
`mainnet` preset in mind as I noticed that makes a lot more sense for a
bunch of existing tests, eg. we have tests that depend on external
fixtures, like api spec tests for events and those are not compatible
with `minimal` preset. Also there doesn't seem to be much downside in
most cases for unit tests to use `mainnet` preset as it does not run
through all the epoch, like for example a e2e or sim test does. So
overall, it allows us to use mainnet fixtures / more "real world" data
which seems better with little to no downside.


Time comparison running unit tests on `unstable` vs. this branch

**unstable**

![image](https://github.com/user-attachments/assets/ba9c8e68-ec1a-4cb7-90fc-eb00cedae4bf)

**nflaig/restructure-tests**

![image](https://github.com/user-attachments/assets/0ffab5a4-4a71-42e1-a26e-32fc5627b873)

There is just a difference of 2 seconds (might be a fluke) in a 6 minute
run, this seems acceptable to me considering the benefits of using
`mainnet` preset noted above.
This commit is contained in:
Nico Flaig
2025-05-07 18:21:12 +01:00
committed by GitHub
parent 57f8f00d93
commit fa898bb319
105 changed files with 206 additions and 214 deletions

View File

@@ -110,7 +110,7 @@ jobs:
# id: unit_tests # id: unit_tests
# Rever to "yarn test:unit" when finished debugging core dumps # Rever to "yarn test:unit" when finished debugging core dumps
# run: sudo sh -c "ulimit -c unlimited && /usr/bin/node-with-debug $(which yarn) test:unit" # run: sudo sh -c "ulimit -c unlimited && /usr/bin/node-with-debug $(which yarn) test:unit"
run: yarn vitest run --project unit --project unit-mainnet --coverage run: yarn vitest run --project unit --project unit-minimal --coverage
# # Remove when finished debugging core dumps # # Remove when finished debugging core dumps
# - uses: './.github/actions/core-dump' # - uses: './.github/actions/core-dump'

View File

@@ -13,7 +13,7 @@ export const browserTestProject = defineProject({
exclude: ["**/*.node.test.ts"], exclude: ["**/*.node.test.ts"],
setupFiles: [path.join(import.meta.dirname, "../scripts/vitest/setupFiles/customMatchers.ts")], setupFiles: [path.join(import.meta.dirname, "../scripts/vitest/setupFiles/customMatchers.ts")],
env: { env: {
LODESTAR_PRESET: "minimal", LODESTAR_PRESET: "mainnet",
}, },
browser: { browser: {
enabled: true, enabled: true,

View File

@@ -1,8 +1,11 @@
import path from "node:path"; import path from "node:path";
import {defineProject} from "vitest/config"; import {defineProject} from "vitest/config";
export const e2eProject = defineProject({ export const e2eMinimalProject = defineProject({
test: { test: {
// Preferable over `e2e-mainnet` to speed up tests, only use `mainnet` preset in e2e tests
// if absolutely required for interop testing, eg. in case of web3signer we need to use
// `mainnet` preset to allow testing across multiple forks and ensure mainnet compatibility
name: "e2e", name: "e2e",
include: ["**/test/e2e/**/*.test.ts"], include: ["**/test/e2e/**/*.test.ts"],
setupFiles: [ setupFiles: [

View File

@@ -3,7 +3,7 @@ import {defineProject} from "vitest/config";
export const specProjectMinimal = defineProject({ export const specProjectMinimal = defineProject({
test: { test: {
name: "spec", name: "spec-minimal",
include: ["**/test/spec/**/*.test.ts"], include: ["**/test/spec/**/*.test.ts"],
setupFiles: [ setupFiles: [
path.join(__dirname, "../scripts/vitest/setupFiles/customMatchers.ts"), path.join(__dirname, "../scripts/vitest/setupFiles/customMatchers.ts"),

View File

@@ -7,16 +7,11 @@ const setupFiles = [
path.join(import.meta.dirname, "../scripts/vitest/setupFiles/lodestarPreset.ts"), path.join(import.meta.dirname, "../scripts/vitest/setupFiles/lodestarPreset.ts"),
]; ];
export const unitTestProject = defineProject({ export const unitTestMinimalProject = defineProject({
test: { test: {
name: "unit", name: "unit-minimal",
include: ["**/test/unit/**/*.test.ts"], include: ["**/test/unit-minimal/**/*.test.ts"],
setupFiles, setupFiles,
// There are some tests which are taking huge time
// test/unit/chain/rewards/blockRewards.test.ts > chain / rewards / blockRewards > Normal case 73869ms
// for now I tried to identify such tests an increase the limit a bit higher
testTimeout: 20_000,
hookTimeout: 20_000,
pool: "forks", pool: "forks",
env: { env: {
LODESTAR_PRESET: "minimal", LODESTAR_PRESET: "minimal",
@@ -26,8 +21,11 @@ export const unitTestProject = defineProject({
export const unitTestMainnetProject = defineProject({ export const unitTestMainnetProject = defineProject({
test: { test: {
name: "unit-mainnet", // Preferable over `unit-minimal` to test against mainnet fixtures/data, only use `minimal` preset in unit tests
include: ["**/test/unit-mainnet/**/*.test.ts"], // if it significantly speeds up or simplifies test cases, eg. committee-based tests are a lot of the time easier
// to write and faster when using `minimal` preset due to reduced committee size which lowers validator count required.
name: "unit",
include: ["**/test/unit/**/*.test.ts"],
setupFiles, setupFiles,
// There are some tests which are taking huge time // There are some tests which are taking huge time
// test/unit/chain/rewards/blockRewards.test.ts > chain / rewards / blockRewards > Normal case 73869ms // test/unit/chain/rewards/blockRewards.test.ts > chain / rewards / blockRewards > Normal case 73869ms

View File

@@ -28,11 +28,11 @@
"docs:lint": "prettier '**/*.md' --check", "docs:lint": "prettier '**/*.md' --check",
"docs:lint:fix": "prettier '**/*.md' --write", "docs:lint:fix": "prettier '**/*.md' --write",
"test": "lerna run test --concurrency 1", "test": "lerna run test --concurrency 1",
"test:unit": "vitest --project unit --project unit-mainnet", "test:unit": "vitest run --project unit --project unit-minimal",
"test:browsers": "vitest --project browser", "test:browsers": "vitest run --project browser",
"test:e2e": "vitest --project e2e", "test:e2e": "vitest run --project e2e --project e2e-mainnet",
"download-spec-tests": "lerna run download-spec-tests", "download-spec-tests": "lerna run download-spec-tests",
"test:spec": "vitest --project spec", "test:spec": "vitest run --project spec-minimal --project spec-mainnet",
"benchmark": "yarn benchmark:files 'packages/*/test/perf/**/*.test.ts'", "benchmark": "yarn benchmark:files 'packages/*/test/perf/**/*.test.ts'",
"benchmark:files": "NODE_OPTIONS='--max-old-space-size=4096 --loader=ts-node/esm' benchmark --config .benchrc.yaml --defaultBranch unstable", "benchmark:files": "NODE_OPTIONS='--max-old-space-size=4096 --loader=ts-node/esm' benchmark --config .benchrc.yaml --defaultBranch unstable",
"release:create-rc": "node scripts/release/create_rc.mjs", "release:create-rc": "node scripts/release/create_rc.mjs",

View File

@@ -66,7 +66,7 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit", "test": "yarn test:unit",
"test:unit": "vitest run --project unit", "test:unit": "vitest run --project unit --project unit-minimal",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },
"dependencies": { "dependencies": {

View File

@@ -78,15 +78,15 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit && yarn test:e2e", "test": "yarn test:unit && yarn test:e2e",
"test:unit": "vitest run --project unit --project unit-mainnet", "test:unit": "vitest run --project unit --project unit-minimal",
"test:e2e": "vitest run --project e2e", "test:e2e": "vitest run --project e2e --project e2e-mainnet",
"test:sim": "vitest run test/sim/**/*.test.ts", "test:sim": "vitest run test/sim/**/*.test.ts",
"test:sim:mergemock": "vitest run test/sim/mergemock.test.ts", "test:sim:mergemock": "vitest run test/sim/mergemock.test.ts",
"test:sim:blobs": "vitest run test/sim/4844-interop.test.ts", "test:sim:blobs": "vitest run test/sim/4844-interop.test.ts",
"download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts", "download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts",
"test:spec:bls": "vitest run --project spec test/spec/bls/", "test:spec:bls": "vitest run --project spec-minimal test/spec/bls/",
"test:spec:general": "vitest run --project spec test/spec/general/", "test:spec:general": "vitest run --project spec-minimal test/spec/general/",
"test:spec:minimal": "vitest run --project spec test/spec/presets/", "test:spec:minimal": "vitest run --project spec-minimal test/spec/presets/",
"test:spec:mainnet": "vitest run --project spec-mainnet test/spec/presets/", "test:spec:mainnet": "vitest run --project spec-mainnet test/spec/presets/",
"test:spec": "yarn test:spec:bls && yarn test:spec:general && yarn test:spec:minimal && yarn test:spec:mainnet", "test:spec": "yarn test:spec:bls && yarn test:spec:general && yarn test:spec:minimal && yarn test:spec:mainnet",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"

View File

@@ -1,67 +0,0 @@
import {bigIntToBytes} from "@lodestar/utils";
import {describe, expect, it} from "vitest";
import {computeSubscribedSubnet} from "../../../../src/network/subnets/util.js";
describe("computeSubscribedSubnet", () => {
// lighthouse's test cases https://github.com/sigp/lighthouse/blob/cc780aae3e0cb89649086a3b63cb02a4f97f7ae2/consensus/types/src/subnet_id.rs#L169
// this goes with mainnet config
const testCases: {nodeId: string; epoch: number; expected: number[]}[] = [
{
nodeId: "0",
epoch: 54321,
expected: [4, 5],
},
{
nodeId: "88752428858350697756262172400162263450541348766581994718383409852729519486397",
epoch: 1017090249,
expected: [61, 62],
},
{
nodeId: "18732750322395381632951253735273868184515463718109267674920115648614659369468",
epoch: 1827566880,
expected: [23, 24],
},
{
nodeId: "27726842142488109545414954493849224833670205008410190955613662332153332462900",
epoch: 846255942,
expected: [38, 39],
},
{
nodeId: "39755236029158558527862903296867805548949739810920318269566095185775868999998",
epoch: 766597383,
expected: [53, 54],
},
{
nodeId: "31899136003441886988955119620035330314647133604576220223892254902004850516297",
epoch: 1204990115,
expected: [39, 40],
},
{
nodeId: "58579998103852084482416614330746509727562027284701078483890722833654510444626",
epoch: 1616209495,
expected: [48, 49],
},
{
nodeId: "28248042035542126088870192155378394518950310811868093527036637864276176517397",
epoch: 1774367616,
expected: [39, 40],
},
{
nodeId: "60930578857433095740782970114409273483106482059893286066493409689627770333527",
epoch: 1484598751,
expected: [34, 35],
},
{
nodeId: "103822458477361691467064888613019442068586830412598673713899771287914656699997",
epoch: 3525502229,
expected: [37, 38],
},
];
for (const [index, {nodeId, epoch, expected}] of testCases.entries()) {
it(`test case ${index}`, () => {
// node is is of type uint256 = 32 bytes
expect(computeSubscribedSubnet(bigIntToBytes(BigInt(nodeId), 32, "be"), epoch)).toEqual(expected);
});
}
});

View File

@@ -2,11 +2,13 @@ import {SecretKey, Signature, aggregateSignatures, fastAggregateVerify} from "@c
import {BitArray, fromHexString, toHexString} from "@chainsafe/ssz"; import {BitArray, fromHexString, toHexString} from "@chainsafe/ssz";
import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; import {createChainForkConfig, defaultChainConfig} from "@lodestar/config";
import { import {
ACTIVE_PRESET,
FAR_FUTURE_EPOCH, FAR_FUTURE_EPOCH,
ForkName, ForkName,
ForkPostElectra, ForkPostElectra,
MAX_COMMITTEES_PER_SLOT, MAX_COMMITTEES_PER_SLOT,
MAX_EFFECTIVE_BALANCE, MAX_EFFECTIVE_BALANCE,
PresetName,
SLOTS_PER_EPOCH, SLOTS_PER_EPOCH,
} from "@lodestar/params"; } from "@lodestar/params";
import {CachedBeaconStateAllForks, CachedBeaconStateElectra, newFilledArray} from "@lodestar/state-transition"; import {CachedBeaconStateAllForks, CachedBeaconStateElectra, newFilledArray} from "@lodestar/state-transition";
@@ -36,6 +38,10 @@ const validSignature = fromHexString(
); );
describe("AggregatedAttestationPool - Altair", () => { describe("AggregatedAttestationPool - Altair", () => {
if (ACTIVE_PRESET !== PresetName.minimal) {
throw Error(`ACTIVE_PRESET '${ACTIVE_PRESET}' must be minimal`);
}
let pool: AggregatedAttestationPool; let pool: AggregatedAttestationPool;
const fork = ForkName.altair; const fork = ForkName.altair;
const config = createChainForkConfig({ const config = createChainForkConfig({

View File

@@ -1,10 +1,9 @@
import {SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params"; import {ACTIVE_PRESET, PresetName, SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params";
import {CachedBeaconStateAllForks, computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {CachedBeaconStateAllForks, computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition";
import {RootHex, phase0} from "@lodestar/types"; import {RootHex, phase0} from "@lodestar/types";
import {mapValues, toHexString} from "@lodestar/utils"; import {mapValues, toHexString} from "@lodestar/utils";
import {beforeAll, beforeEach, describe, expect, it} from "vitest"; import {beforeAll, beforeEach, describe, expect, it} from "vitest";
import {FIFOBlockStateCache, toCheckpointHex} from "../../../../src/chain/index.js"; import {FIFOBlockStateCache, toCheckpointHex} from "../../../../src/chain/index.js";
import {ShufflingCache} from "../../../../src/chain/shufflingCache.js";
import {checkpointToDatastoreKey} from "../../../../src/chain/stateCache/datastore/index.js"; import {checkpointToDatastoreKey} from "../../../../src/chain/stateCache/datastore/index.js";
import {PersistentCheckpointStateCache} from "../../../../src/chain/stateCache/persistentCheckpointsCache.js"; import {PersistentCheckpointStateCache} from "../../../../src/chain/stateCache/persistentCheckpointsCache.js";
import {CheckpointHex} from "../../../../src/chain/stateCache/types.js"; import {CheckpointHex} from "../../../../src/chain/stateCache/types.js";
@@ -13,6 +12,10 @@ import {testLogger} from "../../../utils/logger.js";
import {generateCachedState} from "../../../utils/state.js"; import {generateCachedState} from "../../../utils/state.js";
describe("PersistentCheckpointStateCache", () => { describe("PersistentCheckpointStateCache", () => {
if (ACTIVE_PRESET !== PresetName.minimal) {
throw Error(`ACTIVE_PRESET '${ACTIVE_PRESET}' must be minimal`);
}
let root0a: Buffer, root0b: Buffer, root1: Buffer, root2: Buffer; let root0a: Buffer, root0b: Buffer, root1: Buffer, root2: Buffer;
let cp0a: phase0.Checkpoint, cp0b: phase0.Checkpoint, cp1: phase0.Checkpoint, cp2: phase0.Checkpoint; let cp0a: phase0.Checkpoint, cp0b: phase0.Checkpoint, cp1: phase0.Checkpoint, cp2: phase0.Checkpoint;
let cp0aHex: CheckpointHex, cp0bHex: CheckpointHex, cp1Hex: CheckpointHex, cp2Hex: CheckpointHex; let cp0aHex: CheckpointHex, cp0bHex: CheckpointHex, cp1Hex: CheckpointHex, cp2Hex: CheckpointHex;

View File

@@ -34,7 +34,7 @@ describe("config api implementation", () => {
const {data: specJson} = (await api.getSpec()) as {data: routes.config.Spec}; const {data: specJson} = (await api.getSpec()) as {data: routes.config.Spec};
expect(specJson.SECONDS_PER_ETH1_BLOCK).toBe("14"); expect(specJson.SECONDS_PER_ETH1_BLOCK).toBe("14");
expect(specJson.DEPOSIT_CONTRACT_ADDRESS).toBe("0x1234567890123456789012345678901234567890"); expect(specJson.DEPOSIT_CONTRACT_ADDRESS).toBe("0x00000000219ab540356cbb839cbe05303d7705fa");
}); });
}); });
}); });

View File

@@ -66,7 +66,7 @@ describe("get proposers api impl", () => {
vi.advanceTimersByTime((SYNC_TOLERANCE_EPOCHS * SLOTS_PER_EPOCH + 1) * config.SECONDS_PER_SLOT * 1000); vi.advanceTimersByTime((SYNC_TOLERANCE_EPOCHS * SLOTS_PER_EPOCH + 1) * config.SECONDS_PER_SLOT * 1000);
vi.spyOn(modules.sync, "state", "get").mockReturnValue(SyncState.SyncingHead); vi.spyOn(modules.sync, "state", "get").mockReturnValue(SyncState.SyncingHead);
await expect(api.getProposerDuties({epoch: 1})).rejects.toThrow("Node is syncing - headSlot 0 currentSlot 25"); await expect(api.getProposerDuties({epoch: 1})).rejects.toThrow("Node is syncing - headSlot 0 currentSlot 97");
}); });
it("should raise error if node stalled", async () => { it("should raise error if node stalled", async () => {

View File

@@ -5,25 +5,33 @@ import {getNonCheckpointBlocks} from "../../../../src/chain/archiveStore/utils/a
describe("chain / archive / getNonCheckpointBlocks", () => { describe("chain / archive / getNonCheckpointBlocks", () => {
beforeAll(() => { beforeAll(() => {
expect(SLOTS_PER_EPOCH).toBe(8); expect(SLOTS_PER_EPOCH).toBe(32);
}); });
const testCases: {id: string; blocks: Slot[]; maybeCheckpointSlots: Slot[]}[] = [ const testCases: {id: string; blocks: Slot[]; maybeCheckpointSlots: Slot[]}[] = [
{id: "empty", blocks: [], maybeCheckpointSlots: []}, {id: "empty", blocks: [], maybeCheckpointSlots: []},
{id: "one block", blocks: [4], maybeCheckpointSlots: [4]}, {id: "one block", blocks: [16], maybeCheckpointSlots: [16]},
{id: "one block in first slot", blocks: [0], maybeCheckpointSlots: [0]}, {id: "one block in first slot", blocks: [0], maybeCheckpointSlots: [0]},
{id: "one block per epoch", blocks: [4, 12, 20], maybeCheckpointSlots: [4, 12, 20]}, {id: "one block per epoch", blocks: [16, 48, 80], maybeCheckpointSlots: [16, 48, 80]},
{id: "two blocks per epoch", blocks: [4, 5, 12, 13, 20, 21], maybeCheckpointSlots: [5, 13, 21]}, {id: "two blocks per epoch", blocks: [16, 20, 48, 52, 80, 84], maybeCheckpointSlots: [20, 52, 84]},
{ {
id: "linear sequence of blocks", id: "linear sequence of blocks",
blocks: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], blocks: [
maybeCheckpointSlots: [0, 8, 16, 17], 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65,
],
maybeCheckpointSlots: [0, 32, 64, 65],
}, },
{ {
id: "linear sequence of blocks, first block skipped", id: "linear sequence of blocks, first block skipped",
blocks: [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17], blocks: [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, /*32*/ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, 61, 62, 63, /*64*/ 65,
],
// Since the first blocks are skipped, now the last blocks of the epoch are the checkpoint blocks // Since the first blocks are skipped, now the last blocks of the epoch are the checkpoint blocks
maybeCheckpointSlots: [0, 7, 15, 17], maybeCheckpointSlots: [0, 31, 63, 65],
}, },
]; ];

View File

@@ -34,12 +34,12 @@ describe("UpgradeLightClientHeader", () => {
testSlots = { testSlots = {
phase0: 0, phase0: 0,
altair: 10, altair: 40,
bellatrix: 17, bellatrix: 68,
capella: 25, capella: 100,
deneb: 33, deneb: 132,
electra: 41, electra: 164,
fulu: 54, fulu: 216,
}; };
}); });

View File

@@ -40,7 +40,7 @@ describe("chain / opPools / SyncContributionAndProofPool", () => {
const aggregate = cache.getAggregate(slot, beaconBlockRoot); const aggregate = cache.getAggregate(slot, beaconBlockRoot);
expect(ssz.altair.SyncAggregate.equals(aggregate, ssz.altair.SyncAggregate.defaultValue())).toBe(false); expect(ssz.altair.SyncAggregate.equals(aggregate, ssz.altair.SyncAggregate.defaultValue())).toBe(false);
// TODO Test it's correct. Modify the contributions above so they have 1 bit set to true // TODO Test it's correct. Modify the contributions above so they have 1 bit set to true
expect(aggregate.syncCommitteeBits.bitLen).toBe(32); expect(aggregate.syncCommitteeBits.bitLen).toBe(512);
}); });
}); });
@@ -105,7 +105,7 @@ describe("aggregate", () => {
const expectSyncCommittees = newFilledArray(SYNC_COMMITTEE_SIZE, false); const expectSyncCommittees = newFilledArray(SYNC_COMMITTEE_SIZE, false);
for (let subnet = 0; subnet < numSubnet; subnet++) { for (let subnet = 0; subnet < numSubnet; subnet++) {
// first participation of each subnet is true // first participation of each subnet is true
expectSyncCommittees[subnet * 8] = true; expectSyncCommittees[subnet * 128] = true;
} }
expect(renderBitArray(syncAggregate.syncCommitteeBits)).toEqual( expect(renderBitArray(syncAggregate.syncCommitteeBits)).toEqual(
renderBitArray(BitArray.fromBoolArray(expectSyncCommittees)) renderBitArray(BitArray.fromBoolArray(expectSyncCommittees))

View File

@@ -14,8 +14,8 @@ import {
} from "../../../utils/validationData/aggregateAndProof.js"; } from "../../../utils/validationData/aggregateAndProof.js";
describe("chain / validation / aggregateAndProof", () => { describe("chain / validation / aggregateAndProof", () => {
const vc = 64; const vc = 8192;
const stateSlot = 100; const stateSlot = 400;
const UNKNOWN_ROOT = Buffer.alloc(32, 1); const UNKNOWN_ROOT = Buffer.alloc(32, 1);
const KNOWN_TARGET_ROOT = Buffer.alloc(32, 0xd0); const KNOWN_TARGET_ROOT = Buffer.alloc(32, 0xd0);
@@ -142,14 +142,14 @@ describe("chain / validation / aggregateAndProof", () => {
const {aggregationBits} = signedAggregateAndProof.message.aggregate; const {aggregationBits} = signedAggregateAndProof.message.aggregate;
signedAggregateAndProof.message.aggregate.aggregationBits = new BitArray( signedAggregateAndProof.message.aggregate.aggregationBits = new BitArray(
aggregationBits.uint8Array, aggregationBits.uint8Array,
aggregationBits.bitLen + 1 aggregationBits.bitLen - 1
); );
await expectError(chain, signedAggregateAndProof, AttestationErrorCode.WRONG_NUMBER_OF_AGGREGATION_BITS); await expectError(chain, signedAggregateAndProof, AttestationErrorCode.WRONG_NUMBER_OF_AGGREGATION_BITS);
}); });
it("INVALID_SIGNATURE - selection proof sig", async () => { it("INVALID_SIGNATURE - selection proof sig", async () => {
const bitIndex = 1; const bitIndex = 126;
const {chain, signedAggregateAndProof} = getValidData({bitIndex}); const {chain, signedAggregateAndProof} = getValidData({bitIndex});
// Swap the selectionProof signature with the overall sig of the object // Swap the selectionProof signature with the overall sig of the object
signedAggregateAndProof.message.selectionProof = signedAggregateAndProof.signature; signedAggregateAndProof.message.selectionProof = signedAggregateAndProof.signature;

View File

@@ -21,8 +21,8 @@ import {AttestationValidDataOpts, getAttestationValidData} from "../../../../uti
// TODO: more tests for electra // TODO: more tests for electra
describe("validateAttestation", () => { describe("validateAttestation", () => {
const vc = 64; const vc = 8192;
const stateSlot = 100; const stateSlot = 400;
const UNKNOWN_ROOT = Buffer.alloc(32, 1); const UNKNOWN_ROOT = Buffer.alloc(32, 1);
const KNOWN_TARGET_ROOT = Buffer.alloc(32, 0xd0); const KNOWN_TARGET_ROOT = Buffer.alloc(32, 0xd0);
@@ -212,7 +212,7 @@ describe("validateAttestation", () => {
// Increase the length of aggregationBits beyond the committee size // Increase the length of aggregationBits beyond the committee size
attestation.aggregationBits = new BitArray( attestation.aggregationBits = new BitArray(
attestation.aggregationBits.uint8Array, attestation.aggregationBits.uint8Array,
attestation.aggregationBits.bitLen + 1 attestation.aggregationBits.bitLen - 1
); );
const serializedData = ssz.phase0.Attestation.serialize(attestation); const serializedData = ssz.phase0.Attestation.serialize(attestation);

View File

@@ -12,73 +12,73 @@ describe("network / gossip / topic", () => {
[GossipType.beacon_block]: [ [GossipType.beacon_block]: [
{ {
topic: {type: GossipType.beacon_block, fork: ForkName.phase0, encoding}, topic: {type: GossipType.beacon_block, fork: ForkName.phase0, encoding},
topicStr: "/eth2/18ae4ccb/beacon_block/ssz_snappy", topicStr: "/eth2/f5a5fd42/beacon_block/ssz_snappy",
}, },
], ],
[GossipType.blob_sidecar]: [ [GossipType.blob_sidecar]: [
{ {
topic: {type: GossipType.blob_sidecar, subnet: 1, fork: ForkName.deneb, encoding}, topic: {type: GossipType.blob_sidecar, subnet: 1, fork: ForkName.deneb, encoding},
topicStr: "/eth2/46acb19a/blob_sidecar_1/ssz_snappy", topicStr: "/eth2/d6e497b8/blob_sidecar_1/ssz_snappy",
}, },
], ],
[GossipType.beacon_aggregate_and_proof]: [ [GossipType.beacon_aggregate_and_proof]: [
{ {
topic: {type: GossipType.beacon_aggregate_and_proof, fork: ForkName.phase0, encoding}, topic: {type: GossipType.beacon_aggregate_and_proof, fork: ForkName.phase0, encoding},
topicStr: "/eth2/18ae4ccb/beacon_aggregate_and_proof/ssz_snappy", topicStr: "/eth2/f5a5fd42/beacon_aggregate_and_proof/ssz_snappy",
}, },
], ],
[GossipType.beacon_attestation]: [ [GossipType.beacon_attestation]: [
{ {
topic: {type: GossipType.beacon_attestation, fork: ForkName.phase0, subnet: 5, encoding}, topic: {type: GossipType.beacon_attestation, fork: ForkName.phase0, subnet: 5, encoding},
topicStr: "/eth2/18ae4ccb/beacon_attestation_5/ssz_snappy", topicStr: "/eth2/f5a5fd42/beacon_attestation_5/ssz_snappy",
}, },
], ],
[GossipType.voluntary_exit]: [ [GossipType.voluntary_exit]: [
{ {
topic: {type: GossipType.voluntary_exit, fork: ForkName.phase0, encoding}, topic: {type: GossipType.voluntary_exit, fork: ForkName.phase0, encoding},
topicStr: "/eth2/18ae4ccb/voluntary_exit/ssz_snappy", topicStr: "/eth2/f5a5fd42/voluntary_exit/ssz_snappy",
}, },
], ],
[GossipType.bls_to_execution_change]: [ [GossipType.bls_to_execution_change]: [
{ {
topic: {type: GossipType.bls_to_execution_change, fork: ForkName.capella, encoding}, topic: {type: GossipType.bls_to_execution_change, fork: ForkName.capella, encoding},
topicStr: "/eth2/63f1741c/bls_to_execution_change/ssz_snappy", topicStr: "/eth2/e7b4bb67/bls_to_execution_change/ssz_snappy",
}, },
], ],
[GossipType.proposer_slashing]: [ [GossipType.proposer_slashing]: [
{ {
topic: {type: GossipType.proposer_slashing, fork: ForkName.phase0, encoding}, topic: {type: GossipType.proposer_slashing, fork: ForkName.phase0, encoding},
topicStr: "/eth2/18ae4ccb/proposer_slashing/ssz_snappy", topicStr: "/eth2/f5a5fd42/proposer_slashing/ssz_snappy",
}, },
], ],
[GossipType.attester_slashing]: [ [GossipType.attester_slashing]: [
{ {
topic: {type: GossipType.attester_slashing, fork: ForkName.phase0, encoding}, topic: {type: GossipType.attester_slashing, fork: ForkName.phase0, encoding},
topicStr: "/eth2/18ae4ccb/attester_slashing/ssz_snappy", topicStr: "/eth2/f5a5fd42/attester_slashing/ssz_snappy",
}, },
], ],
[GossipType.sync_committee_contribution_and_proof]: [ [GossipType.sync_committee_contribution_and_proof]: [
{ {
topic: {type: GossipType.sync_committee_contribution_and_proof, fork: ForkName.altair, encoding}, topic: {type: GossipType.sync_committee_contribution_and_proof, fork: ForkName.altair, encoding},
topicStr: "/eth2/8e04f66f/sync_committee_contribution_and_proof/ssz_snappy", topicStr: "/eth2/16abab34/sync_committee_contribution_and_proof/ssz_snappy",
}, },
], ],
[GossipType.sync_committee]: [ [GossipType.sync_committee]: [
{ {
topic: {type: GossipType.sync_committee, fork: ForkName.altair, subnet: 5, encoding}, topic: {type: GossipType.sync_committee, fork: ForkName.altair, subnet: 5, encoding},
topicStr: "/eth2/8e04f66f/sync_committee_5/ssz_snappy", topicStr: "/eth2/16abab34/sync_committee_5/ssz_snappy",
}, },
], ],
[GossipType.light_client_finality_update]: [ [GossipType.light_client_finality_update]: [
{ {
topic: {type: GossipType.light_client_finality_update, fork: ForkName.altair, encoding}, topic: {type: GossipType.light_client_finality_update, fork: ForkName.altair, encoding},
topicStr: "/eth2/8e04f66f/light_client_finality_update/ssz_snappy", topicStr: "/eth2/16abab34/light_client_finality_update/ssz_snappy",
}, },
], ],
[GossipType.light_client_optimistic_update]: [ [GossipType.light_client_optimistic_update]: [
{ {
topic: {type: GossipType.light_client_optimistic_update, fork: ForkName.altair, encoding}, topic: {type: GossipType.light_client_optimistic_update, fork: ForkName.altair, encoding},
topicStr: "/eth2/8e04f66f/light_client_optimistic_update/ssz_snappy", topicStr: "/eth2/16abab34/light_client_optimistic_update/ssz_snappy",
}, },
], ],
}; };
@@ -105,14 +105,14 @@ describe("network / gossip / topic", () => {
// invalid fork digest // invalid fork digest
"/eth2/ffffffff/beacon_attestation_5/ssz_snappy", "/eth2/ffffffff/beacon_attestation_5/ssz_snappy",
// invalid gossip type // invalid gossip type
"/eth2/18ae4ccb/beacon_attestation_foo/ssz_snappy", "/eth2/f5a5fd42/beacon_attestation_foo/ssz_snappy",
// invalid gossip type // invalid gossip type
"/eth2/18ae4ccb/something_different/ssz_snappy", "/eth2/f5a5fd42/something_different/ssz_snappy",
"/eth2/18ae4ccb/beacon_attestation/ssz_snappy", "/eth2/f5a5fd42/beacon_attestation/ssz_snappy",
"/eth2/18ae4ccb/beacon_attestation_/ssz_snappy", "/eth2/f5a5fd42/beacon_attestation_/ssz_snappy",
"/eth2/18ae4ccb/beacon_attestation_PP/ssz_snappy", "/eth2/f5a5fd42/beacon_attestation_PP/ssz_snappy",
// invalid encoding // invalid encoding
"/eth2/18ae4ccb/beacon_attestation_5/ssz_supersnappy", "/eth2/f5a5fd42/beacon_attestation_5/ssz_supersnappy",
]; ];
for (const topicStr of badTopicStrings) { for (const topicStr of badTopicStrings) {
it(`should fail to decode invalid gossip topic string ${topicStr}`, async () => { it(`should fail to decode invalid gossip topic string ${topicStr}`, async () => {

View File

@@ -1,7 +1,7 @@
import {ATTESTATION_SUBNET_PREFIX_BITS, NODE_ID_BITS} from "@lodestar/params"; import {ATTESTATION_SUBNET_PREFIX_BITS, NODE_ID_BITS} from "@lodestar/params";
import {bigIntToBytes} from "@lodestar/utils"; import {bigIntToBytes} from "@lodestar/utils";
import {describe, expect, it} from "vitest"; import {describe, expect, it} from "vitest";
import {getNodeIdPrefix, getNodeOffset} from "../../../../src/network/subnets/util.js"; import {computeSubscribedSubnet, getNodeIdPrefix, getNodeOffset} from "../../../../src/network/subnets/util.js";
const nodeIds: string[] = [ const nodeIds: string[] = [
"0", "0",
@@ -39,3 +39,67 @@ describe("getNodeOffset", () => {
}); });
} }
}); });
describe("computeSubscribedSubnet", () => {
// lighthouse's test cases https://github.com/sigp/lighthouse/blob/cc780aae3e0cb89649086a3b63cb02a4f97f7ae2/consensus/types/src/subnet_id.rs#L169
// this goes with mainnet config
const testCases: {nodeId: string; epoch: number; expected: number[]}[] = [
{
nodeId: "0",
epoch: 54321,
expected: [4, 5],
},
{
nodeId: "88752428858350697756262172400162263450541348766581994718383409852729519486397",
epoch: 1017090249,
expected: [61, 62],
},
{
nodeId: "18732750322395381632951253735273868184515463718109267674920115648614659369468",
epoch: 1827566880,
expected: [23, 24],
},
{
nodeId: "27726842142488109545414954493849224833670205008410190955613662332153332462900",
epoch: 846255942,
expected: [38, 39],
},
{
nodeId: "39755236029158558527862903296867805548949739810920318269566095185775868999998",
epoch: 766597383,
expected: [53, 54],
},
{
nodeId: "31899136003441886988955119620035330314647133604576220223892254902004850516297",
epoch: 1204990115,
expected: [39, 40],
},
{
nodeId: "58579998103852084482416614330746509727562027284701078483890722833654510444626",
epoch: 1616209495,
expected: [48, 49],
},
{
nodeId: "28248042035542126088870192155378394518950310811868093527036637864276176517397",
epoch: 1774367616,
expected: [39, 40],
},
{
nodeId: "60930578857433095740782970114409273483106482059893286066493409689627770333527",
epoch: 1484598751,
expected: [34, 35],
},
{
nodeId: "103822458477361691467064888613019442068586830412598673713899771287914656699997",
epoch: 3525502229,
expected: [37, 38],
},
];
for (const [index, {nodeId, epoch, expected}] of testCases.entries()) {
it(`test case ${index}`, () => {
// node is is of type uint256 = 32 bytes
expect(computeSubscribedSubnet(bigIntToBytes(BigInt(nodeId), 32, "be"), epoch)).toEqual(expected);
});
}
});

View File

@@ -17,7 +17,7 @@ describe("getCurrentAndNextFork", () => {
expect(nextFork).toBeUndefined(); expect(nextFork).toBeUndefined();
}); });
it("should return altair as next fork", () => { it("should return altair as next fork and then bellatrix", () => {
config.forks.altair.epoch = 1000; config.forks.altair.epoch = 1000;
let forks = getCurrentAndNextFork(config, 0); let forks = getCurrentAndNextFork(config, 0);
expect(forks.currentFork.name).toBe(ForkName.phase0); expect(forks.currentFork.name).toBe(ForkName.phase0);
@@ -29,7 +29,7 @@ describe("getCurrentAndNextFork", () => {
forks = getCurrentAndNextFork(config, 1000); forks = getCurrentAndNextFork(config, 1000);
expect(forks.currentFork.name).toBe(ForkName.altair); expect(forks.currentFork.name).toBe(ForkName.altair);
expect(forks.nextFork).toBeUndefined(); expect(forks.nextFork?.name).toBe(ForkName.bellatrix);
}); });
}); });

View File

@@ -30,8 +30,8 @@
"docs:build": "node --loader ts-node/esm ./docsgen/index.ts", "docs:build": "node --loader ts-node/esm ./docsgen/index.ts",
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test:unit": "vitest run --project unit --project unit-mainnet", "test:unit": "vitest run --project unit --project unit-minimal",
"test:e2e": "vitest run --project e2e", "test:e2e": "vitest run --project e2e --project e2e-mainnet",
"test:sim:multifork": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/multiFork.test.ts", "test:sim:multifork": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/multiFork.test.ts",
"test:sim:mixedclient": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/mixedClient.test.ts", "test:sim:mixedclient": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/mixedClient.test.ts",
"test:sim:endpoints": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/endpoints.test.ts", "test:sim:endpoints": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/endpoints.test.ts",

View File

@@ -1,29 +0,0 @@
import {LogLevel} from "@lodestar/utils";
import {describe, expect, it} from "vitest";
import {beaconHandlerInit} from "../../../src/cmds/beacon/handler.js";
import {BeaconArgs} from "../../../src/cmds/beacon/options.js";
import {GlobalArgs} from "../../../src/options/globalOptions.js";
import {testFilesDir} from "../../utils.js";
describe("cmds / beacon / args handler", () => {
// Make tests faster skipping a network call
process.env.SKIP_FETCH_NETWORK_BOOTNODES = "true";
it("Set known deposit contract", async () => {
const {options} = await runBeaconHandlerInit({
network: "mainnet",
});
// Okay to hardcode, since this value will never change
expect(options.eth1.depositContractDeployBlock).toBe(11052984);
});
});
async function runBeaconHandlerInit(args: Partial<BeaconArgs & GlobalArgs>) {
return beaconHandlerInit({
logLevel: LogLevel.info,
logFileLevel: LogLevel.debug,
dataDir: testFilesDir,
...args,
} as BeaconArgs & GlobalArgs);
}

View File

@@ -78,6 +78,15 @@ describe("cmds / beacon / args handler", () => {
expect(privateKey.equals(prevPk)).toBe(true); expect(privateKey.equals(prevPk)).toBe(true);
}); });
it("Set known deposit contract", async () => {
const {options} = await runBeaconHandlerInit({
network: "mainnet",
});
// Okay to hardcode, since this value will never change
expect(options.eth1.depositContractDeployBlock).toBe(11052984);
});
it("Apply custom network name from config file", async () => { it("Apply custom network name from config file", async () => {
const networkName = "test-network"; const networkName = "test-network";
const config = {...chainConfig}; const config = {...chainConfig};

View File

@@ -220,7 +220,7 @@ describe("options / beaconNodeOptions", () => {
}, },
sync: { sync: {
isSingleNode: true, isSingleNode: true,
slotImportTolerance: 8, slotImportTolerance: 32,
disableProcessAsChainSegment: true, disableProcessAsChainSegment: true,
backfillBatchSize: 64, backfillBatchSize: 64,
disableRangeSync: false, disableRangeSync: false,

View File

@@ -50,7 +50,7 @@
"lint": "biome check src/", "lint": "biome check src/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit", "test": "yarn test:unit",
"test:unit": "yarn vitest run --project unit", "test:unit": "yarn vitest run --project unit --project unit-minimal",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },
"repository": { "repository": {

View File

@@ -31,7 +31,7 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit", "test": "yarn test:unit",
"test:unit": "vitest run --project unit", "test:unit": "vitest run --project unit --project unit-minimal",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },
"dependencies": { "dependencies": {

View File

@@ -44,7 +44,7 @@
"lint": "biome check src/", "lint": "biome check src/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit", "test": "yarn test:unit",
"test:unit": "vitest run --project unit", "test:unit": "vitest run --project unit --project unit-minimal",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },
"repository": { "repository": {

View File

@@ -32,7 +32,7 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit", "test": "yarn test:unit",
"test:unit": "vitest run --project unit --project unit-mainnet", "test:unit": "vitest run --project unit --project unit-minimal",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },
"dependencies": { "dependencies": {

View File

@@ -65,7 +65,7 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit", "test": "yarn test:unit",
"test:unit": "vitest run --project unit", "test:unit": "vitest run --project unit --project unit-minimal",
"test:browsers": "yarn run build:bundle && vitest run --project browser", "test:browsers": "yarn run build:bundle && vitest run --project browser",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },

View File

@@ -56,9 +56,9 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit && yarn test:e2e", "test": "yarn test:unit && yarn test:e2e",
"test:unit": "vitest run --project unit", "test:unit": "vitest run --project unit --project unit-minimal",
"test:browsers": "vitest run --project browser", "test:browsers": "vitest run --project browser",
"test:e2e": "vitest run --project e2e", "test:e2e": "vitest run --project e2e --project e2e-mainnet",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -53,9 +53,9 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit", "test": "yarn test:unit",
"test:unit": "vitest run --project unit", "test:unit": "vitest run --project unit --project unit-minimal",
"test:browsers": "vitest run --project browser", "test:browsers": "vitest run --project browser",
"test:e2e": "vitest run --project e2e", "test:e2e": "vitest run --project e2e --project e2e-mainnet",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },
"repository": { "repository": {

View File

@@ -51,9 +51,9 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit && yarn test:e2e", "test": "yarn test:unit && yarn test:e2e",
"test:unit": "vitest run --project unit --project unit-mainnet", "test:unit": "vitest run --project unit --project unit-minimal",
"test:browsers": "vitest run --project browser", "test:browsers": "vitest run --project browser",
"test:e2e": "vitest run --project e2e", "test:e2e": "vitest run --project e2e --project e2e-mainnet",
"check-readme": "typescript-docs-verifier", "check-readme": "typescript-docs-verifier",
"generate-fixtures": "node --loader ts-node/esm scripts/generate_fixtures.ts" "generate-fixtures": "node --loader ts-node/esm scripts/generate_fixtures.ts"
}, },

View File

@@ -48,7 +48,7 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit", "test": "yarn test:unit",
"test:unit": "vitest run --project unit", "test:unit": "vitest run --project unit --project unit-minimal",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },
"dependencies": { "dependencies": {

View File

@@ -159,13 +159,13 @@ export const sszSnappySignedBeaconBlockAltair: MessageFixture = {
protocolVersion: 2, protocolVersion: 2,
}, },
asyncChunks: [ asyncChunks: [
"0xf803", // length prefix "0xb404", // length prefix
"0xff060000734e61507059", // snappy frames header "0xff060000734e61507059", // snappy frames header
"0x003f0000ee14ab0df8031064000000dafe01007a01000c995f0100010100090105ee70000d700054ee44000d44fe0100fecc0011cc0c400100003e0400fe01008e0100", "0x00420000bab7f8feb4041064000000dafe01007a01000c995f0100010100090105ee70000d700054ee44000d44fe0100fecc0011cc0c7c0100003e0400fe0100fe01007e0100",
].map((d) => fromHexString(d)), ].map((d) => fromHexString(d)),
chunks: [ chunks: [
"0xf803", "0xb404",
"0xff060000734e61507059003f0000ee14ab0df8031064000000dafe01007a01000c995f0100010100090105ee70000d700054ee44000d44fe0100fecc0011cc0c400100003e0400fe01008e0100", "0xff060000734e6150705900420000bab7f8feb4041064000000dafe01007a01000c995f0100010100090105ee70000d700054ee44000d44fe0100fecc0011cc0c7c0100003e0400fe0100fe01007e0100",
].map((s) => fromHexString(s)), ].map((s) => fromHexString(s)),
}; };

View File

@@ -47,8 +47,8 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit && yarn test:e2e", "test": "yarn test:unit && yarn test:e2e",
"test:unit": "vitest run --project unit", "test:unit": "vitest run --project unit --project unit-minimal",
"test:e2e": "vitest run --project e2e", "test:e2e": "vitest run --project e2e --project e2e-mainnet",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },
"repository": { "repository": {

View File

@@ -53,7 +53,7 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit", "test": "yarn test:unit",
"test:unit": "vitest run --project unit", "test:unit": "vitest run --project unit --project unit-minimal",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -5,7 +5,6 @@ import {
COMPOUNDING_WITHDRAWAL_PREFIX, COMPOUNDING_WITHDRAWAL_PREFIX,
FAR_FUTURE_EPOCH, FAR_FUTURE_EPOCH,
SLOTS_PER_EPOCH, SLOTS_PER_EPOCH,
SYNC_COMMITTEE_SIZE,
} from "@lodestar/params"; } from "@lodestar/params";
import {ssz} from "@lodestar/types"; import {ssz} from "@lodestar/types";
import {describe, expect, it} from "vitest"; import {describe, expect, it} from "vitest";
@@ -15,17 +14,18 @@ import {generateValidators} from "../../utils/validator.js";
describe("processConsolidationRequest", () => { describe("processConsolidationRequest", () => {
it("rejects BLS withdrawal credentials", () => { it("rejects BLS withdrawal credentials", () => {
const vc = 32;
const electraForkEpoch = 400000; const electraForkEpoch = 400000;
const currentEpoch = electraForkEpoch + 10; const currentEpoch = electraForkEpoch + 10;
const currentSlot = SLOTS_PER_EPOCH * currentEpoch; const currentSlot = SLOTS_PER_EPOCH * currentEpoch;
const validators = generateValidators(SYNC_COMMITTEE_SIZE, { const validators = generateValidators(vc, {
activation: electraForkEpoch - 10000, activation: electraForkEpoch - 10000,
withdrawableEpoch: FAR_FUTURE_EPOCH, withdrawableEpoch: FAR_FUTURE_EPOCH,
exit: FAR_FUTURE_EPOCH, exit: FAR_FUTURE_EPOCH,
}); });
for (let i = 0; i < SYNC_COMMITTEE_SIZE; i++) { for (let i = 0; i < vc; i++) {
const buffer = Buffer.alloc(32, 0); const buffer = Buffer.alloc(32, 0);
buffer.writeInt16BE(i + 1, 30); // Offset to ensure the SK is less than the order buffer.writeInt16BE(i + 1, 30); // Offset to ensure the SK is less than the order
const sk = bls.SecretKey.fromBytes(buffer); const sk = bls.SecretKey.fromBytes(buffer);

View File

@@ -62,9 +62,7 @@
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test": "yarn test:unit", "test": "yarn test:unit",
"test:constants:minimal": "vitest run --project constants", "test:unit": "vitest run --project unit --project unit-minimal",
"test:constants:mainnet": "vitest run --project constants-mainnet",
"test:unit": "wrapper() { yarn test:constants:minimal $@ && yarn test:constants:mainnet $@ && LODESTAR_PRESET=mainnet vitest run --project unit $@; }; wrapper",
"test:browsers": "vitest run --project browser", "test:browsers": "vitest run --project browser",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },

View File

@@ -1,6 +1,6 @@
import * as constants from "@lodestar/params"; import * as constants from "@lodestar/params";
import {describe, expect, it} from "vitest"; import {describe, expect, it} from "vitest";
import {ssz} from "../../src/index.js"; import {ssz} from "../../../src/index.js";
// NOTE: This test is here and not in lodestar-params, to prevent lodestar-params depending on SSZ // NOTE: This test is here and not in lodestar-params, to prevent lodestar-params depending on SSZ
// Since lodestar-params and lodestar-types are in the same mono-repo, running this test here is enough // Since lodestar-params and lodestar-types are in the same mono-repo, running this test here is enough

View File

@@ -1,6 +1,6 @@
import * as constants from "@lodestar/params"; import * as constants from "@lodestar/params";
import {describe, expect, it} from "vitest"; import {describe, expect, it} from "vitest";
import {ssz} from "../../src/index.js"; import {ssz} from "../../../src/index.js";
// NOTE: This test is here and not in lodestar-params, to prevent lodestar-params depending on SSZ // NOTE: This test is here and not in lodestar-params, to prevent lodestar-params depending on SSZ
// Since lodestar-params and lodestar-types are in the same mono-repo, running this test here is enough // Since lodestar-params and lodestar-types are in the same mono-repo, running this test here is enough

View File

@@ -6,8 +6,8 @@ describe("size", () => {
const minSize = ssz.phase0.BeaconState.minSize; const minSize = ssz.phase0.BeaconState.minSize;
const maxSize = ssz.phase0.BeaconState.maxSize; const maxSize = ssz.phase0.BeaconState.maxSize;
// https://gist.github.com/protolambda/db75c7faa1e94f2464787a480e5d613e // https://gist.github.com/protolambda/db75c7faa1e94f2464787a480e5d613e
expect(minSize).toBe(7057); expect(minSize).toBe(2687377);
expect(maxSize).toBe(141837537701009); expect(maxSize).toBe(141837543039377);
}); });
}); });

View File

@@ -30,7 +30,7 @@
"check-types": "tsc && vitest run --project types", "check-types": "tsc && vitest run --project types",
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test:unit": "vitest run --project unit", "test:unit": "vitest run --project unit --project unit-minimal",
"test:browsers": "vitest run --project browser", "test:browsers": "vitest run --project browser",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"
}, },

View File

@@ -27,9 +27,9 @@
"check-types": "tsc", "check-types": "tsc",
"lint": "biome check src/ test/", "lint": "biome check src/ test/",
"lint:fix": "yarn run lint --write", "lint:fix": "yarn run lint --write",
"test:unit": "vitest run --project unit --project unit-mainnet", "test:unit": "vitest run --project unit --project unit-minimal",
"test": "yarn test:unit && yarn test:e2e", "test": "yarn test:unit && yarn test:e2e",
"test:spec": "vitest run --project spec", "test:spec": "vitest run --project spec-minimal",
"test:e2e": "vitest run --project e2e --project e2e-mainnet", "test:e2e": "vitest run --project e2e --project e2e-mainnet",
"download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts", "download-spec-tests": "node --loader=ts-node/esm test/spec/downloadTests.ts",
"check-readme": "typescript-docs-verifier" "check-readme": "typescript-docs-verifier"

View File

@@ -2,7 +2,7 @@ import {getClient, routes} from "@lodestar/api";
import {createBeaconConfig} from "@lodestar/config"; import {createBeaconConfig} from "@lodestar/config";
import {config} from "@lodestar/config/default"; import {config} from "@lodestar/config/default";
import {genesisData} from "@lodestar/config/networks"; import {genesisData} from "@lodestar/config/networks";
import {ForkSeq} from "@lodestar/params"; import {ACTIVE_PRESET, ForkSeq, PresetName} from "@lodestar/params";
import {computeStartSlotAtEpoch, interopSecretKey, interopSecretKeys} from "@lodestar/state-transition"; import {computeStartSlotAtEpoch, interopSecretKey, interopSecretKeys} from "@lodestar/state-transition";
import {StartedExternalSigner, getKeystoresStr, startExternalSigner} from "@lodestar/test-utils"; import {StartedExternalSigner, getKeystoresStr, startExternalSigner} from "@lodestar/test-utils";
import {ssz, sszTypesFor} from "@lodestar/types"; import {ssz, sszTypesFor} from "@lodestar/types";
@@ -15,6 +15,10 @@ import {testLogger} from "../utils/logger.js";
describe("web3signer signature test", () => { describe("web3signer signature test", () => {
vi.setConfig({testTimeout: 60_000, hookTimeout: 60_000}); vi.setConfig({testTimeout: 60_000, hookTimeout: 60_000});
if (ACTIVE_PRESET !== PresetName.mainnet) {
throw Error(`ACTIVE_PRESET '${ACTIVE_PRESET}' must be mainnet`);
}
const altairSlot = 2375711; const altairSlot = 2375711;
const epoch = 0; const epoch = 0;
// Sample validator // Sample validator

Some files were not shown because too many files have changed in this diff Show More