videogen/apps/mobile/lib/transfer-pending.test.ts
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

68 lines
3.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
isExpiredUnsubmitted,
parsePendingTransfer,
pendingMatchesDraft,
recoveredMatchesPending,
sourceForPending,
} from "./transfer-pending";
const personal = {
source_account_id: "personal_1", kind: "personal" as const, label: "Personal",
role: "owner", can_send: true,
limits: { per_transfer_micros: 100, daily_micros: 200, daily_used_micros: 0, daily_remaining_micros: 200 },
};
const workspace = { ...personal, source_account_id: "workspace_1", kind: "workspace" as const, label: "Studio" };
describe("persisted mobile transfers", () => {
it("migrates legacy sends as submitted and confines them to personal wallets", () => {
const legacy = parsePendingTransfer(JSON.stringify({
recipientHandle: "Bob", amountMicros: 10, idempotencyKey: "old", submitted: false,
}))!;
expect(legacy.version).toBe(1);
expect(legacy.submitted).toBe(true);
expect(sourceForPending(legacy, [workspace, personal])?.source_account_id).toBe("personal_1");
expect(pendingMatchesDraft(legacy, workspace, "bob", 10)).toBe(false);
});
it("restores the exact v2 source, challenge and stable send key", () => {
const v2 = parsePendingTransfer(JSON.stringify({
version: 2, sourceAccountId: "workspace_1", sourceKind: "workspace", sourceLabel: "Studio",
challengeId: "ch_1", challengeExpiresAt: "2020-01-01T00:00:00Z",
recipientHandle: "@Bob", amountMicros: 10, idempotencyKey: "stable", submitted: false,
}))!;
expect(sourceForPending(v2, [personal, workspace])?.source_account_id).toBe("workspace_1");
expect(pendingMatchesDraft(v2, workspace, "bob", 10)).toBe(true);
expect(isExpiredUnsubmitted(v2)).toBe(true);
expect(isExpiredUnsubmitted({ ...v2, submitted: true })).toBe(false);
expect(pendingMatchesDraft({ ...v2, submitted: true }, workspace, "bob", 10)).toBe(true);
const result = {
transfer_id: "tr_1", source: { source_account_id: "workspace_1", kind: "workspace" as const, label: "Studio" },
recipient: { handle: "bob", display_name: "Bob", kind: "personal" as const }, amount_micros: 10, amount_usd: "0.00001", status: "completed",
mint_first_seq: 1, idempotent_replay: false, created_at: null, completed_at: null,
receipt_proof: null, verification: { status: "pending" as const },
};
expect(recoveredMatchesPending(v2, result)).toBe(true);
const legacy = parsePendingTransfer(JSON.stringify({
recipientHandle: "Bob", amountMicros: 10, idempotencyKey: "old", submitted: false,
}))!;
expect(recoveredMatchesPending(legacy, result)).toBe(false);
});
it("matches handles case-insensitively but Mint addresses exactly", () => {
const pending = parsePendingTransfer(JSON.stringify({
version: 2, sourceAccountId: "personal_1", sourceKind: "personal", sourceLabel: "Personal",
challengeId: "ch_address", challengeExpiresAt: "2099-01-01T00:00:00Z",
recipientHandle: "ait1qAddress", amountMicros: 10, idempotencyKey: "address", submitted: true,
}))!;
expect(pendingMatchesDraft(pending, personal, "ait1qAddress", 10)).toBe(true);
expect(pendingMatchesDraft(pending, personal, "ait1qaddress", 10)).toBe(false);
expect(pendingMatchesDraft({ ...pending, recipientHandle: "Bob" }, personal, "@bob", 10)).toBe(true);
});
});