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

@@ -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",
"types": "dist/lib.d.ts",
"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;
i++
) {
// using little-endian
solutionView.setBigUint64(0, i, true);
const hashArrayBuf = await crypto.subtle.digest("SHA-256", arr);