bot / test / banca-plan.test.mjs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Golden vectors for the banker's pure decision surface — plan-actions and
// friends-of-social, exported off the :worker build. Expectations in
// test/vectors/banca-plan.json are hand-computed from the BANK/1 fold rules
// (independent derivation — nothing here re-runs the implementation to
// produce its own oracle). Runs against the committed dist/ — never src/.
//
// What each family proves:
//   charter  — founds idempotently: only after loadTail(-1)+foundDelayMs,
//              only while no charter has folded, view/charter-error first,
//              and never on a foreign link.
//   acks     — EXACTLY view/ackable: a settled pay (order known) and a
//              settled mint are acked; a failed slot-contender, a burn, an
//              already-final record and a failed mint never are (acking a
//              failed contender would displace a settlement).
//   approve  — per policy: "all", "friends" (against the verified friends
//              list), and an unknown policy warns instead of opening the door.
//   faucet   — once per open non-banker account, totals derived from the
//              ledger's own faucet-memo mints (failures count), capTotal is a
//              hard stop and mandatory, issuance seqs ride the fold's
//              high-water, and a spent space warns instead of signing.
//   treasury — ONE mint-self per tick while the banker's own balance sits
//              under floor (the balance is the idempotence), planned BEFORE
//              the faucet so the two passes never collide on the issuance
//              space; malformed config and a spent space warn, never mint.
//   friends  — the social.json shape gate: suffix-scanned, parse-or-nothing,
//              canonical pubs only, state "friend" only, deduped.
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";

const { planActions, friendsOfSocial } = await import(
  new URL("../stack-b/dist/worker.js", import.meta.url).href
);

const vec = JSON.parse(
  readFileSync(new URL("./vectors/banca-plan.json", import.meta.url), "utf8"),
);

const plain = (v) => JSON.parse(JSON.stringify(v));

test("banca plan-actions golden vectors", () => {
  for (const c of vec.plan) {
    assert.deepEqual(
      plain(planActions(c.snapshot, c.known, c.cfg, c.friends, c.now)),
      c.ops,
      c.name,
    );
  }
});

test("banca friends-of-social shape gate", () => {
  for (const c of vec.friends) {
    assert.deepEqual(plain(friendsOfSocial(c.dump)), c.out, c.name);
  }
});

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/bot.git