proofchain/packages/web/test/verdict.test.ts
caelum0x 0aff927c78 feat: ProofChain production build across 5 packages
- contracts: ProvenanceRegistry, AttestationRegistry, SettlementEscrow, MockUSDC
  (Foundry, OZ AccessControl/SafeERC20/ReentrancyGuard/Pausable), 55 tests
- shared: typed ABI/type/address layer (viem, Base Sepolia)
- agent: Fastify + Claude tool-calling verification service, deterministic
  scoring reconciliation, on-chain attest/settle, 73 tests
- web: Next.js 15 dApp (wagmi/viem/RainbowKit) — supplier/buyer/verifier/deal, 80 tests
- infra: Supabase schema + client, IPFS (Pinata + local fallback), 45 tests
- integrated, security + TS reviewed, 18 findings fixed; 314 tests green

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-31 16:46:57 +03:00

51 lines
1.5 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import { fetchVerdictJson, verdictSchema } from "@/lib/verdict";
const BYTES32 = `0x${"a".repeat(64)}`;
const valid = {
batchId: BYTES32,
score: 8000,
passed: true,
threshold: 7000,
findings: [],
documentHashes: [],
createdAt: "2026-01-01T00:00:00.000Z",
model: "claude-opus-4-8",
};
function mockFetch(body: unknown, init: { ok?: boolean; status?: number } = {}) {
return vi.fn().mockResolvedValue({
ok: init.ok ?? true,
status: init.status ?? 200,
json: async () => body,
} as unknown as Response);
}
afterEach(() => vi.unstubAllGlobals());
describe("verdictSchema", () => {
it("accepts a valid verdict", () => {
expect(verdictSchema.safeParse(valid).success).toBe(true);
});
it("rejects an out-of-range score", () => {
expect(verdictSchema.safeParse({ ...valid, score: 20000 }).success).toBe(false);
});
});
describe("fetchVerdictJson", () => {
it("fetches and validates from an ipfs uri", async () => {
vi.stubGlobal("fetch", mockFetch(valid));
const v = await fetchVerdictJson("ipfs://Qm");
expect(v.score).toBe(8000);
});
it("throws on HTTP error", async () => {
vi.stubGlobal("fetch", mockFetch({}, { ok: false, status: 404 }));
await expect(fetchVerdictJson("ipfs://Qm")).rejects.toThrow(/HTTP 404/);
});
it("throws on schema mismatch", async () => {
vi.stubGlobal("fetch", mockFetch({ score: "bad" }));
await expect(fetchVerdictJson("https://x.test/v")).rejects.toThrow(/validation/i);
});
});