Some checks failed
CI / Frontend Lint (push) Failing after 6s
CI / Frontend Type Check (push) Failing after 6s
CI / Frontend Build (push) Failing after 6s
CI / Frontend E2E Tests (push) Failing after 8s
CI / Contracts Compile (push) Has been cancelled
CI / Contracts Test (push) Has been cancelled
CI / Orchestrator Build (push) Has been cancelled
Security Scan / OWASP ZAP Scan (push) Has been cancelled
Security Scan / Dependency Vulnerability Scan (push) Has been cancelled
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import { describe, it, expect, beforeEach } from "@jest/globals";
|
|
import {
|
|
__resetForTests,
|
|
anchorPlan,
|
|
computePlanHash,
|
|
finalizeAnchor,
|
|
planIdToBytes32,
|
|
} from "../../src/services/notaryChain";
|
|
import type { Plan } from "../../src/types/plan";
|
|
|
|
const FIXTURE_PLAN: Plan = {
|
|
plan_id: "11111111-2222-3333-4444-555555555555",
|
|
creator: "0xabc",
|
|
steps: [{ type: "pay", amount: 100, asset: "USD" }],
|
|
};
|
|
|
|
describe("NotaryChain adapter", () => {
|
|
beforeEach(() => __resetForTests());
|
|
|
|
describe("helpers", () => {
|
|
it("planIdToBytes32 is deterministic and 32 bytes", () => {
|
|
const a = planIdToBytes32("p-1");
|
|
const b = planIdToBytes32("p-1");
|
|
expect(a).toBe(b);
|
|
expect(a).toMatch(/^0x[0-9a-f]{64}$/);
|
|
});
|
|
|
|
it("planIdToBytes32 collision-resistant across different ids", () => {
|
|
expect(planIdToBytes32("a")).not.toBe(planIdToBytes32("b"));
|
|
});
|
|
|
|
it("computePlanHash is deterministic and sha256", () => {
|
|
const h1 = computePlanHash(FIXTURE_PLAN);
|
|
const h2 = computePlanHash(FIXTURE_PLAN);
|
|
expect(h1).toBe(h2);
|
|
expect(h1).toMatch(/^0x[0-9a-f]{64}$/);
|
|
});
|
|
});
|
|
|
|
describe("mock fallback (envs unset)", () => {
|
|
it("anchorPlan returns mode=mock with planHash when unconfigured", async () => {
|
|
const result = await anchorPlan(FIXTURE_PLAN, {});
|
|
expect(result.mode).toBe("mock");
|
|
expect(result.planHash).toMatch(/^0x[0-9a-f]{64}$/);
|
|
expect(result.txHash).toBeUndefined();
|
|
});
|
|
|
|
it("finalizeAnchor returns mode=mock when unconfigured", async () => {
|
|
const result = await finalizeAnchor(FIXTURE_PLAN.plan_id!, true, {});
|
|
expect(result.mode).toBe("mock");
|
|
expect(result.txHash).toBeUndefined();
|
|
});
|
|
|
|
it("anchorPlan stays on the mock path when only some envs are set", async () => {
|
|
const result = await anchorPlan(FIXTURE_PLAN, {
|
|
rpcUrl: "https://rpc.d-bis.org",
|
|
// contractAddress + privateKey missing
|
|
});
|
|
expect(result.mode).toBe("mock");
|
|
});
|
|
});
|
|
});
|