cred402/test/credit_history.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
1.9 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { Cred402Economy } from "../agents/economy.js";
import { Ledger } from "../lib/ledger/index.js";
import { buildCreditHistory } from "../lib/services/credit_history.js";
async function activeAgent() {
const econ = new Cred402Economy(new Ledger());
econ.bootstrap();
econ.createJob();
const { reports } = await econ.runEvidencePurchases();
await econ.runWatchdogAudit(reports);
econ.underwriteSeller();
return { econ, agentId: econ.seller.agent_id };
}
test("history: builds a chronological, categorized credit file", async () => {
const { econ, agentId } = await activeAgent();
const h = buildCreditHistory(econ.ledger, agentId);
assert.ok(!("error" in h));
if ("error" in h) return;
assert.equal(h.agent_id, agentId);
assert.ok(h.entries.length > 0);
// chronological by sequence
for (let i = 1; i < h.entries.length; i++) {
assert.ok(h.entries[i]!.seq > h.entries[i - 1]!.seq);
}
// identity + revenue + credit events all present for an active agent
assert.ok(h.counts.identity >= 1, "expected a registration event");
assert.ok(h.counts.revenue >= 1, "expected revenue events");
assert.ok(h.counts.credit >= 1, "expected credit events");
// count map reconciles with entry total
const total = Object.values(h.counts).reduce((s, n) => s + n, 0);
assert.equal(total, h.entries.length);
assert.ok(h.first_seen !== undefined && h.last_activity !== undefined);
});
test("history: only includes events that mention the agent", async () => {
const { econ, agentId } = await activeAgent();
const h = buildCreditHistory(econ.ledger, agentId);
if ("error" in h) return assert.fail("expected history");
const other = buildCreditHistory(econ.ledger, "definitely-not-an-agent");
assert.ok("error" in other); // unknown agent → error, not an empty file
});