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

42 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 { buildOnboardingScorecard } from "../lib/services/onboarding_scorecard.js";
test("scorecard: a fresh low-reputation agent is not ready and lists the blocking gap", () => {
const ledger = new Ledger();
ledger.agents.register_agent({ agent_id: "Fresh", owner_public_key: "01", agent_public_key: "01", service_type: "monitoring" });
ledger.agents.update_reputation("Fresh", -50, "0x0"); // 70 → 20, below the 40 floor
const card = buildOnboardingScorecard(ledger, "Fresh");
assert.ok(!("error" in card));
if ("error" in card) return;
assert.equal(card.ready, false);
const repItem = card.items.find((i) => i.requirement.startsWith("Reputation"))!;
assert.equal(repItem.met, false);
assert.ok(repItem.blocking);
assert.ok(card.readiness_pct < 100);
});
test("scorecard: an agent meeting every blocking gate is ready", async () => {
const econ = new Cred402Economy(new Ledger());
econ.bootstrap();
econ.createJob();
const { reports } = await econ.runEvidencePurchases();
await econ.runWatchdogAudit(reports);
const card = buildOnboardingScorecard(econ.ledger, econ.seller.agent_id);
if ("error" in card) return assert.fail("expected a scorecard");
// every blocking item is satisfied → ready, even if optional items remain
assert.ok(card.items.filter((i) => i.blocking).every((i) => i.met));
assert.equal(card.ready, true);
assert.ok(card.readiness_pct >= 50);
});
test("scorecard: unknown agent returns an error", () => {
const ledger = new Ledger();
const card = buildOnboardingScorecard(ledger, "Ghost");
assert.ok("error" in card);
});