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

49 lines
1.8 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { Ledger } from "../lib/ledger/index.js";
import { AttestationGraph } from "../lib/services/attestation_graph.js";
import { compareAgents } from "../lib/services/agent_compare.js";
function reg(l: Ledger, id: string, rep: number, credit: number) {
l.agents.register_agent({ agent_id: id, owner_public_key: "01", agent_public_key: "01", service_type: "monitoring" });
l.agents.seed_profile(id, { reputation_score: rep });
l.agents.set_credit_score(id, credit);
}
test("compare: picks the stronger agent and reports per-metric winners", () => {
const l = new Ledger();
reg(l, "Strong", 90, 85);
reg(l, "Weak", 50, 40);
const att = new AttestationGraph(l);
const cmp = compareAgents(l, att, "Strong", "Weak");
assert.ok(!("error" in cmp));
if ("error" in cmp) return;
assert.equal(cmp.overall_winner, "a");
const rep = cmp.metrics.find((m) => m.metric === "reputation")!;
assert.equal(rep.winner, "a");
assert.equal(rep.higher_is_better, true);
});
test("compare: lower-is-better metrics invert the winner", () => {
const l = new Ledger();
reg(l, "Clean", 80, 70);
reg(l, "Clean2", 80, 70);
const att = new AttestationGraph(l);
const cmp = compareAgents(l, att, "Clean", "Clean2");
if ("error" in cmp) return assert.fail("expected comparison");
const fraud = cmp.metrics.find((m) => m.metric === "fraud_score")!;
assert.equal(fraud.higher_is_better, false);
const dispute = cmp.metrics.find((m) => m.metric === "dispute_rate")!;
assert.equal(dispute.higher_is_better, false);
});
test("compare: unknown agent → error", () => {
const l = new Ledger();
reg(l, "Real", 70, 50);
const att = new AttestationGraph(l);
assert.ok("error" in compareAgents(l, att, "Real", "Ghost"));
assert.ok("error" in compareAgents(l, att, "Ghost", "Real"));
});