From 46536b657ed0c631a09c2333647dcbd728d54833 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Mon, 1 Jul 2024 15:18:12 +0700 Subject: [PATCH] fix: lint --- packages/persistent-merkle-tree/package.json | 1 + .../src/hasher/as-sha256.ts | 15 ++++- .../src/hasher/hashtree.ts | 10 ++-- .../src/hasher/noble.ts | 2 +- .../src/hasher/types.ts | 2 +- packages/persistent-merkle-tree/src/tree.ts | 3 +- packages/ssz/src/type/byteArray.ts | 4 +- packages/ssz/src/type/containerNodeStruct.ts | 6 +- packages/ssz/src/type/optional.ts | 4 +- packages/ssz/src/type/union.ts | 4 +- packages/ssz/src/viewDU/arrayBasic.ts | 10 +++- packages/ssz/src/viewDU/container.ts | 10 +++- .../lodestarTypes/phase0/listValidator.ts | 12 ++-- .../test/lodestarTypes/phase0/validator.ts | 2 +- .../phase0/viewDU/listValidator.ts | 16 +++--- .../lodestarTypes/phase0/viewDU/validator.ts | 55 ++++++++++--------- .../ssz/test/perf/eth2/hashTreeRoot.test.ts | 2 +- .../ssz/test/perf/eth2/validators.test.ts | 7 +-- .../phase0/listValidator.test.ts | 39 +++++++------ .../lodestarTypes/phase0/validator.test.ts | 2 +- .../phase0/viewDU/validatorNodeStruct.test.ts | 24 ++------ 21 files changed, 127 insertions(+), 103 deletions(-) diff --git a/packages/persistent-merkle-tree/package.json b/packages/persistent-merkle-tree/package.json index f44d77af..5702c9d2 100644 --- a/packages/persistent-merkle-tree/package.json +++ b/packages/persistent-merkle-tree/package.json @@ -20,6 +20,7 @@ "clean": "rm -rf lib", "build": "tsc", "lint": "eslint --color --ext .ts src/", + "lint:fix": "yarn run lint --fix", "benchmark:files": "node --max-old-space-size=4096 --expose-gc -r ts-node/register ../../node_modules/.bin/benchmark", "benchmark": "yarn benchmark:files 'test/perf/*.test.ts'", "benchmark:local": "yarn benchmark --local", diff --git a/packages/persistent-merkle-tree/src/hasher/as-sha256.ts b/packages/persistent-merkle-tree/src/hasher/as-sha256.ts index 3c91aa4d..5e356ada 100644 --- a/packages/persistent-merkle-tree/src/hasher/as-sha256.ts +++ b/packages/persistent-merkle-tree/src/hasher/as-sha256.ts @@ -1,4 +1,11 @@ -import {digest2Bytes32, digest64HashObjectsInto, digest64HashObjects, HashObject, batchHash4HashObjectInputs, hashInto} from "@chainsafe/as-sha256"; +import { + digest2Bytes32, + digest64HashObjectsInto, + digest64HashObjects, + HashObject, + batchHash4HashObjectInputs, + hashInto, +} from "@chainsafe/as-sha256"; import type {Hasher} from "./types"; import {HashComputation, Node} from "../node"; @@ -23,7 +30,9 @@ export const hasher: Hasher = { throw new Error(`Invalid nLevel, expect to be greater than 0, got ${nLevel}`); } if (inputLength % bytesInBatch !== 0) { - throw new Error(`Invalid input length, expect to be multiple of ${bytesInBatch} for nLevel ${nLevel}, got ${inputLength}`); + throw new Error( + `Invalid input length, expect to be multiple of ${bytesInBatch} for nLevel ${nLevel}, got ${inputLength}` + ); } if (inputLength > MAX_INPUT_SIZE) { throw new Error(`Invalid input length, expect to be less than ${MAX_INPUT_SIZE}, got ${inputLength}`); @@ -35,7 +44,7 @@ export const hasher: Hasher = { const hashInput = buffer.subarray(0, inputLength); const hashOutput = buffer.subarray(0, outputLength); hashInto(hashInput, hashOutput); - inputLength = outputLength + inputLength = outputLength; } // the result is unsafe as it will be modified later, consumer should save the result if needed diff --git a/packages/persistent-merkle-tree/src/hasher/hashtree.ts b/packages/persistent-merkle-tree/src/hasher/hashtree.ts index 625ca6a8..24bfdd6e 100644 --- a/packages/persistent-merkle-tree/src/hasher/hashtree.ts +++ b/packages/persistent-merkle-tree/src/hasher/hashtree.ts @@ -1,8 +1,8 @@ import {hashInto} from "@chainsafe/hashtree"; import {Hasher, HashObject} from "./types"; import {HashComputation, Node} from "../node"; -import { byteArrayToHashObject } from "@chainsafe/as-sha256"; -import { byteArrayIntoHashObject } from "@chainsafe/as-sha256/lib/hashObject"; +import {byteArrayToHashObject} from "@chainsafe/as-sha256"; +import {byteArrayIntoHashObject} from "@chainsafe/as-sha256/lib/hashObject"; /** * Best SIMD implementation is in 512 bits = 64 bytes @@ -49,7 +49,9 @@ export const hasher: Hasher = { throw new Error(`Invalid nLevel, expect to be greater than 0, got ${nLevel}`); } if (inputLength % bytesInBatch !== 0) { - throw new Error(`Invalid input length, expect to be multiple of ${bytesInBatch} for nLevel ${nLevel}, got ${inputLength}`); + throw new Error( + `Invalid input length, expect to be multiple of ${bytesInBatch} for nLevel ${nLevel}, got ${inputLength}` + ); } if (inputLength > MAX_INPUT_SIZE) { throw new Error(`Invalid input length, expect to be less than ${MAX_INPUT_SIZE}, got ${inputLength}`); @@ -179,4 +181,4 @@ function hashObjectsToUint32Array(obj1: HashObject, obj2: HashObject, arr: Uint3 arr[13] = obj2.h5; arr[14] = obj2.h6; arr[15] = obj2.h7; -} \ No newline at end of file +} diff --git a/packages/persistent-merkle-tree/src/hasher/noble.ts b/packages/persistent-merkle-tree/src/hasher/noble.ts index d8f115b0..78999e7d 100644 --- a/packages/persistent-merkle-tree/src/hasher/noble.ts +++ b/packages/persistent-merkle-tree/src/hasher/noble.ts @@ -11,7 +11,7 @@ export const hasher: Hasher = { digest64HashObjects: (left, right, parent) => { byteArrayIntoHashObject(digest64(hashObjectToUint8Array(left), hashObjectToUint8Array(right)), parent); }, - digestNLevelUnsafe(data: Uint8Array, nLevel: number): Uint8Array { + digestNLevelUnsafe(): Uint8Array { throw new Error("Not implemented"); }, batchHashObjects: (inputs: HashObject[]) => { diff --git a/packages/persistent-merkle-tree/src/hasher/types.ts b/packages/persistent-merkle-tree/src/hasher/types.ts index 64dd7993..b6591cdb 100644 --- a/packages/persistent-merkle-tree/src/hasher/types.ts +++ b/packages/persistent-merkle-tree/src/hasher/types.ts @@ -19,7 +19,7 @@ export type Hasher = { * With nLevel = 3, hash multiple of 256 bytes, return multiple of 32 bytes. * The result is unsafe as it will be overwritten by the next call. */ - digestNLevelUnsafe(data: Uint8Array, nLevel: number): Uint8Array + digestNLevelUnsafe(data: Uint8Array, nLevel: number): Uint8Array; /** * Batch hash 2 * n HashObjects, return n HashObjects output */ diff --git a/packages/persistent-merkle-tree/src/tree.ts b/packages/persistent-merkle-tree/src/tree.ts index 1f6b8ac3..1ade6129 100644 --- a/packages/persistent-merkle-tree/src/tree.ts +++ b/packages/persistent-merkle-tree/src/tree.ts @@ -1,6 +1,6 @@ import {zeroNode} from "./zeroNode"; import {Gindex, GindexBitstring, convertGindexToBitstring} from "./gindex"; -import {Node, LeafNode, BranchNode, HashComputation, HashComputationGroup, arrayAtIndex} from "./node"; +import {Node, LeafNode, BranchNode, HashComputationGroup, arrayAtIndex} from "./node"; import {createNodeFromProof, createProof, Proof, ProofInput} from "./proof"; import {createSingleProof} from "./proof/single"; @@ -799,7 +799,6 @@ export function findDiffDepthi(from: number, to: number): number { return findDiffDepthi32Bits(from, to); } - /** * Returns true if the `index` at `depth` is a left node, false if it is a right node. * diff --git a/packages/ssz/src/type/byteArray.ts b/packages/ssz/src/type/byteArray.ts index b6dbb128..48c5263f 100644 --- a/packages/ssz/src/type/byteArray.ts +++ b/packages/ssz/src/type/byteArray.ts @@ -1,4 +1,4 @@ -import {concatGindices, Gindex, HashComputationGroup, Node, toGindex, Tree} from "@chainsafe/persistent-merkle-tree"; +import {concatGindices, Gindex, Node, toGindex, Tree} from "@chainsafe/persistent-merkle-tree"; import {fromHexString, toHexString, byteArrayEquals} from "../util/byteArray"; import {splitIntoRootChunks} from "../util/merkleize"; import {ByteViews} from "./abstract"; @@ -38,7 +38,7 @@ export abstract class ByteArrayType extends CompositeType return new BranchNodeStruct(this.valueToTree.bind(this), value); } - private valueToTree( - value: ValueOfFields, - ): Node { + private valueToTree(value: ValueOfFields): Node { const uint8Array = new Uint8Array(this.value_serializedSize(value)); const dataView = new DataView(uint8Array.buffer, uint8Array.byteOffset, uint8Array.byteLength); this.value_serializeToBytes({uint8Array, dataView}, 0, value); diff --git a/packages/ssz/src/type/optional.ts b/packages/ssz/src/type/optional.ts index d2d8fb0c..c82df001 100644 --- a/packages/ssz/src/type/optional.ts +++ b/packages/ssz/src/type/optional.ts @@ -1,4 +1,4 @@ -import {concatGindices, Gindex, HashComputationGroup, Node, Tree, zeroNode} from "@chainsafe/persistent-merkle-tree"; +import {concatGindices, Gindex, Node, Tree, zeroNode} from "@chainsafe/persistent-merkle-tree"; import {mixInLength} from "../util/merkleize"; import {Require} from "../util/types"; import {namedClass} from "../util/named"; @@ -76,7 +76,7 @@ export class OptionalType> extends CompositeTy // TODO add an OptionalViewDU // TODO - batch - commitViewDU(view: ValueOfType, hashComps: HashComputationGroup | null = null): Node { + commitViewDU(view: ValueOfType): Node { return this.value_toTree(view); } diff --git a/packages/ssz/src/type/union.ts b/packages/ssz/src/type/union.ts index ac60e1b7..5bd664e0 100644 --- a/packages/ssz/src/type/union.ts +++ b/packages/ssz/src/type/union.ts @@ -1,4 +1,4 @@ -import {concatGindices, getNode, Gindex, HashComputationGroup, Node, Tree} from "@chainsafe/persistent-merkle-tree"; +import {concatGindices, getNode, Gindex, Node, Tree} from "@chainsafe/persistent-merkle-tree"; import {mixInLength} from "../util/merkleize"; import {Require} from "../util/types"; import {namedClass} from "../util/named"; @@ -107,7 +107,7 @@ export class UnionType[]> extends CompositeType< } // TODO - batch - commitViewDU(view: ValueOfTypes, hashComps: HashComputationGroup | null = null): Node { + commitViewDU(view: ValueOfTypes): Node { return this.value_toTree(view); } diff --git a/packages/ssz/src/viewDU/arrayBasic.ts b/packages/ssz/src/viewDU/arrayBasic.ts index fee0e801..159c525a 100644 --- a/packages/ssz/src/viewDU/arrayBasic.ts +++ b/packages/ssz/src/viewDU/arrayBasic.ts @@ -1,4 +1,12 @@ -import {getHashComputations, getNodeAtDepth, getNodesAtDepth, HashComputationGroup, LeafNode, Node, setNodesAtDepth} from "@chainsafe/persistent-merkle-tree"; +import { + getHashComputations, + getNodeAtDepth, + getNodesAtDepth, + HashComputationGroup, + LeafNode, + Node, + setNodesAtDepth, +} from "@chainsafe/persistent-merkle-tree"; import {ValueOf} from "../type/abstract"; import {BasicType} from "../type/basic"; import {ArrayBasicType} from "../view/arrayBasic"; diff --git a/packages/ssz/src/viewDU/container.ts b/packages/ssz/src/viewDU/container.ts index e0c16cdd..ed01b958 100644 --- a/packages/ssz/src/viewDU/container.ts +++ b/packages/ssz/src/viewDU/container.ts @@ -1,10 +1,16 @@ -import {getHashComputations, getNodeAtDepth, HashComputationGroup, LeafNode, Node, setNodesAtDepth} from "@chainsafe/persistent-merkle-tree"; +import { + getHashComputations, + getNodeAtDepth, + HashComputationGroup, + LeafNode, + Node, + setNodesAtDepth, +} from "@chainsafe/persistent-merkle-tree"; import {ByteViews, Type} from "../type/abstract"; import {BasicType, isBasicType} from "../type/basic"; import {CompositeType, isCompositeType, CompositeTypeAny} from "../type/composite"; import {ContainerTypeGeneric} from "../view/container"; import {TreeViewDU} from "./abstract"; -import { isNullOrUndefined } from "util"; /* eslint-disable @typescript-eslint/member-ordering */ diff --git a/packages/ssz/test/lodestarTypes/phase0/listValidator.ts b/packages/ssz/test/lodestarTypes/phase0/listValidator.ts index ef189c85..66cec422 100644 --- a/packages/ssz/test/lodestarTypes/phase0/listValidator.ts +++ b/packages/ssz/test/lodestarTypes/phase0/listValidator.ts @@ -1,8 +1,8 @@ -import { ListCompositeType } from "../../../src/type/listComposite"; -import { Node } from "@chainsafe/persistent-merkle-tree"; -import { ListCompositeTreeViewDU } from "../../../src/viewDU/listComposite"; -import { ValidatorNodeStructType } from "./validator"; -import { ListValidatorTreeViewDU } from "./viewDU/listValidator"; +import {ListCompositeType} from "../../../src/type/listComposite"; +import {Node} from "@chainsafe/persistent-merkle-tree"; +import {ListCompositeTreeViewDU} from "../../../src/viewDU/listComposite"; +import {ValidatorNodeStructType} from "./validator"; +import {ListValidatorTreeViewDU} from "./viewDU/listValidator"; export class ListValidatorType extends ListCompositeType { constructor(limit: number) { @@ -12,4 +12,4 @@ export class ListValidatorType extends ListCompositeType { return new ListValidatorTreeViewDU(this, node, cache as any); } -} \ No newline at end of file +} diff --git a/packages/ssz/test/lodestarTypes/phase0/validator.ts b/packages/ssz/test/lodestarTypes/phase0/validator.ts index 33d4cc3d..758d95d7 100644 --- a/packages/ssz/test/lodestarTypes/phase0/validator.ts +++ b/packages/ssz/test/lodestarTypes/phase0/validator.ts @@ -2,7 +2,7 @@ import {ByteViews} from "../../../src/type/abstract"; import {ContainerNodeStructType} from "../../../src/type/containerNodeStruct"; import {ValueOfFields} from "../../../src/view/container"; import * as primitiveSsz from "../primitive/sszTypes"; -import { ValidatorTreeViewDU } from "./viewDU/validator"; +import {ValidatorTreeViewDU} from "./viewDU/validator"; import {Node} from "@chainsafe/persistent-merkle-tree"; const {Boolean, Bytes32, UintNum64, BLSPubkey, EpochInf} = primitiveSsz; diff --git a/packages/ssz/test/lodestarTypes/phase0/viewDU/listValidator.ts b/packages/ssz/test/lodestarTypes/phase0/viewDU/listValidator.ts index 941fe5de..487b8659 100644 --- a/packages/ssz/test/lodestarTypes/phase0/viewDU/listValidator.ts +++ b/packages/ssz/test/lodestarTypes/phase0/viewDU/listValidator.ts @@ -1,10 +1,10 @@ import {HashComputationGroup, Node, digestNLevelUnsafe, setNodesAtDepth} from "@chainsafe/persistent-merkle-tree"; -import { ListCompositeType } from "../../../../src/type/listComposite"; -import { ArrayCompositeTreeViewDUCache } from "../../../../src/viewDU/arrayComposite"; -import { ListCompositeTreeViewDU } from "../../../../src/viewDU/listComposite"; -import { ValidatorNodeStructType } from "../validator"; -import { ValidatorTreeViewDU } from "./validator"; -import { ByteViews } from "../../../../src"; +import {ListCompositeType} from "../../../../src/type/listComposite"; +import {ArrayCompositeTreeViewDUCache} from "../../../../src/viewDU/arrayComposite"; +import {ListCompositeTreeViewDU} from "../../../../src/viewDU/listComposite"; +import {ValidatorNodeStructType} from "../validator"; +import {ValidatorTreeViewDU} from "./validator"; +import {ByteViews} from "../../../../src"; /** * hashtree has a MAX_SIZE of 1024 bytes = 32 chunks @@ -71,7 +71,9 @@ export class ListValidatorTreeViewDU extends ListCompositeTreeViewDU= 0; j--) { diff --git a/packages/ssz/test/lodestarTypes/phase0/viewDU/validator.ts b/packages/ssz/test/lodestarTypes/phase0/viewDU/validator.ts index 31b67f99..d606ec7f 100644 --- a/packages/ssz/test/lodestarTypes/phase0/viewDU/validator.ts +++ b/packages/ssz/test/lodestarTypes/phase0/viewDU/validator.ts @@ -1,13 +1,10 @@ -import { byteArrayIntoHashObject } from "@chainsafe/as-sha256"; -import { BranchNodeStruct } from "../../../../src/branchNodeStruct"; -import { ContainerTypeGeneric } from "../../../../src/view/container"; -import { TreeViewDU } from "../../../../src/viewDU/abstract"; -import { ValidatorType } from "../validator"; -import { - Node, - digestNLevelUnsafe, -} from "@chainsafe/persistent-merkle-tree"; -import { ByteViews } from "../../../../src/type/abstract"; +import {byteArrayIntoHashObject} from "@chainsafe/as-sha256"; +import {BranchNodeStruct} from "../../../../src/branchNodeStruct"; +import {ContainerTypeGeneric} from "../../../../src/view/container"; +import {TreeViewDU} from "../../../../src/viewDU/abstract"; +import {ValidatorType} from "../validator"; +import {Node, digestNLevelUnsafe} from "@chainsafe/persistent-merkle-tree"; +import {ByteViews} from "../../../../src/type/abstract"; type Validator = { pubkey: Uint8Array; withdrawalCredentials: Uint8Array; @@ -19,7 +16,6 @@ type Validator = { withdrawableEpoch: number; }; -const numFields = 8; const NUMBER_2_POW_32 = 2 ** 32; /* * Below constants are respective to their ssz type in `ValidatorType`. @@ -218,21 +214,30 @@ export class ValidatorTreeViewDU extends TreeViewDU { itBenchHashTreeRoot(sszPhase0.Attestation, getAttestation(0)); diff --git a/packages/ssz/test/perf/eth2/validators.test.ts b/packages/ssz/test/perf/eth2/validators.test.ts index 81820e74..3e15ce24 100644 --- a/packages/ssz/test/perf/eth2/validators.test.ts +++ b/packages/ssz/test/perf/eth2/validators.test.ts @@ -1,4 +1,4 @@ -import {itBench, setBenchOpts} from "@dapplion/benchmark"; +import {itBench} from "@dapplion/benchmark"; import {Validator} from "../../lodestarTypes/phase0/types"; import {ValidatorContainer, ValidatorNodeStruct, Validators} from "../../lodestarTypes/phase0/sszTypes"; import {BranchNodeStruct, CompositeViewDU} from "../../../src"; @@ -69,8 +69,7 @@ describe("ContainerNodeStructViewDU vs ValidatorViewDU hashtreeroot", () => { fn: () => { listValidator.commit(); }, - }) - + }); // this needs to create validator tree every time itBench({ @@ -81,7 +80,7 @@ describe("ContainerNodeStructViewDU vs ValidatorViewDU hashtreeroot", () => { node.h0 = null as unknown as number; } }, - fn: () => { + fn: () => { for (const node of nodes) { node.root; } diff --git a/packages/ssz/test/unit/lodestarTypes/phase0/listValidator.test.ts b/packages/ssz/test/unit/lodestarTypes/phase0/listValidator.test.ts index 438ebe7f..6602afed 100644 --- a/packages/ssz/test/unit/lodestarTypes/phase0/listValidator.test.ts +++ b/packages/ssz/test/unit/lodestarTypes/phase0/listValidator.test.ts @@ -1,12 +1,10 @@ -import { ListCompositeType } from "../../../../src/type/listComposite"; -import { ValidatorType } from "../../../lodestarTypes/phase0/validator"; -import { - preset, -} from "../../../lodestarTypes/params"; -import { ssz } from "../../../lodestarTypes"; -import { expect } from "chai"; -import { ContainerType } from "../../../../src/type/container"; -import { Validator } from "../../../lodestarTypes/phase0"; +import {ListCompositeType} from "../../../../src/type/listComposite"; +import {ValidatorType} from "../../../lodestarTypes/phase0/validator"; +import {preset} from "../../../lodestarTypes/params"; +import {ssz} from "../../../lodestarTypes"; +import {expect} from "chai"; +import {ContainerType} from "../../../../src/type/container"; +import {Validator} from "../../../lodestarTypes/phase0"; const {VALIDATOR_REGISTRY_LIMIT} = preset; describe("ListValidator ssz type", function () { @@ -25,8 +23,11 @@ describe("ListValidator ssz type", function () { const ValidatorContainer = new ContainerType(ValidatorType, {typeName: "Validator", jsonCase: "eth2"}); const oldValidatorsType = new ListCompositeType(ValidatorContainer, VALIDATOR_REGISTRY_LIMIT); for (const numValidators of testCases) { - it (`should commit ${numValidators} validators`, () => { - const validators = Array.from({length: numValidators}, (_, i) => ({...seedValidator, withdrawableEpoch: seedValidator.withdrawableEpoch + i})); + it(`should commit ${numValidators} validators`, () => { + const validators = Array.from({length: numValidators}, (_, i) => ({ + ...seedValidator, + withdrawableEpoch: seedValidator.withdrawableEpoch + i, + })); const oldViewDU = oldValidatorsType.toViewDU(validators); const newViewDU = ssz.phase0.Validators.toViewDU(validators); // modify all validators @@ -39,11 +40,14 @@ describe("ListValidator ssz type", function () { }); } - const testCases2 = [[1], [3, 5], [1,9, 7]]; + const testCases2 = [[1], [3, 5], [1, 9, 7]]; const numValidator = 33; for (const modifiedIndices of testCases2) { it(`should modify ${modifiedIndices.length} validators`, () => { - const validators = Array.from({length: numValidator}, (_, i) => ({...seedValidator, withdrawableEpoch: seedValidator.withdrawableEpoch + i})); + const validators = Array.from({length: numValidator}, (_, i) => ({ + ...seedValidator, + withdrawableEpoch: seedValidator.withdrawableEpoch + i, + })); const oldViewDU = oldValidatorsType.toViewDU(validators); const newViewDU = ssz.phase0.Validators.toViewDU(validators); for (const index of modifiedIndices) { @@ -52,13 +56,16 @@ describe("ListValidator ssz type", function () { } expect(newViewDU.hashTreeRoot()).to.be.deep.equal(oldViewDU.hashTreeRoot()); expect(newViewDU.serialize()).to.be.deep.equal(oldViewDU.serialize()); - }) + }); } const testCases3 = [1, 3, 5, 7]; for (const numPush of testCases3) { it(`should push ${numPush} validators`, () => { - const validators = Array.from({length: numValidator}, (_, i) => ({...seedValidator, withdrawableEpoch: seedValidator.withdrawableEpoch + i})); + const validators = Array.from({length: numValidator}, (_, i) => ({ + ...seedValidator, + withdrawableEpoch: seedValidator.withdrawableEpoch + i, + })); const oldViewDU = oldValidatorsType.toViewDU(validators); const newViewDU = ssz.phase0.Validators.toViewDU(validators); const newValidators: Validator[] = []; @@ -77,6 +84,6 @@ describe("ListValidator ssz type", function () { for (let i = 0; i < numPush; i++) { expect(allValidators[numValidator + i]).to.be.deep.equal(newValidators[i]); } - }) + }); } }); diff --git a/packages/ssz/test/unit/lodestarTypes/phase0/validator.test.ts b/packages/ssz/test/unit/lodestarTypes/phase0/validator.test.ts index 04beee42..4ecfc8e0 100644 --- a/packages/ssz/test/unit/lodestarTypes/phase0/validator.test.ts +++ b/packages/ssz/test/unit/lodestarTypes/phase0/validator.test.ts @@ -3,7 +3,7 @@ import {ContainerType} from "../../../../../ssz/src/type/container"; import {ssz} from "../../../lodestarTypes"; import {ValidatorType} from "../../../lodestarTypes/phase0/validator"; import {ValidatorTreeViewDU} from "../../../lodestarTypes/phase0/viewDU/validator"; -import { expect } from "chai"; +import {expect} from "chai"; const ValidatorContainer = new ContainerType(ValidatorType, {typeName: "Validator", jsonCase: "eth2"}); diff --git a/packages/ssz/test/unit/lodestarTypes/phase0/viewDU/validatorNodeStruct.test.ts b/packages/ssz/test/unit/lodestarTypes/phase0/viewDU/validatorNodeStruct.test.ts index 96085875..c2a43333 100644 --- a/packages/ssz/test/unit/lodestarTypes/phase0/viewDU/validatorNodeStruct.test.ts +++ b/packages/ssz/test/unit/lodestarTypes/phase0/viewDU/validatorNodeStruct.test.ts @@ -1,9 +1,8 @@ -import { digestNLevelUnsafe } from "@chainsafe/persistent-merkle-tree"; -import { validatorToMerkleBytes } from "../../../../lodestarTypes/phase0/viewDU/validator"; -import { HashObject } from "@chainsafe/as-sha256"; -import { ValidatorNodeStruct } from "../../../../lodestarTypes/phase0/validator"; -import { expect } from "chai"; -import { Validator } from "../../../../lodestarTypes/phase0/sszTypes"; +import {digestNLevelUnsafe} from "@chainsafe/persistent-merkle-tree"; +import {validatorToMerkleBytes} from "../../../../lodestarTypes/phase0/viewDU/validator"; +import {ValidatorNodeStruct} from "../../../../lodestarTypes/phase0/validator"; +import {expect} from "chai"; +import {Validator} from "../../../../lodestarTypes/phase0/sszTypes"; describe("validatorNodeStruct", () => { const seedValidator = { @@ -38,16 +37,5 @@ describe("validatorNodeStruct", () => { expect(root).to.be.deep.equals(expectedRoot0); expect(root).to.be.deep.equals(expectedRootNode2.root); } - }) + }); }); - -function expectEqualNode(node1: HashObject, node2: HashObject, message: string) { - expect(node1.h0 >>> 0).to.be.equal(node2.h0 >>> 0, `${message} h0`); - expect(node1.h1 >>> 0).to.be.equal(node2.h1 >>> 0, `${message} h1`); - expect(node1.h2 >>> 0).to.be.equal(node2.h2 >>> 0, `${message} h2`); - expect(node1.h3 >>> 0).to.be.equal(node2.h3 >>> 0, `${message} h3`); - expect(node1.h4 >>> 0).to.be.equal(node2.h4 >>> 0, `${message} h4`); - expect(node1.h5 >>> 0).to.be.equal(node2.h5 >>> 0, `${message} h5`); - expect(node1.h6 >>> 0).to.be.equal(node2.h6 >>> 0, `${message} h6`); - expect(node1.h7 >>> 0).to.be.equal(node2.h7 >>> 0, `${message} h7`); -}