Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Jan 16, 2024
1 parent 11f7898 commit 18f4544
Show file tree
Hide file tree
Showing 52 changed files with 185 additions and 257 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,8 @@ module.exports = {
extends: ["plugin:vitest/recommended"],
rules: {
"vitest/no-disabled-tests": "error",
"vitest/consistent-test-it": "error",
"vitest/consistent-test-it": ["error", {fn: "it", withinDescribe: "it"}],
"vitest/no-focused-tests": "error",
"vitest/no-duplicate-hooks": "error",
"vitest/prefer-called-with": "error",
"vitest/prefer-spy-on": "error",
// We use a lot dynamic assertions so tests may not have usage of expect
Expand Down
1 change: 1 addition & 0 deletions packages/api/test/perf/compileRouteUrlFormater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {compileRouteUrlFormater} from "../../src/utils/urlFormat.js";
/* eslint-disable no-console */

describe("route parse", () => {
// eslint-disable-next-line vitest/no-disabled-tests
it.skip("Benchmark compileRouteUrlFormater", () => {
const path = "/eth/v1/validator/:name/attester/:epoch";
const args = {epoch: 5, name: "HEAD"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("beacon state api", function () {
await bn.close();
});

describe("getEpochCommittees", async () => {
describe("getEpochCommittees", () => {
it("should return all committees for the given state", async () => {
const res = await client.getEpochCommittees("head");
ApiError.assert(res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe("lightclient api", function () {
expect(update.version).toBe(ForkName.altair);
});

// eslint-disable-next-line vitest/no-disabled-tests
it.skip("getFinalityUpdate()", async function () {
// TODO: not sure how this causes subsequent tests failed
await waitForEvent<phase0.Checkpoint>(bn.chain.emitter, routes.events.EventType.finalizedCheckpoint, 240000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const pyrmontDepositsDataRoot = [
];

// https://github.com/ChainSafe/lodestar/issues/5967
// eslint-disable-next-line vitest/no-disabled-tests
describe.skip("eth1 / Eth1Provider", function () {
const controller = new AbortController();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {getGoerliRpcUrl} from "../../testParams.js";
// It's OKAY to disable temporarily since this functionality is tested indirectly by the sim merge tests.
// See https://github.com/ChainSafe/lodestar/issues/4197
// https://github.com/ChainSafe/lodestar/issues/5967
// eslint-disable-next-line vitest/no-disabled-tests
describe.skip("eth1 / Eth1MergeBlockTracker", function () {
const logger = testLogger();

Expand Down
1 change: 1 addition & 0 deletions packages/beacon-node/test/e2e/eth1/eth1Provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Eth1Block} from "../../../src/eth1/interface.js";
import {getGoerliRpcUrl} from "../../testParams.js";

// https://github.com/ChainSafe/lodestar/issues/5967
// eslint-disable-next-line vitest/no-disabled-tests
describe.skip("eth1 / Eth1Provider", function () {
let controller: AbortController;
beforeEach(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/beacon-node/test/e2e/eth1/stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {getGoerliRpcUrl} from "../../testParams.js";
import {Eth1Options} from "../../../src/eth1/options.js";

// https://github.com/ChainSafe/lodestar/issues/5967
// eslint-disable-next-line vitest/no-disabled-tests
describe.skip("Eth1 streams", function () {
let controller: AbortController;
beforeEach(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/beacon-node/test/e2e/network/mdns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let port = 9000;
const mu = "/ip4/127.0.0.1/tcp/0";

// https://github.com/ChainSafe/lodestar/issues/5967
// eslint-disable-next-line vitest/no-disabled-tests
describe.skip("mdns", function () {
const afterEachCallbacks: (() => Promise<void> | void)[] = [];
afterEach(async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/e2e/network/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function runTests({useWorker}: {useWorker: boolean}): void {

// Current implementation of discv5 consumer doesn't allow to deterministically force a peer to be found
// a random find node lookup can yield no results if there are too few peers in the DHT
// it.skip("should connect to new peer by subnet", async function () {});
it.todo("should connect to new peer by subnet", async function () {});

it("Should goodbye peers on stop", async function () {
const [netA, netB] = await createTestNodesAB();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {CommitteeSubscription} from "../../../../src/network/subnets/interface.j
import {EchoWorker, getEchoWorker} from "./workerEchoHandler.js";

// TODO: Need to find the way to load the echoWorker in the test environment
// eslint-disable-next-line vitest/no-disabled-tests
describe.skip("data serialization through worker boundary", function () {
let echoWorker: EchoWorker;

Expand Down
47 changes: 0 additions & 47 deletions packages/beacon-node/test/e2e/network/reqresp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,53 +83,6 @@ function runTests({useWorker}: {useWorker: boolean}): void {
return [netA, netB, await getPeerIdOf(netA), await getPeerIdOf(netB)];
}

// it("should send/receive a ping message", async function () {
// const [netA, netB] = await createAndConnectPeers();

// // Modify the metadata to make the seqNumber non-zero
// netB.metadata.attnets = BitArray.fromBitLen(0);
// netB.metadata.attnets = BitArray.fromBitLen(0);
// const expectedPong = netB.metadata.seqNumber;
// expect(expectedPong.toString()).to.deep.equal("2", "seqNumber");

// const pong = await netA.reqResp.ping(peerIdB);
// expect(pong.toString()).to.deep.equal(expectedPong.toString(), "Wrong response body");
// });

// it("should send/receive a metadata message - altair", async function () {
// const [netA, netB] = await createAndConnectPeers();

// const metadata: altair.Metadata = {
// seqNumber: netB.metadata.seqNumber,
// attnets: netB.metadata.attnets,
// syncnets: netB.metadata.syncnets,
// };

// const receivedMetadata = await netA.reqResp.metadata(peerIdB);
// expect(receivedMetadata).to.deep.equal(metadata, "Wrong response body");
// });

// it("should send/receive a status message", async function () {
// const status: phase0.Status = {
// forkDigest: Buffer.alloc(4, 0),
// finalizedRoot: Buffer.alloc(32, 0),
// finalizedEpoch: 0,
// headRoot: Buffer.alloc(32, 0),
// headSlot: 0,
// };
// const statusNetA: phase0.Status = {...status, finalizedEpoch: 1};
// const statusNetB: phase0.Status = {...status, finalizedEpoch: 2};

// const [netA, netB] = await createAndConnectPeers({
// onStatus: async function* onRequest() {
// yield {data: ssz.phase0.Status.serialize(statusNetB), fork: ForkName.phase0};
// },
// });

// const receivedStatus = await netA.reqResp.status(peerIdB, statusNetA);
// expect(receivedStatus).to.deep.equal(statusNetB, "Wrong response body");
// });

it("should send/receive signed blocks", async function () {
const req: phase0.BeaconBlocksByRangeRequest = {startSlot: 0, step: 1, count: 2};
const blocks: phase0.SignedBeaconBlock[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const slotCount = endSlot - startSlot;
const timeoutInfura = 300_000;
const logger = testLogger();

// eslint-disable-next-line vitest/no-disabled-tests
describe.skip("verify+import blocks - range sync perf test", () => {
setBenchOpts({
yieldEventLoopAfterEach: true, // So SubTree(s)'s WeakRef can be garbage collected https://github.com/nodejs/node/issues/39902
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/test/spec/bls/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ for (const fnName of readdirSyncSpec(blsSpecTests.outputDir)) {
// Test format: https://github.com/ethereum/bls12-381-tests
if (testData.output === null) {
// Expect failure
expect(() => fn(testData.input) as never).to.throw();
expect(() => fn(testData.input) as never).toThrow();
} else {
// Expect success
expect(fn(testData.input)).to.deep.equals(testData.output);
expect(fn(testData.input)).toEqual(testData.output);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const epochProcessing =
if (testcase.post === undefined) {
// If post.ssz_snappy is not value, the sub-transition processing is aborted
// https://github.com/ethereum/consensus-specs/blob/dev/tests/formats/epoch_processing/README.md#postssz_snappy
expect(() => epochTransitionFn(state, epochTransitionCache)).to.throw();
expect(() => epochTransitionFn(state, epochTransitionCache)).toThrow();
} else {
epochTransitionFn(state, epochTransitionCache);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/beacon-node/test/spec/presets/fork_choice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ const forkChoiceTest =
const proposerBootRoot = (chain.forkChoice as ForkChoice).getProposerBoostRoot();

if (step.checks.head !== undefined) {
expect({slot: head.slot, root: head.blockRoot}).deep.equals(
expect({slot: head.slot, root: head.blockRoot}).toEqualWithMessage(
{slot: bnToNum(step.checks.head.slot), root: step.checks.head.root},
`Invalid head at step ${i}`
);
}
if (step.checks.proposer_boost_root !== undefined) {
expect(proposerBootRoot).to.be.equal(
expect(proposerBootRoot).toEqualWithMessage(
step.checks.proposer_boost_root,
`Invalid proposer boost root at step ${i}`
);
Expand All @@ -283,18 +283,18 @@ const forkChoiceTest =
// Compare in slots because proposer boost steps doesn't always come on
// slot boundary.
if (step.checks.time !== undefined && step.checks.time > 0)
expect(chain.forkChoice.getTime()).to.be.equal(
expect(chain.forkChoice.getTime()).toEqualWithMessage(
Math.floor(bnToNum(step.checks.time) / config.SECONDS_PER_SLOT),
`Invalid forkchoice time at step ${i}`
);
if (step.checks.justified_checkpoint) {
expect(toSpecTestCheckpoint(chain.forkChoice.getJustifiedCheckpoint())).to.be.deep.equal(
expect(toSpecTestCheckpoint(chain.forkChoice.getJustifiedCheckpoint())).toEqualWithMessage(
step.checks.justified_checkpoint,
`Invalid justified checkpoint at step ${i}`
);
}
if (step.checks.finalized_checkpoint) {
expect(toSpecTestCheckpoint(chain.forkChoice.getFinalizedCheckpoint())).to.be.deep.equal(
expect(toSpecTestCheckpoint(chain.forkChoice.getFinalizedCheckpoint())).toEqualWithMessage(
step.checks.finalized_checkpoint,
`Invalid finalized checkpoint at step ${i}`
);
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/spec/presets/genesis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const genesisValidity: TestRunnerFn<GenesisValidityTestCase, boolean> = (fork) =
},
getExpected: (testCase) => testCase.is_valid,
expectFunc: (testCase, expected, actual) => {
expect(actual).to.be.equal(expected, "isValidGenesisState is not" + expected);
expect(actual).toEqualWithMessage(expected, "isValidGenesisState is not" + expected);
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/test/spec/presets/merkle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const merkle: TestRunnerFn<MerkleTestCase, IProof> = (fork) => {
const leafIndex = Number(specTestProof.leaf_index);
const depth = Math.floor(Math.log2(leafIndex));
const verified = verifyMerkleBranch(leaf, branch, depth, leafIndex % 2 ** depth, stateRoot);
expect(verified).to.equal(true, "invalid merkle branch");
expect(verified).toEqualWithMessage(true, "invalid merkle branch");

const lodestarProof = new Tree(state.node).getProof({
gindex: specTestProof.leaf_index,
Expand All @@ -48,7 +48,7 @@ const merkle: TestRunnerFn<MerkleTestCase, IProof> = (fork) => {
timeout: 10000,
getExpected: (testCase) => testCase.proof,
expectFunc: (testCase, expected, actual) => {
expect(actual).to.be.deep.equal(expected, "incorrect proof");
expect(actual).toEqualWithMessage(expected, "incorrect proof");
},
// Do not manually skip tests here, do it in packages/beacon-node/test/spec/presets/index.test.ts
},
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/spec/presets/rewards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const rewards: TestRunnerFn<RewardTestCase, Deltas> = (fork) => {
testCase.inactivity_penalty_deltas,
]),
expectFunc: (testCase, expected, actual) => {
expect(actual).to.deep.equal(expected);
expect(actual).toEqual(expected);
},
// Do not manually skip tests here, do it in packages/beacon-node/test/spec/presets/index.test.ts
},
Expand Down
1 change: 1 addition & 0 deletions packages/beacon-node/test/spec/presets/ssz_static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const sszStatic =

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
// eslint-disable-next-line vitest/consistent-test-it
it(testCase, function () {
// Mainnet must deal with big full states and hash each one multiple times
if (ACTIVE_PRESET === "mainnet") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe("api - beacon - getBlockHeaders", function () {
vi.clearAllMocks();
});

// eslint-disable-next-line vitest/no-disabled-tests
it.skip("no filters - assume head slot", async function () {
server.forkChoiceStub.getHead.mockReturnValue(generateProtoBlock({slot: 1}));
when(server.chainStub.getCanonicalBlockAtSlot)
Expand Down Expand Up @@ -76,6 +77,7 @@ describe("api - beacon - getBlockHeaders", function () {
expect(blockHeaders.length).toBe(0);
});

// eslint-disable-next-line vitest/no-disabled-tests
it.skip("parent root filter - both finalized and non finalized results", async function () {
server.dbStub.blockArchive.getByParentRoot.mockResolvedValue(ssz.phase0.SignedBeaconBlock.defaultValue());
server.forkChoiceStub.getBlockSummariesByParentRoot.mockReturnValue([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe("beacon state api utils", function () {
});
});

describe("getStateValidatorIndex", async function () {
describe("getStateValidatorIndex", () => {
const state = generateCachedAltairState();
const pubkey2index = state.epochCtx.pubkey2index;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {MockedBeaconChain} from "../../../../../__mocks__/mockedBeaconChain.js";
import {MockedBeaconDb} from "../../../../../__mocks__/mockedBeaconDb.js";
import {MockedBeaconSync} from "../../../../../__mocks__/beaconSyncMock.js";

// eslint-disable-next-line vitest/no-disabled-tests
describe.skip("get proposers api impl", function () {
const logger = testLogger();

Expand Down Expand Up @@ -73,9 +74,9 @@ describe.skip("get proposers api impl", function () {
const {data: result} = await api.getProposerDuties(1);
expect(result.length).toBe(SLOTS_PER_EPOCH);
// "stubGetBeaconProposer function should not have been called"
expect(stubGetNextBeaconProposer).toHaveBeenCalled();
expect(stubGetNextBeaconProposer).toHaveBeenCalledWith();
// "stubGetBeaconProposer function should have been called"
expect(stubGetBeaconProposer).not.toHaveBeenCalled();
expect(stubGetBeaconProposer).not.toHaveBeenCalledWith();
});

it("should have different proposer for current and next epoch", async function () {
Expand Down Expand Up @@ -125,6 +126,6 @@ describe.skip("get proposers api impl", function () {
chainStub.getHeadStateAtCurrentEpoch.mockResolvedValue(cachedState);
const stubGetBeaconProposer = vi.spyOn(cachedState.epochCtx, "getBeaconProposer");
await expect(stubGetBeaconProposer).rejects.toThrow();
await expect(api.getProposerDuties(2), "calling getProposerDuties should throw").rejects.toThrow();
await expect(api.getProposerDuties(2)).rejects.toThrow();
});
});
4 changes: 2 additions & 2 deletions packages/beacon-node/test/unit/chain/bls/bls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("BlsVerifier ", function () {
it("should return false if at least one signature is malformed", async () => {
// signature is malformed
const malformedSignature = Buffer.alloc(96, 10);
expect(() => bls.Signature.fromBytes(malformedSignature, CoordType.affine, true)).to.throws();
expect(() => bls.Signature.fromBytes(malformedSignature, CoordType.affine, true)).toThrow();
sets[1].signature = malformedSignature;
expect(await verifier.verifySignatureSets(sets)).toBe(false);
});
Expand Down Expand Up @@ -79,7 +79,7 @@ describe("BlsVerifier ", function () {
it("should return false for malformed signature", async () => {
// signature is malformed
const malformedSignature = Buffer.alloc(96, 10);
expect(() => bls.Signature.fromBytes(malformedSignature, CoordType.affine, true)).to.throws();
expect(() => bls.Signature.fromBytes(malformedSignature, CoordType.affine, true)).toThrow();
sets[1].signature = malformedSignature;
expect(await verifier.verifySignatureSetsSameMessage(sets, signingRoot)).toEqual([true, false, true]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe("LodestarForkChoice", function () {
* \
* parent (37) - child (38)
*/
// eslint-disable-next-line vitest/no-disabled-tests
it.skip("getHead - should not consider orphaned block as head", () => {
const {blockHeader} = computeAnchorCheckpoint(config, anchorState);
const finalizedRoot = ssz.phase0.BeaconBlockHeader.hashTreeRoot(blockHeader);
Expand Down Expand Up @@ -231,6 +232,7 @@ describe("LodestarForkChoice", function () {
*
* To simplify, go with epoch 0, 1, 2 instead of 9, 10, 11
*/
// eslint-disable-next-line vitest/no-disabled-tests
it.skip("should not filter blocks with unrealized checkpoints = store checkpoints", () => {
const blockDelaySec = 0;
// C9 is the justified/finalized block
Expand Down
Loading

0 comments on commit 18f4544

Please sign in to comment.