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

30 lines
1.3 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { ServerState } from "../api/state.js";
import { cspr } from "../lib/core/units.js";
test("review-all: reviews every active line and summarizes the actions", () => {
const state = new ServerState();
// Open a couple of lines on the bootstrapped agents.
const agents = state.ledger.agents.list().slice(0, 2);
for (const a of agents) {
state.ledger.pool.open_credit_line({ agent_id: a.agent_id, max_credit: cspr(10), interest_rate_bps: 800, origination_fee_bps: 50, term_seconds: 86_400 });
}
const summary = state.reviewAllCreditLines();
assert.equal(summary.reviewed, agents.length);
assert.equal(summary.errors, 0);
// counts reconcile to the number reviewed
assert.equal(summary.increased + summary.held + summary.ineligible, summary.reviewed);
assert.equal(summary.results.length, agents.length);
});
test("review-all: an empty book reviews nothing", () => {
const state = new ServerState();
// The bootstrap may leave no active drawn lines; close any by ignoring — just assert structure.
const summary = state.reviewAllCreditLines();
assert.equal(typeof summary.reviewed, "number");
assert.equal(summary.increased + summary.held + summary.ineligible + summary.errors, summary.results.length);
});