Skip to content

Commit

Permalink
Update test related dependencies (#4605)
Browse files Browse the repository at this point in the history
* Update tar and relevant types

* Update lerna and electron

* Update the relevant lock files

* Update critical dependenceis

* Update some deps for node-forge

* Fix the failing unit test

* Remove the skipped test

* Fix the uint8arrays version to 3.0.0 to avoid a breaking change introduced in 3.1.0
achingbrain/uint8arrays#38

* Update the test dependencies

* Add support for bigint comparision

* Update eslint configurations

* Update tests and assertions

* Update few packages missed in merge conflicts

* Fix utils package test config

* Fix failing tests

* Fix lint errors

* Update the failing unit test

* Fix perf test

* Remove chai-bigint as chai does not support bigint yet

* Fix failing tests for validator

* Revert changes to enforce max-top-level-describe

* Revert change of exported functions

* Revert a change for max top level describe limit

* Revert a change for max top level describe limit

* Fix lint warnings
  • Loading branch information
nazarhussain committed Oct 1, 2022
1 parent 631b6e7 commit 82ea295
Show file tree
Hide file tree
Showing 87 changed files with 580 additions and 709 deletions.
27 changes: 23 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
project: "./tsconfig.json",
sourceType: "module",
},
plugins: ["@typescript-eslint", "eslint-plugin-import", "@chainsafe/eslint-plugin-node", "no-only-tests", "prettier"],
plugins: ["@typescript-eslint", "eslint-plugin-import", "@chainsafe/eslint-plugin-node", "prettier"],
extends: [
"eslint:recommended",
"plugin:import/errors",
Expand Down Expand Up @@ -161,9 +161,6 @@ module.exports = {
// Force to add names to all functions to ease CPU profiling
"func-names": ["error", "always"],

// Prevents accidentally pushing a commit with .only in Mocha tests
"no-only-tests/no-only-tests": "error",

// TEMP Disabled while eslint-plugin-import support ESM (Typescript does support it) https://github.com/import-js/eslint-plugin-import/issues/2170
"import/no-unresolved": "off",

Expand Down Expand Up @@ -209,6 +206,28 @@ module.exports = {
"func-names": "off",
},
},
{
files: ["**/test/**/*.test.ts"],
plugins: ["mocha", "chai-expect"],
extends: ["plugin:mocha/recommended", "plugin:chai-expect/recommended"],
rules: {
// Use of arrow functions are very common
"mocha/no-mocha-arrows": "off",
// It's common to call function inside describe block
// https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-setup-in-describe.md
"mocha/no-setup-in-describe": "off",
// We use to split before in small isolated tasks
// https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-sibling-hooks.md
"mocha/no-sibling-hooks": "off",
// We need to disable because we disabled "mocha/no-setup-in-describe" rule
// TODO: Move all setup code to before/beforeEach and then disable async describe
// https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-async-describe.md
"mocha/no-async-describe": "off",
// We observed that having multiple top level "describe" save valuable indentation
// https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/max-top-level-suites.md
"mocha/max-top-level-suites": "off",
},
},
{
files: ["**/types/**/*.ts"],
rules: {
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,52 +37,52 @@
"devDependencies": {
"@chainsafe/eslint-plugin-node": "^11.2.3",
"@dapplion/benchmark": "^0.2.2",
"@types/chai": "4.2.0",
"@types/chai-as-promised": "^7.1.2",
"@types/mocha": "^8.0.3",
"@types/node": "^18.6.1",
"@types/sinon": "^9.0.0",
"@types/chai": "^4.3.3",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^10.0.0",
"@types/node": "^18.7.23",
"@types/sinon": "^10.0.13",
"@types/sinon-chai": "^3.2.8",
"@typescript-eslint/eslint-plugin": "5.26.0",
"@typescript-eslint/parser": "5.26.0",
"chai": "^4.2.0",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"codecov": "^3.8.3",
"crypto-browserify": "^3.12.0",
"electron": "^20.2.0",
"electron": "^21.0.1",
"eslint": "^8.16.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-no-only-tests": "^2.6.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-chai-expect": "^3.0.0",
"eslint-plugin-mocha": "^10.1.0",
"https-browserify": "^1.0.0",
"karma": "^6.4.0",
"karma": "^6.4.1",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.1",
"karma-cli": "^2.0.0",
"karma-electron": "^7.2.0",
"karma-electron": "^7.3.0",
"karma-firefox-launcher": "^2.1.2",
"karma-mocha": "^2.0.1",
"karma-spec-reporter": "^0.0.34",
"karma-webpack": "^5.0.0",
"lerna": "^5.5.2",
"mocha": "^9.2.2",
"mocha": "^10.0.0",
"node-gyp": "^9.0.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"path-browserify": "^1.0.1",
"prettier": "^2.0.5",
"process": "^0.11.10",
"resolve-typescript-plugin": "^1.2.0",
"sinon": "^9.0.2",
"sinon": "^14.0.0",
"sinon-chai": "^3.7.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"supertest": "^4.0.2",
"supertest": "^6.2.4",
"ts-loader": "^9.3.1",
"ts-node": "^10.9.1",
"typescript": "4.7.4",
"typescript-docs-verifier": "^2.3.0",
"webpack": "^5.74.0"
},
"dependencies": {}
}
}
5 changes: 1 addition & 4 deletions packages/api/test/unit/client/httpClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {IncomingMessage} from "node:http";
import chai, {expect} from "chai";
import chaiAsPromised from "chai-as-promised";
import {expect} from "chai";
import fastify, {RouteOptions} from "fastify";
import {ErrorAborted, TimeoutError} from "@lodestar/utils";
import {HttpClient, HttpError} from "../../../src/utils/client/index.js";

chai.use(chaiAsPromised);

interface IUser {
id?: number;
name: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/.mocharc.spec.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

module.exports = {
colors: true,
require: ["./test/setupPreset.ts"],
require: ["./test/setupPreset.ts", "./test/setup.ts"],
"node-option": [
"loader=ts-node/esm"
],
Expand Down
1 change: 1 addition & 0 deletions packages/beacon-node/.mocharc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
colors: true
require:
- ./test/setupPreset.ts
- ./test/setup.ts
timeout: 5000
exit: true
extension: ["ts"]
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface INetwork {
/** Subscribe, search peers, join long-lived syncnets */
prepareSyncCommitteeSubnets(subscriptions: CommitteeSubscription[]): void;
reStatusPeers(peers: PeerId[]): void;
reportPeer(peer: PeerId, action: PeerAction, actionName?: string): void;
reportPeer(peer: PeerId, action: PeerAction, actionName: string): void;

// Gossip handler
subscribeGossipCoreTopics(): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import chaiAsPromised from "chai-as-promised";
import chai, {expect} from "chai";
import {expect} from "chai";
import {createIBeaconConfig, IChainConfig} from "@lodestar/config";
import {chainConfig as chainConfigDef} from "@lodestar/config/default";
import {getClient} from "@lodestar/api";
Expand All @@ -8,8 +7,6 @@ import {LogLevel, testLogger, TestLoggerOpts} from "../../../../../utils/logger.
import {getDevBeaconNode} from "../../../../../utils/node/beacon.js";
import {getAndInitDevValidators} from "../../../../../utils/node/validator.js";

chai.use(chaiAsPromised);

/* eslint-disable @typescript-eslint/naming-convention */
describe("lodestar / api / impl / state", function () {
const SECONDS_PER_SLOT = 2;
Expand Down
5 changes: 1 addition & 4 deletions packages/beacon-node/test/e2e/api/lodestar/lodestar.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import chaiAsPromised from "chai-as-promised";
import chai, {expect} from "chai";
import {expect} from "chai";
import {createIBeaconConfig, IChainConfig} from "@lodestar/config";
import {chainConfig as chainConfigDef} from "@lodestar/config/default";
import {phase0} from "@lodestar/types";
Expand All @@ -10,8 +9,6 @@ import {getDevBeaconNode} from "../../../utils/node/beacon.js";
import {waitForEvent} from "../../../utils/events/resolver.js";
import {ChainEvent} from "../../../../src/chain/index.js";

chai.use(chaiAsPromised);

describe("api / impl / validator", function () {
describe("getLiveness endpoint", function () {
const SECONDS_PER_SLOT = 2;
Expand Down
5 changes: 1 addition & 4 deletions packages/beacon-node/test/e2e/chain/bls/multithread.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import chai, {expect} from "chai";
import chaiAsPromised from "chai-as-promised";
import {expect} from "chai";
import bls from "@chainsafe/bls";
import {ISignatureSet, SignatureSetType} from "@lodestar/state-transition";
import {BlsMultiThreadWorkerPool} from "../../../../src/chain/bls/multithread/index.js";
import {testLogger} from "../../../utils/logger.js";
import {VerifySignatureOpts} from "../../../../src/chain/bls/interface.js";

chai.use(chaiAsPromised);

describe("chain / bls / multithread queue", function () {
this.timeout(30 * 1000);
const logger = testLogger();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import chai, {expect} from "chai";
import chaiAsPromised from "chai-as-promised";
import {expect} from "chai";
import {routes} from "@lodestar/api/beacon";
import {BLSPubkey, phase0, Slot, ssz} from "@lodestar/types";
import {IChainConfig} from "@lodestar/config";
Expand All @@ -17,8 +16,6 @@ import {waitForEvent} from "../../utils/events/resolver.js";
import {generateAttestationData} from "../../utils/attestation.js";
import {BeaconNode} from "../../../src/node/index.js";

chai.use(chaiAsPromised);

/* eslint-disable @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
// TODO: Reconsider this tests latter.
// Doppelganger testing can be split in two items:
Expand Down
16 changes: 8 additions & 8 deletions packages/beacon-node/test/e2e/eth1/eth1MergeBlockTracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ describe.skip("eth1 / Eth1MergeBlockTracker", function () {
// Given the total difficulty offset the block that has TTD is the `difficultyOffset`nth block
const mergeBlock = await eth1MergeBlockTracker.getTerminalPowBlock();
if (!mergeBlock) throw Error("mergeBlock not found");
expect(mergeBlock.totalDifficulty >= terminalTotalDifficulty).to.equal(
true,
"mergeBlock.totalDifficulty is not >= TTD"
);
// Chai does not support bigint comparison
// eslint-disable-next-line chai-expect/no-inner-compare
expect(mergeBlock.totalDifficulty >= terminalTotalDifficulty, "mergeBlock.totalDifficulty is not >= TTD").to.be
.true;
});

it("Should find merge block fetching past blocks", async () => {
Expand Down Expand Up @@ -148,9 +148,9 @@ describe.skip("eth1 / Eth1MergeBlockTracker", function () {
// Given the total difficulty offset the block that has TTD is the `difficultyOffset`nth block
const mergeBlock = await eth1MergeBlockTracker.getTerminalPowBlock();
if (!mergeBlock) throw Error("mergeBlock not found");
expect(mergeBlock.totalDifficulty >= terminalTotalDifficulty).to.equal(
true,
"mergeBlock.totalDifficulty is not >= TTD"
);
// Chai does not support bigint comparison
// eslint-disable-next-line chai-expect/no-inner-compare
expect(mergeBlock.totalDifficulty >= terminalTotalDifficulty, "mergeBlock.totalDifficulty is not >= TTD").to.be
.true;
});
});
7 changes: 2 additions & 5 deletions packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import "mocha";
import crypto from "node:crypto";
import http from "node:http";
import chai, {expect} from "chai";
import chaiAsPromised from "chai-as-promised";
import {expect} from "chai";
import {JsonRpcHttpClient} from "../../../src/eth1/provider/jsonRpcHttpClient.js";
import {getGoerliRpcUrl} from "../../testParams.js";
import {IRpcPayload} from "../../../src/eth1/interface.js";

chai.use(chaiAsPromised);

describe("eth1 / jsonRpcHttpClient", function () {
this.timeout("10 seconds");

Expand Down Expand Up @@ -156,7 +153,7 @@ describe("eth1 / jsonRpcHttpClient", function () {
}
});

describe("eth1 / jsonRpcHttpClient - with retries", async function () {
describe("eth1 / jsonRpcHttpClient - with retries", function () {
this.timeout("10 seconds");
const port = 36421;
const noMethodError = {code: -32601, message: "Method not found"};
Expand Down
24 changes: 0 additions & 24 deletions packages/beacon-node/test/e2e/network/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,30 +217,6 @@ describe("network", function () {
expect(goodbye).to.equal(BigInt(GoodByeReasonCode.CLIENT_SHUTDOWN), "goodbye reason must be CLIENT_SHUTDOWN");
});

it("Should goodbye peers on stop", async function () {
const [{network: netA}, {network: netB}] = await createTestNodesAB();

const connected = Promise.all([onPeerConnect(netA), onPeerConnect(netB)]);
await connect(netA, netB.peerId, netB.localMultiaddrs);
await connected;

// Wait some time and stop netA expecting to goodbye netB
await sleep(500, controller.signal);

const onGoodbyeNetB = sinon.stub<[phase0.Goodbye, PeerId]>();
netB.events.on(NetworkEvent.reqRespRequest, (request, peer) => {
if (request.method === ReqRespMethod.Goodbye) onGoodbyeNetB(request.body, peer);
});

await netA.stop();
await sleep(500, controller.signal);

expect(onGoodbyeNetB.callCount).to.equal(1, "netB must receive 1 goodbye");
const [goodbye, peer] = onGoodbyeNetB.getCall(0).args;
expect(peer.toString()).to.equal(netA.peerId.toString(), "netA must be the goodbye requester");
expect(goodbye).to.equal(BigInt(GoodByeReasonCode.CLIENT_SHUTDOWN), "goodbye reason must be CLIENT_SHUTDOWN");
});

it("Should subscribe to gossip core topics on demand", async () => {
const {network: netA} = await createTestNode("A");

Expand Down
5 changes: 1 addition & 4 deletions packages/beacon-node/test/e2e/network/reqresp.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import chai, {expect} from "chai";
import chaiAsPromised from "chai-as-promised";
import {expect} from "chai";
import {PeerId} from "@libp2p/interface-peer-id";
import {createSecp256k1PeerId} from "@libp2p/peer-id-factory";
import {createIBeaconConfig} from "@lodestar/config";
Expand Down Expand Up @@ -29,8 +28,6 @@ import {connect, onPeerConnect} from "../../utils/network.js";
import {StubbedBeaconDb} from "../../utils/stub/index.js";
import {GossipHandlers} from "../../../src/network/gossip/index.js";

chai.use(chaiAsPromised);

/* eslint-disable require-yield, @typescript-eslint/naming-convention */

describe("network / ReqResp", function () {
Expand Down
5 changes: 1 addition & 4 deletions packages/beacon-node/test/e2e/sync/endpoint.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import chaiAsPromised from "chai-as-promised";
import chai, {expect} from "chai";
import {expect} from "chai";
import {createIBeaconConfig, IChainConfig} from "@lodestar/config";
import {chainConfig as chainConfigDef} from "@lodestar/config/default";
import {getClient, routes} from "@lodestar/api";
import {getDevBeaconNode} from "../../utils/node/beacon.js";
import {LogLevel, testLogger, TestLoggerOpts} from "../../utils/logger.js";

chai.use(chaiAsPromised);

/* eslint-disable @typescript-eslint/naming-convention */
describe("lodestar / sync", function () {
const SECONDS_PER_SLOT = 2;
Expand Down
6 changes: 6 additions & 0 deletions packages/beacon-node/test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import chai from "chai";
import chaiAsPromised from "chai-as-promised";
import sinonChai from "sinon-chai";

chai.use(chaiAsPromised);
chai.use(sinonChai);
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import chai, {expect} from "chai";
import chaiAsPromised from "chai-as-promised";
import {expect} from "chai";
import varint from "varint";
import {Uint8ArrayList} from "uint8arraylist";
import {BufferedSource} from "../../../../../../src/network/reqresp/utils/index.js";
Expand All @@ -8,8 +7,6 @@ import {isEqualSszType} from "../../../../../utils/ssz.js";
import {arrToSource} from "../../../../../../test/unit/network/reqresp/utils.js";
import {goerliShadowForkBlock13249} from "./testData.js";

chai.use(chaiAsPromised);

describe("network / reqresp / sszSnappy / decode", () => {
describe("Test data vectors (generated in a previous version)", () => {
const testCases = [goerliShadowForkBlock13249];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ describe("api - beacon - getBlockHeaders", function () {
expect(blockHeaders).to.not.be.null;
expect(blockHeaders.length).to.be.equal(2);
expect(blockHeaders.filter((header) => header.canonical).length).to.be.equal(1);
expect(server.forkChoiceStub.getHead.calledOnce).to.equal(true);
expect(server.chainStub.getCanonicalBlockAtSlot.calledOnce).to.equal(true);
expect(server.forkChoiceStub.getBlockSummariesAtSlot.calledOnce).to.equal(true);
expect(server.dbStub.block.get.calledOnce).to.equal(true);
expect(server.forkChoiceStub.getHead).to.be.calledOnce;
expect(server.chainStub.getCanonicalBlockAtSlot).to.be.calledOnce;
expect(server.forkChoiceStub.getBlockSummariesAtSlot).to.be.calledOnce;
expect(server.dbStub.block.get).to.be.calledOnce;
});

it("future slot", async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("api - beacon - publishBlock", function () {

syncStub.isSynced.returns(true);
await expect(blockApi.publishBlock(block)).to.be.fulfilled;
expect(chainStub.processBlock.calledOnceWith(block)).to.equal(true);
expect(gossipStub.publishBeaconBlock.calledOnceWith(block)).to.equal(true);
expect(chainStub.processBlock).to.be.calledOnceWith(block);
expect(gossipStub.publishBeaconBlock).to.be.calledOnceWith(block);
});
});

0 comments on commit 82ea295

Please sign in to comment.