forked from Dshield-xyz/Dshield
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprover.test.ts
More file actions
76 lines (63 loc) · 2.21 KB
/
Copy pathprover.test.ts
File metadata and controls
76 lines (63 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { describe, it, expect, vi, beforeEach } from "vitest";
import { proveWithdrawal } from "./prover";
const executeMock = vi.fn();
const generateProofMock = vi.fn();
const destroyMock = vi.fn();
vi.mock("@noir-lang/noir_js", () => ({
Noir: vi.fn().mockImplementation(function Noir() {
return { execute: executeMock };
}),
}));
vi.mock("@aztec/bb.js", () => ({
UltraHonkBackend: vi.fn().mockImplementation(function UltraHonkBackend() {
return { generateProof: generateProofMock, destroy: destroyMock };
}),
}));
const VALID_INPUTS = {
nullifier: "1",
secret: "2",
root: "0x3",
nullifierHash: "4",
recipientHash: "5",
pathSiblings: ["6", "0x7"],
pathBits: [0, 1],
};
describe("proveWithdrawal", () => {
beforeEach(() => {
vi.clearAllMocks();
executeMock.mockResolvedValue({ witness: new Uint8Array() });
generateProofMock.mockResolvedValue({
proof: new Uint8Array([0xde, 0xad, 0xbe, 0xef]),
publicInputs: ["0x1", "0xabc"],
});
});
// No Worker global exists in this test environment, so proveWithdrawal
// takes the inline fallback path — this exercises the same runProof()
// logic the Web Worker calls in the browser.
it("reports 'executing' then 'proving' progress and returns the hex-encoded proof", async () => {
const stages: string[] = [];
const result = await proveWithdrawal(VALID_INPUTS, (stage) => stages.push(stage));
expect(stages).toEqual(["executing", "proving"]);
expect(result.proof).toBe("deadbeef");
expect(result.publicInputs).toBe(
"1".padStart(64, "0") + "abc".padStart(64, "0"),
);
});
it("hex-prefixes note fields before passing them to Noir.execute", async () => {
await proveWithdrawal(VALID_INPUTS);
expect(executeMock).toHaveBeenCalledWith({
nullifier: "0x1",
secret: "0x2",
root: "0x3",
nullifier_hash: "0x4",
recipient: "0x5",
path_bits: ["0", "1"],
path_siblings: ["0x6", "0x7"],
});
});
it("destroys the backend even when proving fails", async () => {
generateProofMock.mockRejectedValueOnce(new Error("boom"));
await expect(proveWithdrawal(VALID_INPUTS)).rejects.toThrow("boom");
expect(destroyMock).toHaveBeenCalledOnce();
});
});