cred402/test/category_analytics.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

41 lines
1.7 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { Ledger } from "../lib/ledger/index.js";
import { Cred402Economy } from "../agents/economy.js";
import { buildCategoryAnalytics } from "../lib/services/category_analytics.js";
test("categories: rolls agents up by service type with reconciling counts", () => {
const l = new Ledger();
const reg = (id: string, svc: "monitoring" | "weather_risk", rep: number) => {
l.agents.register_agent({ agent_id: id, owner_public_key: "01", agent_public_key: "01", service_type: svc });
l.agents.seed_profile(id, { reputation_score: rep });
};
reg("M1", "monitoring", 80);
reg("M2", "monitoring", 60);
reg("W1", "weather_risk", 70);
const cats = buildCategoryAnalytics(l).categories;
const monitoring = cats.find((c) => c.category === "monitoring")!;
assert.equal(monitoring.agent_count, 2);
assert.equal(monitoring.avg_reputation, 70); // (80 + 60) / 2
const weather = cats.find((c) => c.category === "weather_risk")!;
assert.equal(weather.agent_count, 1);
// every registered agent is accounted for in exactly one category
const total = cats.reduce((s, c) => s + c.agent_count, 0);
assert.equal(total, l.agents.list().length);
});
test("categories: sorted by total revenue descending", async () => {
const econ = new Cred402Economy(new Ledger());
econ.bootstrap();
econ.createJob();
const { reports } = await econ.runEvidencePurchases();
await econ.runWatchdogAudit(reports);
const cats = buildCategoryAnalytics(econ.ledger).categories;
for (let i = 1; i < cats.length; i++) {
assert.ok(BigInt(cats[i - 1]!.total_revenue_motes) >= BigInt(cats[i]!.total_revenue_motes));
}
});