Skip to content

Commit

Permalink
Merge 599c756 into 67bcd88
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain authored Dec 20, 2024
2 parents 67bcd88 + 599c756 commit 327be3f
Show file tree
Hide file tree
Showing 102 changed files with 2,839 additions and 1,767 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ jobs:
run: yarn check-types
- name: Lint
run: yarn lint
- name: Tests
run: yarn test
- name: Unit Tests
run: yarn test:unit
- name: Browsers Tests
run: yarn test:browsers

# Download spec tests with cache
- name: Restore spec tests cache
Expand All @@ -44,23 +46,23 @@ jobs:
# Otherwise just doing `yarn test:spec` you can't tell which specific suite failed
# many of the suites have identical names for minimal and mainnet
- name: Spec tests general
run: yarn mocha test/spec/generic/index.test.ts
run: yarn test:spec-generic
working-directory: packages/ssz
- name: Spec tests phase0-minimal
run: LODESTAR_PRESET=minimal LODESTAR_FORK=phase0 yarn mocha test/spec/ssz_static.test.ts
run: LODESTAR_FORK=phase0 yarn test:spec-static-minimal
working-directory: packages/ssz
- name: Spec tests phase0-mainnet
run: LODESTAR_PRESET=mainnet LODESTAR_FORK=phase0 yarn mocha test/spec/ssz_static.test.ts
run: LODESTAR_FORK=phase0 yarn test:spec-static-mainnet
working-directory: packages/ssz
- name: Spec tests altair-minimal
run: LODESTAR_PRESET=minimal LODESTAR_FORK=altair yarn mocha test/spec/ssz_static.test.ts
run: LODESTAR_FORK=altair yarn test:spec-static-minimal
working-directory: packages/ssz
- name: Spec tests altair-mainnet
run: LODESTAR_PRESET=mainnet LODESTAR_FORK=altair yarn mocha test/spec/ssz_static.test.ts
run: LODESTAR_FORK=altair yarn test:spec-static-mainnet
working-directory: packages/ssz
- name: Spec tests bellatrix-minimal
run: LODESTAR_PRESET=minimal LODESTAR_FORK=bellatrix yarn mocha test/spec/ssz_static.test.ts
run: LODESTAR_FORK=bellatrix yarn test:spec-static-minimal
working-directory: packages/ssz
- name: Spec tests bellatrix-mainnet
run: LODESTAR_PRESET=mainnet LODESTAR_FORK=bellatrix yarn mocha test/spec/ssz_static.test.ts
run: LODESTAR_FORK=bellatrix yarn test:spec-static-mainnet
working-directory: packages/ssz
22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"build": "yarn clean && lerna run build",
"lint": "lerna run lint",
"check-types": "lerna run check-types",
"coverage": "lerna run coverage",
"test:unit": "lerna run test:unit",
"test:browsers": "lerna run test:browsers",
"test": "lerna run test",
"benchmark:files": "NODE_OPTIONS='--max_old_space_size=4096 --loader=ts-node/esm' benchmark --config .benchrc.yaml",
"benchmark": "yarn benchmark:files 'packages/*/test/perf/**/*.test.ts'",
Expand All @@ -31,32 +32,29 @@
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^6",
"@typescript-eslint/parser": "^6",
"@vitest/browser": "^2.1.4",
"@vitest/coverage-v8": "^2.1.4",
"babel-loader": "^8.2.2",
"chai": "^4.3.4",
"eslint": "^7.30.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-no-only-tests": "^2.4.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"karma": "^6.3.16",
"karma-babel-preprocessor": "^8.0.1",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.2.0",
"karma-mocha": "^1.3.0",
"karma-webpack": "^5.0.0",
"lerna": "^8.1.3",
"mocha": "^8.3.2",
"nyc": "^15.0.0",
"mocha": "^9.0.1",
"prettier": "^2.2.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "~5.4.2",
"vite-plugin-node-polyfills": "^0.22.0",
"vitest": "^2.1.4",
"webdriverio": "^9.2.11",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^3.11.2"
},
"resolutions": {
"@types/react": "^17.0"
"@types/react": "^17.0",
"chai": "4.5.0"
}
}
46 changes: 0 additions & 46 deletions packages/as-sha256/karma.config.cjs

This file was deleted.

9 changes: 5 additions & 4 deletions packages/as-sha256/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
"build:types": "tsc -p tsconfig.build.types.json",
"build:web": "webpack --mode production --entry ./index.js --output ./dist/as-sha256.min.js",
"test": "yarn run test:unit",
"test:unit": "yarn run test:unit:node",
"test:unit:node": "yarn mocha test/unit/*.test.ts",
"test:unit:browser": "karma start --single-run --browsers ChromeHeadless,FirefoxHeadless karma.config.cjs",
"benchmark": "node --loader ts-node/esm ./node_modules/.bin/benchmark 'test/perf/*.test.ts'",
"test:unit": "vitest run --dir test/unit/",
"test:browsers": "yarn test:browsers:chrome && yarn test:browsers:firefox",
"test:browsers:chrome": "vitest run --browser chrome --config ./vitest.browser.config.ts --dir test/unit",
"test:browsers:firefox": "vitest run --browser firefox --config ./vitest.browser.config.ts --dir test/unit",
"benchmark": "node -r ts-node/register ./node_modules/.bin/benchmark 'test/perf/*.test.ts'",
"benchmark:local": "yarn benchmark --local",
"test:ci": "yarn test:as-ci"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/as-sha256/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {allocUnsafe} from "./alloc.js";
import {newInstance} from "./wasm.js";
import {HashObject, byteArrayIntoHashObject, byteArrayToHashObject, hashObjectToByteArray} from "./hashObject.js";
import type {HashObject} from "./hashObject.js";
import {byteArrayIntoHashObject, byteArrayToHashObject, hashObjectToByteArray} from "./hashObject.js";
import SHA256 from "./sha256.js";
export {HashObject, byteArrayToHashObject, hashObjectToByteArray, byteArrayIntoHashObject, SHA256};

Expand Down
20 changes: 10 additions & 10 deletions packages/as-sha256/test/unit/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import {describe, it, expect} from "vitest";
import {Buffer} from "buffer";
import * as sha256 from "../../src/index.js";
import {expect} from "chai";

describe("sha256", function () {
describe("digest function", function () {
it("abc", function () {
const input = Buffer.from("abc", "utf8");
expect(Buffer.from(sha256.digest(input)).toString("hex")).to.be.equal(
expect(Buffer.from(sha256.digest(input)).toString("hex")).toEqual(
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
);
});

it("empty string", function () {
const input = Buffer.from("", "utf8");
expect(Buffer.from(sha256.digest(input)).toString("hex")).to.be.equal(
expect(Buffer.from(sha256.digest(input)).toString("hex")).toEqual(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
);
});

it("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", function () {
const input = Buffer.from("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "utf8");
expect(Buffer.from(sha256.digest(input)).toString("hex")).to.be.equal(
expect(Buffer.from(sha256.digest(input)).toString("hex")).toEqual(
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
);
});
Expand All @@ -30,7 +30,7 @@ describe("sha256", function () {
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
"utf8"
);
expect(Buffer.from(sha256.digest(input)).toString("hex")).to.be.equal(
expect(Buffer.from(sha256.digest(input)).toString("hex")).toEqual(
"cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1"
);
});
Expand All @@ -45,7 +45,7 @@ describe("sha256", function () {
131, 72, 178, 215, 235, 20, 207, 110,
]);
expect(output).to.be.deep.equal(expectedOutput, "incorrect digest64 result");
expect(Buffer.from(output).toString("hex")).to.be.equal(
expect(Buffer.from(output).toString("hex")).toEqual(
"be39380ff1d0261e6f37dafe4278b662ef611f1cb2f7c0a18348b2d7eb14cf6e"
);
// digestTwoHashObjects should be the same to digest64
Expand All @@ -57,7 +57,7 @@ describe("sha256", function () {
const output2 = new Uint8Array(32);
sha256.hashObjectToByteArray(obj, output2, 0);
for (let i = 0; i < 32; i++) {
expect(output2[i]).to.be.equal(output[i], "failed at index" + i);
expect(output2[i]).toEqual(output[i], "failed at index" + i);
}
expect(output2).to.be.deep.equal(expectedOutput, "incorrect digestTwoHashObjects result");

Expand All @@ -69,16 +69,16 @@ describe("sha256", function () {
const input = Buffer.from("harkamalharkamalharkamalharkamalharkamalharkamalharkamalharkamal", "utf8");
const output = Buffer.from(sha256.digest(input)).toString("hex");
const output64 = Buffer.from(sha256.digest64(input)).toString("hex");
expect(output).to.be.equal(output64);
expect(output).toEqual(output64);
});

it("1024 digest test", function () {
const inputStr = "12345678".repeat(128);
const input = Buffer.from(inputStr, "utf8");
expect(input.length).to.be.equal(1024);
expect(input.length).toEqual(1024);

const output = Buffer.from(sha256.digest(input)).toString("hex");
expect(output).to.be.equal("54c7cb8a82d68145fd5f5da4103f5a66f422dbea23d9fc9f40f59b1dcf5403a9");
expect(output).toEqual("54c7cb8a82d68145fd5f5da4103f5a66f422dbea23d9fc9f40f59b1dcf5403a9");
});
});
});
Expand Down
24 changes: 12 additions & 12 deletions packages/as-sha256/test/unit/simd.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect} from "chai";
import {describe, it, expect} from "vitest";
import crypto from "crypto";
import {byteArrayToHashObject, hashObjectToByteArray} from "../../src/hashObject.js";
import * as sha256 from "../../src/index.js";
Expand All @@ -10,11 +10,11 @@ describe("Test SIMD implementation of as-sha256", () => {
const input = Buffer.from(input1 + input2, "utf8");
const outputs = sha256.batchHash4UintArray64s([input, input, input, input]);
const expectedOutput = new Uint8Array([
190, 57, 56, 15, 241, 208, 38, 30, 111, 55, 218, 254, 66, 120, 182, 98, 239, 97, 31, 28, 178, 247, 192, 161,
131, 72, 178, 215, 235, 20, 207, 110,
190, 57, 56, 15, 241, 208, 38, 30, 111, 55, 218, 254, 66, 120, 182, 98, 239, 97, 31, 28, 178, 247, 192, 161, 131,
72, 178, 215, 235, 20, 207, 110,
]);
for (let i = 0; i < 4; i++) {
expect(outputs[i]).to.be.deep.equal(expectedOutput, "incorrect batchHash4UintArray64s result " + i);
expect(outputs[i]).toEqualWithMessage(expectedOutput, "incorrect batchHash4UintArray64s result " + i);
}
});

Expand All @@ -23,10 +23,10 @@ describe("Test SIMD implementation of as-sha256", () => {
const input = crypto.randomBytes(64);
const outputs = sha256.batchHash4UintArray64s([input, input, input, input]);
const expectedOutput = sha256.digest64(input);
expect(outputs[0]).to.be.deep.equal(expectedOutput);
expect(outputs[1]).to.be.deep.equal(expectedOutput);
expect(outputs[2]).to.be.deep.equal(expectedOutput);
expect(outputs[3]).to.be.deep.equal(expectedOutput);
expect(outputs[0]).toEqual(expectedOutput);
expect(outputs[1]).toEqual(expectedOutput);
expect(outputs[2]).toEqual(expectedOutput);
expect(outputs[3]).toEqual(expectedOutput);
}
});

Expand All @@ -35,13 +35,13 @@ describe("Test SIMD implementation of as-sha256", () => {
const inputHashObject = byteArrayToHashObject(Buffer.from(input1, "utf8"), 0);
const outputs = sha256.batchHash4HashObjectInputs(Array.from({length: 8}, () => inputHashObject));
const expectedOutput = new Uint8Array([
190, 57, 56, 15, 241, 208, 38, 30, 111, 55, 218, 254, 66, 120, 182, 98, 239, 97, 31, 28, 178, 247, 192, 161,
131, 72, 178, 215, 235, 20, 207, 110,
190, 57, 56, 15, 241, 208, 38, 30, 111, 55, 218, 254, 66, 120, 182, 98, 239, 97, 31, 28, 178, 247, 192, 161, 131,
72, 178, 215, 235, 20, 207, 110,
]);
for (let i = 0; i < 4; i++) {
const output = new Uint8Array(32);
hashObjectToByteArray(outputs[i], output, 0);
expect(output).to.be.deep.equal(expectedOutput, "incorrect batchHash4UintArray64s result " + i);
expect(output).toEqualWithMessage(expectedOutput, "incorrect batchHash4UintArray64s result " + i);
}
});

Expand All @@ -59,7 +59,7 @@ describe("Test SIMD implementation of as-sha256", () => {

const expectedOutputs = Array.from({length: numHash}, (_, i) => sha256.digest64(inputs[i]));
for (let i = 0; i < numHash; i++) {
expect(output.subarray(i * 32, (i + 1) * 32)).to.be.deep.equal(expectedOutputs[i]);
expect(output.subarray(i * 32, (i + 1) * 32)).toEqual(expectedOutputs[i]);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../tsconfig.json",
"include": ["src", "test"],
"compilerOptions": {
"typeRoots": ["../../node_modules/@types", "./node_modules/@types", "./types"],
"typeRoots": ["../../node_modules/@types", "./node_modules/@types", "../../types", "./types"],
}
}
4 changes: 4 additions & 0 deletions packages/as-sha256/vitest.browser.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {defineConfig, mergeConfig} from "vitest/config";
import vitestConfig from "../../vitest.base.browser.config";

export default mergeConfig(vitestConfig, defineConfig({}));
4 changes: 4 additions & 0 deletions packages/as-sha256/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {defineConfig, mergeConfig} from "vitest/config";
import baseConfig from "../../vitest.base.unit.config";

export default mergeConfig(baseConfig, defineConfig({}));
2 changes: 1 addition & 1 deletion packages/persistent-merkle-tree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"benchmark:files": "node --max-old-space-size=4096 --expose-gc --loader ts-node/esm ../../node_modules/.bin/benchmark",
"benchmark": "yarn benchmark:files 'test/perf/*.test.ts'",
"benchmark:local": "yarn benchmark --local",
"test": "mocha 'test/unit/**/*.test.ts'"
"test": "vitest run --dir test/unit"
},
"pre-push": [
"lint"
Expand Down
7 changes: 3 additions & 4 deletions packages/persistent-merkle-tree/test/unit/backing.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {assert} from "chai";
import {describe, it} from "mocha";
import {describe, it, expect} from "vitest";
import {Tree, LeafNode, subtreeFillToDepth} from "../../src/index.js";

describe("get", () => {
it("should return the right node", () => {
const n = subtreeFillToDepth(LeafNode.fromRoot(Buffer.alloc(32, 1)), 3);
const backing = new Tree(n);
assert.deepEqual(backing.getRoot(8n), Buffer.alloc(32, 1));
expect(backing.getRoot(8n)).toEqual(Uint8Array.from(Buffer.alloc(32, 1)));
});
});

Expand All @@ -16,6 +15,6 @@ describe("set", () => {
const n2 = LeafNode.fromRoot(Buffer.alloc(32, 2));
const backing = new Tree(n);
backing.setNode(15n, n2);
assert.deepEqual(backing.getRoot(15n), Buffer.alloc(32, 2));
expect(backing.getRoot(15n)).toEqual(Uint8Array.from(Buffer.alloc(32, 2)));
});
});
Loading

0 comments on commit 327be3f

Please sign in to comment.