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

44 lines
1.9 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 { buildAgentMultichainSummary } from "../lib/services/agent_multichain.js";
test("multichain: unknown agent → error", () => {
const l = new Ledger();
assert.ok("error" in buildAgentMultichainSummary(l, "Ghost"));
});
test("multichain: aggregates CANs per target chain under the shared exposure cap", () => {
const l = new Ledger();
const econ = new Cred402Economy(l);
econ.bootstrap();
const agentId = econ.seller.agent_id;
l.exposure.ensure_agent(agentId, 1_000_000_000n);
l.notes.issue_can({ agent_id: agentId, credit_score: 80, risk_policy_version: 1, target_chain: "eip155:8453", target_pool: "0xpool", max_draw: 100_000_000n, asset: "USDC" });
l.notes.issue_can({ agent_id: agentId, credit_score: 80, risk_policy_version: 1, target_chain: "solana:mainnet", target_pool: "Sol1", max_draw: 100_000_000n, asset: "USDC" });
const summary = buildAgentMultichainSummary(l, agentId);
assert.ok(!("error" in summary));
if ("error" in summary) return;
assert.equal(summary.total_credit_notes, 2);
const chains = summary.chains.map((c) => c.chain).sort();
assert.deepEqual(chains, ["eip155:8453", "solana:mainnet"]);
// exposure reserved by the two CANs is reflected in the shared cap
assert.ok(summary.global_exposure);
assert.equal(summary.global_exposure!.reserved, "200000000");
});
test("multichain: an agent with no cross-chain activity has empty chains", () => {
const l = new Ledger();
const econ = new Cred402Economy(l);
econ.bootstrap();
const summary = buildAgentMultichainSummary(l, econ.seller.agent_id);
if ("error" in summary) return assert.fail("expected summary");
assert.equal(summary.total_bindings, 0);
assert.equal(summary.total_external_receipts, 0);
assert.deepEqual(summary.chains, []);
});