Skip to content

Commit

Permalink
deps: update vitest to latest version (#6967)
Browse files Browse the repository at this point in the history
* Upgrade vitest

* --segfault-retry removed from vitest

* Fix the vitest config

* Fix deprecated syntax

* Fix types

* Add a patch for browser tests

* Update build config

* Revert changes from bundle

* Fix the e2e tests context

* Fix the e2e tests

* Fix the e2e callback hooks

* Fix callback hooks

---------

Co-authored-by: Cayman <caymannava@gmail.com>
  • Loading branch information
nazarhussain and wemeetagain authored Aug 1, 2024
1 parent 12e1871 commit 5b0608a
Show file tree
Hide file tree
Showing 29 changed files with 1,499 additions and 1,326 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"@types/node": "^20.12.8",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitest/browser": "^1.6.0",
"@vitest/coverage-v8": "^1.6.0",
"@vitest/browser": "^2.0.4",
"@vitest/coverage-v8": "^2.0.4",
"crypto-browserify": "^3.12.0",
"dotenv": "^16.4.5",
"electron": "^26.2.2",
Expand All @@ -81,20 +81,20 @@
"ts-node": "^10.9.2",
"typescript": "^5.4.2",
"typescript-docs-verifier": "^2.5.0",
"vite": "^5.2.11",
"vite": "^5.3.4",
"vite-plugin-dts": "^3.9.1",
"vite-plugin-node-polyfills": "^0.21.0",
"vite-plugin-top-level-await": "^1.4.1",
"vitest": "^1.6.0",
"vitest-when": "^0.3.1",
"vite-plugin-node-polyfills": "^0.22.0",
"vite-plugin-top-level-await": "^1.4.2",
"vitest": "^2.0.4",
"vitest-when": "^0.4.1",
"wait-port": "^1.1.0",
"webdriverio": "^8.36.1"
},
"resolutions": {
"@puppeteer/browsers": "^2.1.0",
"dns-over-http-resolver": "^2.1.1",
"loupe": "^2.3.6",
"vite": "^5.2.11",
"vite": "^5.3.4",
"testcontainers/**/nan": "^2.19.0"
}
}
2 changes: 1 addition & 1 deletion packages/api/test/unit/client/httpClientFallback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("httpClient fallback", () => {

// Using fetchSub instead of actually setting up servers because there are some strange
// race conditions, where the server stub doesn't count the call in time before the test is over.
const fetchStub = vi.fn<Parameters<typeof fetch>, ReturnType<typeof fetch>>();
const fetchStub = vi.fn<(...args: Parameters<typeof fetch>) => ReturnType<typeof fetch>>();

let httpClient: HttpClient;

Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
"lint": "eslint --color --ext .ts src/ test/",
"lint:fix": "yarn run lint --fix",
"test": "yarn test:unit && yarn test:e2e",
"test:unit:minimal": "LODESTAR_PRESET=minimal vitest --run --segfaultRetry 3 --dir test/unit/",
"test:unit:mainnet": "LODESTAR_PRESET=mainnet vitest --run --segfaultRetry 3 --dir test/unit-mainnet",
"test:unit:minimal": "LODESTAR_PRESET=minimal vitest --run --dir test/unit/",
"test:unit:mainnet": "LODESTAR_PRESET=mainnet vitest --run --dir test/unit-mainnet",
"test:unit": "wrapper() { yarn test:unit:minimal $@ && yarn test:unit:mainnet $@; }; wrapper",
"test:e2e": "LODESTAR_PRESET=minimal vitest --run --segfaultRetry 3 --config vitest.e2e.config.ts --dir test/e2e",
"test:e2e": "LODESTAR_PRESET=minimal vitest --run --config vitest.e2e.config.ts --dir test/e2e",
"test:sim": "vitest --run test/sim/**/*.test.ts",
"test:sim:mergemock": "vitest --run test/sim/mergemock.test.ts",
"test:sim:blobs": "vitest --run test/sim/4844-interop.test.ts",
Expand Down
227 changes: 112 additions & 115 deletions packages/beacon-node/test/e2e/chain/proposerBoostReorg.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, afterEach, expect} from "vitest";
import {describe, it, afterEach, expect, vi} from "vitest";
import {SLOTS_PER_EPOCH} from "@lodestar/params";
import {TimestampFormatCode} from "@lodestar/logger";
import {ChainConfig} from "@lodestar/config";
Expand All @@ -12,125 +12,122 @@ import {getAndInitDevValidators} from "../../utils/node/validator.js";
import {waitForEvent} from "../../utils/events/resolver.js";
import {ReorgEventData} from "../../../src/chain/emitter.js";

describe(
"proposer boost reorg",
function () {
const validatorCount = 8;
const testParams: Pick<ChainConfig, "SECONDS_PER_SLOT" | "REORG_PARENT_WEIGHT_THRESHOLD" | "PROPOSER_SCORE_BOOST"> =
{
// eslint-disable-next-line @typescript-eslint/naming-convention
SECONDS_PER_SLOT: 2,
// need this to make block `reorgSlot - 1` strong enough
// eslint-disable-next-line @typescript-eslint/naming-convention
REORG_PARENT_WEIGHT_THRESHOLD: 80,
// need this to make block `reorgSlot + 1` to become the head
// eslint-disable-next-line @typescript-eslint/naming-convention
PROPOSER_SCORE_BOOST: 120,
};
describe("proposer boost reorg", function () {
vi.setConfig({testTimeout: 60000});

const afterEachCallbacks: (() => Promise<unknown> | void)[] = [];
afterEach(async () => {
while (afterEachCallbacks.length > 0) {
const callback = afterEachCallbacks.pop();
if (callback) await callback();
}
});
const validatorCount = 8;
const testParams: Pick<ChainConfig, "SECONDS_PER_SLOT" | "REORG_PARENT_WEIGHT_THRESHOLD" | "PROPOSER_SCORE_BOOST"> = {
// eslint-disable-next-line @typescript-eslint/naming-convention
SECONDS_PER_SLOT: 2,
// need this to make block `reorgSlot - 1` strong enough
// eslint-disable-next-line @typescript-eslint/naming-convention
REORG_PARENT_WEIGHT_THRESHOLD: 80,
// need this to make block `reorgSlot + 1` to become the head
// eslint-disable-next-line @typescript-eslint/naming-convention
PROPOSER_SCORE_BOOST: 120,
};

const reorgSlot = 10;
const proposerBoostReorg = true;
/**
* reorgSlot
* /
* reorgSlot - 1 ------------ reorgSlot + 1
*
* Note that in addition of being not timely, there are other criterion that
* the block needs to satisfy before being re-orged out. This test assumes
* other criterion are already satisfied
*/
it(`should reorg a late block at slot ${reorgSlot}`, async () => {
// the node needs time to transpile/initialize bls worker threads
const genesisSlotsDelay = 7;
const genesisTime = Math.floor(Date.now() / 1000) + genesisSlotsDelay * testParams.SECONDS_PER_SLOT;
const testLoggerOpts: TestLoggerOpts = {
level: LogLevel.debug,
timestampFormat: {
format: TimestampFormatCode.EpochSlot,
genesisTime,
slotsPerEpoch: SLOTS_PER_EPOCH,
secondsPerSlot: testParams.SECONDS_PER_SLOT,
},
};
const logger = testLogger("BeaconNode", testLoggerOpts);
const bn = await getDevBeaconNode({
params: testParams,
options: {
sync: {isSingleNode: true},
network: {allowPublishToZeroPeers: true, mdns: true, useWorker: false},
chain: {
blsVerifyAllMainThread: true,
forkchoiceConstructor: TimelinessForkChoice,
proposerBoost: true,
proposerBoostReorg,
},
},
validatorCount,
const afterEachCallbacks: (() => Promise<unknown> | void)[] = [];
afterEach(async () => {
while (afterEachCallbacks.length > 0) {
const callback = afterEachCallbacks.pop();
if (callback) await callback();
}
});

const reorgSlot = 10;
const proposerBoostReorg = true;
/**
* reorgSlot
* /
* reorgSlot - 1 ------------ reorgSlot + 1
*
* Note that in addition of being not timely, there are other criterion that
* the block needs to satisfy before being re-orged out. This test assumes
* other criterion are already satisfied
*/
it(`should reorg a late block at slot ${reorgSlot}`, async () => {
// the node needs time to transpile/initialize bls worker threads
const genesisSlotsDelay = 7;
const genesisTime = Math.floor(Date.now() / 1000) + genesisSlotsDelay * testParams.SECONDS_PER_SLOT;
const testLoggerOpts: TestLoggerOpts = {
level: LogLevel.debug,
timestampFormat: {
format: TimestampFormatCode.EpochSlot,
genesisTime,
logger,
});
slotsPerEpoch: SLOTS_PER_EPOCH,
secondsPerSlot: testParams.SECONDS_PER_SLOT,
},
};
const logger = testLogger("BeaconNode", testLoggerOpts);
const bn = await getDevBeaconNode({
params: testParams,
options: {
sync: {isSingleNode: true},
network: {allowPublishToZeroPeers: true, mdns: true, useWorker: false},
chain: {
blsVerifyAllMainThread: true,
forkchoiceConstructor: TimelinessForkChoice,
proposerBoost: true,
proposerBoostReorg,
},
},
validatorCount,
genesisTime,
logger,
});

(bn.chain.forkChoice as TimelinessForkChoice).lateSlot = reorgSlot;
afterEachCallbacks.push(async () => bn.close());
const {validators} = await getAndInitDevValidators({
node: bn,
logPrefix: "vc-0",
validatorsPerClient: validatorCount,
validatorClientCount: 1,
startIndex: 0,
useRestApi: false,
testLoggerOpts,
});
afterEachCallbacks.push(() => Promise.all(validators.map((v) => v.close())));
(bn.chain.forkChoice as TimelinessForkChoice).lateSlot = reorgSlot;
afterEachCallbacks.push(async () => bn.close());
const {validators} = await getAndInitDevValidators({
node: bn,
logPrefix: "vc-0",
validatorsPerClient: validatorCount,
validatorClientCount: 1,
startIndex: 0,
useRestApi: false,
testLoggerOpts,
});
afterEachCallbacks.push(() => Promise.all(validators.map((v) => v.close())));

const commonAncestor = await waitForEvent<{slot: Slot; block: RootHex}>(
bn.chain.emitter,
routes.events.EventType.head,
240000,
({slot}) => slot === reorgSlot - 1
);
// reorgSlot
// /
// commonAncestor ------------ newBlock
const commonAncestorRoot = commonAncestor.block;
const reorgBlockEventData = await waitForEvent<{slot: Slot; block: RootHex}>(
const commonAncestor = await waitForEvent<{slot: Slot; block: RootHex}>(
bn.chain.emitter,
routes.events.EventType.head,
240000,
({slot}) => slot === reorgSlot - 1
);
// reorgSlot
// /
// commonAncestor ------------ newBlock
const commonAncestorRoot = commonAncestor.block;
const reorgBlockEventData = await waitForEvent<{slot: Slot; block: RootHex}>(
bn.chain.emitter,
routes.events.EventType.head,
240000,
({slot}) => slot === reorgSlot
);
const reorgBlockRoot = reorgBlockEventData.block;
const [newBlockEventData, reorgEventData] = await Promise.all([
waitForEvent<{slot: Slot; block: RootHex}>(
bn.chain.emitter,
routes.events.EventType.head,
routes.events.EventType.block,
240000,
({slot}) => slot === reorgSlot
);
const reorgBlockRoot = reorgBlockEventData.block;
const [newBlockEventData, reorgEventData] = await Promise.all([
waitForEvent<{slot: Slot; block: RootHex}>(
bn.chain.emitter,
routes.events.EventType.block,
240000,
({slot}) => slot === reorgSlot + 1
),
waitForEvent<ReorgEventData>(bn.chain.emitter, routes.events.EventType.chainReorg, 240000),
]);
expect(reorgEventData.slot).toEqual(reorgSlot + 1);
const newBlock = await bn.chain.getBlockByRoot(newBlockEventData.block);
if (newBlock == null) {
throw Error(`Block ${reorgSlot + 1} not found`);
}
expect(reorgEventData.oldHeadBlock).toEqual(reorgBlockRoot);
expect(reorgEventData.newHeadBlock).toEqual(newBlockEventData.block);
expect(reorgEventData.depth).toEqual(2);
expect(toHexString(newBlock?.block.message.parentRoot)).toEqual(commonAncestorRoot);
logger.info("New block", {
slot: newBlock.block.message.slot,
parentRoot: toHexString(newBlock.block.message.parentRoot),
});
({slot}) => slot === reorgSlot + 1
),
waitForEvent<ReorgEventData>(bn.chain.emitter, routes.events.EventType.chainReorg, 240000),
]);
expect(reorgEventData.slot).toEqual(reorgSlot + 1);
const newBlock = await bn.chain.getBlockByRoot(newBlockEventData.block);
if (newBlock == null) {
throw Error(`Block ${reorgSlot + 1} not found`);
}
expect(reorgEventData.oldHeadBlock).toEqual(reorgBlockRoot);
expect(reorgEventData.newHeadBlock).toEqual(newBlockEventData.block);
expect(reorgEventData.depth).toEqual(2);
expect(toHexString(newBlock?.block.message.parentRoot)).toEqual(commonAncestorRoot);
logger.info("New block", {
slot: newBlock.block.message.slot,
parentRoot: toHexString(newBlock.block.message.parentRoot),
});
},
{timeout: 60000}
);
});
});
Loading

0 comments on commit 5b0608a

Please sign in to comment.