cred402/test/realfi_plaid.test.ts
caelum0x 2d43618725 feat: real integrations (Casper Testnet, x402/EIP-712, MCP, RealFi, cross-chain), wallet sign-in, branding
Replace the design-note docs (p1–p7) with the implemented "make it real" phase
docs (p8–p10) and wire production-grade, env-gated real integrations:

- p8 Casper Testnet: byte-exact deploys + WASM install via casper-js-sdk; live
  node reads (node.testnet.casper.network); CRED402_CHAIN=sim|testnet transport.
- p9 x402 + data + MCP: real EIP-712 typed-data digests (@casper-ecosystem/
  casper-eip-712); casper-x402 facilitator client (x402 V2); live Open-Meteo GHI;
  official @modelcontextprotocol/sdk server; casper-sidecar SSE event feed.
- p10 RealFi + cross-chain: real Stripe test-mode webhooks (HMAC-verified) and
  Plaid sandbox → privacy-preserving on-chain envelopes; Base Sepolia EVM deploy
  (Foundry); reachable via /api/realfi/* and /api/x402/facilitator routes.
- Sign-in with Casper Wallet: real extension provider + challenge/ed25519/session
  flow (/v1/auth/wallet/*), console connect + sign-in button.
- Branding: Cred402 logo mark, favicon, OG image; Vercel config for the console.

All env-gated with sim/free-API fallbacks; full suite green, all toolchains
(TS/Rust/Go/Solidity) build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 00:37:36 +03:00

47 lines
2.1 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { Ledger } from "../lib/ledger/ledger.js";
import { RealFiBridge } from "../lib/services/realfi_bridge.js";
import { bankVerificationFromPlaid, plaidFromEnv } from "../lib/realfi/plaid.js";
/**
* p10 — real Plaid sandbox integration. The live calls hit Plaid sandbox (gated
* by PLAID_CLIENT_ID/PLAID_SECRET); the response → envelope mapping is pure and
* tested here offline, then committed through the real RealFi Bridge so a Bank
* Verification Envelope lands on-chain (hashes only).
*/
test("p10 plaid: maps a sandbox auth+balance response to a verified bank envelope", () => {
const input = bankVerificationFromPlaid(
"operator:0xabc",
{ accounts: [{ account_id: "acc_1" }], numbers: { ach: [{ account: "1111" }] } },
{ accounts: [{ balances: { current: 4210.55 } }] },
1_700_000_000,
);
assert.equal(input.account_ownership_verified, true, "account + ACH present → ownership verified");
assert.equal(input.data_period_end, 1_700_000_000);
assert.equal(input.data_period_start, 1_700_000_000 - 30 * 24 * 60 * 60);
// Commit it through the real bridge → on-chain attestation (hashes only).
const bridge = new RealFiBridge(new Ledger());
const { attestation_hash, envelope } = bridge.recordBankVerification(input);
assert.match(attestation_hash, /^0x[0-9a-f]+$/);
assert.equal(envelope.account_ownership_verified, true);
// Raw report is hashed, never stored.
assert.ok(!("cashflow_report" in envelope), "no raw cashflow on the envelope");
});
test("p10 plaid: missing ACH numbers → ownership not verified", () => {
const input = bankVerificationFromPlaid(
"operator:0xdef",
{ accounts: [{ account_id: "acc_2" }], numbers: { ach: [] } },
{ accounts: [{ balances: { current: 10 } }] },
);
assert.equal(input.account_ownership_verified, false);
});
test("p10 plaid: connector is null unless sandbox creds are configured", () => {
assert.equal(plaidFromEnv({}), null);
assert.ok(plaidFromEnv({ PLAID_CLIENT_ID: "x", PLAID_SECRET: "y" }));
});