test: add tests for solver

This commit is contained in:
2025-06-27 23:42:26 +02:00
parent 19e97d523a
commit 246e001af9
6 changed files with 2723 additions and 1 deletions

View File

@@ -5,9 +5,12 @@
}, },
"dependencies": { "dependencies": {
"@eslint/js": "^9.29.0", "@eslint/js": "^9.29.0",
"@jest/globals": "^30.0.3",
"@swc/jest": "^0.2.38",
"@types/node": "^24.0.4", "@types/node": "^24.0.4",
"eslint": "^9.29.0", "eslint": "^9.29.0",
"globals": "^16.2.0", "globals": "^16.2.0",
"jest": "^30.0.3",
"prettier": "^3.6.0", "prettier": "^3.6.0",
"turbo": "^2.5.4", "turbo": "^2.5.4",
"typescript": "^5.8.3", "typescript": "^5.8.3",

View File

@@ -0,0 +1,6 @@
/** @type {import('jest').Config} */
module.exports = {
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest",
},
};

View File

@@ -4,6 +4,7 @@
"module": "dist/lib.js", "module": "dist/lib.js",
"types": "dist/lib.d.ts", "types": "dist/lib.d.ts",
"scripts": { "scripts": {
"build": "tsc -p tsconfig.build.json" "build": "tsc -p tsconfig.build.json",
"test": "jest"
} }
} }

View File

@@ -0,0 +1,23 @@
import { describe, it, expect } from "@jest/globals";
import * as solver from "./lib";
describe("solver", () => {
it("solveJs", async () => {
expect(
await solver.solveJs(
new Uint8Array([1, 2]),
new Uint8Array([3, 4]),
),
).toStrictEqual(new Uint8Array([45, 176, 0, 0, 0, 0, 0, 0]));
});
it("verify", async () => {
expect(
await solver.verify(
new Uint8Array([1, 2]),
new Uint8Array([3, 4]),
new Uint8Array([45, 176, 0, 0, 0, 0, 0, 0]),
),
).toStrictEqual(true);
});
});

View File

@@ -12,6 +12,7 @@ export async function solveJs(
true; true;
i++ i++
) { ) {
// using little-endian
solutionView.setBigUint64(0, i, true); solutionView.setBigUint64(0, i, true);
const hashArrayBuf = await crypto.subtle.digest("SHA-256", arr); const hashArrayBuf = await crypto.subtle.digest("SHA-256", arr);

2688
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff