Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(play): repair holder-world admission and harden the multiplayer room for event crowds

nirholase240690c4560
diff --git a/api/_lib/display-name-safety.js b/api/_lib/display-name-safety.js
index 91a48a453..3d976c030 100644
--- a/api/_lib/display-name-safety.js
+++ b/api/_lib/display-name-safety.js
@@ -3,7 +3,7 @@
// Hate-slur gate for THIRD-PARTY text we index and render as our own UI.
//
// The ERC-8004 crawler indexes every agent registered on-chain across several
-// chains — 126k rows and climbing — and hydrates each one's display name,
+// chains (126k rows and climbing) and hydrates each one's display name,
// description and image straight from attacker-controlled metadata. Until this
// gate existed, whether a row appeared on three.ws was decided by a single line:
//
@@ -21,7 +21,7 @@
// Agent and token names are crude by nature; "shit", "damn", "hell" pass.
// • WHOLE-WORD matching. Substring matching is what makes naive filters useless:
// it flags "kikel-jina69" (an Olas-generated agent name) and "Scunthorpe".
-// • Hex-aware. Names routinely embed addresses — "Surf AI for 0xdb6b887289c380…".
+// • Hex-aware. Names routinely embed addresses, e.g. "Surf AI for 0xdb6b887289c380…".
// Leetspeak folding (0→o, 3→e, 8→b …) turns any address into letter soup, and
// a long enough one contains almost any short stem. Addresses are excluded
// from the letters-only evasion pass, and short stems are never matched inside
@@ -31,16 +31,16 @@
// via scripts/deactivate-slur-agents.mjs. Every public feed already filters
// `active = true`, so one flag covers explore, marketplace, agents, and search.
//
-// Dependency-free and synchronous — the crawler hydrates thousands of rows per tick
+// Dependency-free and synchronous: the crawler hydrates thousands of rows per tick
// and must not pay a network hop per name.
// Stems in canonical (folded, lowercase) form. Matched as WHOLE WORDS, with an
// optional plural/possessive tail, never as bare substrings.
//
// Notably absent, and why:
-// • "coon" — "Coon" is a common surname, and "raccoon"/"tycoon"/"Coon Rapids"
+// • "coon" : "Coon" is a common surname, and "raccoon"/"tycoon"/"Coon Rapids"
// are ordinary. Even whole-word, the false-positive cost is too high.
-// • "spic" — kept, because whole-word cannot reach inside "spice"/"spicy".
+// • "spic" : kept, because whole-word cannot reach inside "spice"/"spicy".
const SLUR_STEMS = [
'nigger',
'nigga',
@@ -100,22 +100,22 @@ const STEM_RE = new RegExp(`^(?:${SLUR_STEMS.join('|')})${TAIL}$`);
* Which slur stem the text contains, or null. Whole-word only.
*
* Two passes:
- * 1. Token pass — split on non-letters, fold each token, require a whole-word hit.
+ * 1. Token pass: split on non-letters, fold each token, require a whole-word hit.
* Catches "Real Hood Nigger Shit" and "N1GG3R", and cannot reach inside
* "kikel-jina69" or a hex address.
- * 2. Squeezed pass — join the letters and look for a whole stem, to catch the
+ * 2. Squeezed pass: join the letters and look for a whole stem, to catch the
* deliberately spaced "n.i.g.g.e.r" / "n i g g e r". Skipped entirely when the
* text carries a long alphanumeric run (an address), because squeezing one of
* those manufactures matches out of nothing.
*
- * @param {string} text — a display name, a description, or both concatenated.
+ * @param {string} text a display name, a description, or both concatenated.
* @returns {string|null} the matched stem, for logging. Never surfaced to users.
*/
export function matchedSlurStem(text) {
const raw = String(text || '');
if (!raw.trim()) return null;
- // Pass 1 — whole-word over folded tokens.
+ // Pass 1: whole-word over folded tokens.
for (const token of foldLeet(raw).split(/[^a-z]+/)) {
if (!token) continue;
const t = collapseRuns(token);
@@ -123,10 +123,10 @@ export function matchedSlurStem(text) {
if (hit) return hit;
}
- // Pass 2 — the spaced-out evasion ("n.i.g.g.e.r", "n i g g e r").
+ // Pass 2: the spaced-out evasion ("n.i.g.g.e.r", "n i g g e r").
//
// Squeezing text destroys word boundaries, so this pass can only ever be a
- // substring match — which on ordinary text flags "Spicy Trades" for "spic".
+ // substring match, which on ordinary text flags "Spicy Trades" for "spic".
// Run it only when the text bears the evasion's signature: a run of isolated
// single letters. Real names do not spell themselves out one character at a time.
if (LONG_ALNUM_RUN.test(raw)) return null;
diff --git a/multiplayer/src/combat-handlers.js b/multiplayer/src/combat-handlers.js
index 52124c5e6..ccd494c7d 100644
--- a/multiplayer/src/combat-handlers.js
+++ b/multiplayer/src/combat-handlers.js
@@ -114,8 +114,11 @@ export function tickMobs(room, dtMs) {
}
if (!target) {
- if (mob.state !== 'idle') mob.state = 'idle';
- mob.tsServer = now;
+ // Stamp tsServer only on the transition to idle, never every tick: an
+ // unconditional write dirties a synced float64 for every alive mob at
+ // 5Hz, which kept every state patch non-empty for every client even in
+ // an empty world. An idle mob's fields are static; peers need no tick.
+ if (mob.state !== 'idle') { mob.state = 'idle'; mob.tsServer = now; }
continue;
}
diff --git a/multiplayer/src/display-name-safety.js b/multiplayer/src/display-name-safety.js
new file mode 100644
index 000000000..3d976c030
--- /dev/null
+++ b/multiplayer/src/display-name-safety.js
@@ -0,0 +1,149 @@
+// api/_lib/display-name-safety.js
+//
+// Hate-slur gate for THIRD-PARTY text we index and render as our own UI.
+//
+// The ERC-8004 crawler indexes every agent registered on-chain across several
+// chains (126k rows and climbing) and hydrates each one's display name,
+// description and image straight from attacker-controlled metadata. Until this
+// gate existed, whether a row appeared on three.ws was decided by a single line:
+//
+// const active = meta.active !== false; // the agent's own metadata says so
+//
+// Nothing checked what the name said. A Base-registered agent whose name was a
+// racial slur was `active`, `has_3d`, and rendered on /marketplace.
+//
+// ── PRECISION IS THE WHOLE PROBLEM ───────────────────────────────────────────
+// A false negative shows a slur once. A false positive silently delists a
+// legitimate on-chain agent forever, with no appeal and no signal to its owner.
+// The second failure is the one that scales, so this gate is deliberately narrow:
+//
+// • Unambiguous racial / ethnic / anti-LGBT slurs only. NOT a profanity filter.
+// Agent and token names are crude by nature; "shit", "damn", "hell" pass.
+// • WHOLE-WORD matching. Substring matching is what makes naive filters useless:
+// it flags "kikel-jina69" (an Olas-generated agent name) and "Scunthorpe".
+// • Hex-aware. Names routinely embed addresses, e.g. "Surf AI for 0xdb6b887289c380…".
+// Leetspeak folding (0→o, 3→e, 8→b …) turns any address into letter soup, and
+// a long enough one contains almost any short stem. Addresses are excluded
+// from the letters-only evasion pass, and short stems are never matched inside
+// a long alphanumeric run.
+//
+// Applied at hydration (a slur never becomes `active`) and to already-indexed rows
+// via scripts/deactivate-slur-agents.mjs. Every public feed already filters
+// `active = true`, so one flag covers explore, marketplace, agents, and search.
+//
+// Dependency-free and synchronous: the crawler hydrates thousands of rows per tick
+// and must not pay a network hop per name.
+
+// Stems in canonical (folded, lowercase) form. Matched as WHOLE WORDS, with an
+// optional plural/possessive tail, never as bare substrings.
+//
+// Notably absent, and why:
+// • "coon" : "Coon" is a common surname, and "raccoon"/"tycoon"/"Coon Rapids"
+// are ordinary. Even whole-word, the false-positive cost is too high.
+// • "spic" : kept, because whole-word cannot reach inside "spice"/"spicy".
+const SLUR_STEMS = [
+ 'nigger',
+ 'nigga',
+ 'faggot',
+ 'kike',
+ 'wetback',
+ 'tranny',
+ 'trannie',
+ 'chink',
+ 'gook',
+ 'beaner',
+ 'spic',
+];
+
+// Optional tails a slur is commonly written with. Anything longer is a different
+// word (e.g. "kikel", "spice") and must not match.
+const TAIL = '(?:s|es|z|ies)?';
+
+// Leetspeak / homoglyph folding, applied per token.
+const LEET = new Map(
+ Object.entries({
+ '0': 'o', '1': 'i', '!': 'i', '|': 'i', '3': 'e', '4': 'a',
+ '@': 'a', '5': 's', $: 's', '7': 't', '+': 't', '8': 'b', '9': 'g',
+ }),
+);
+
+// An address, tx hash, or long id. Folding digits inside one of these produces
+// arbitrary letters, so it is never eligible for the letters-only evasion pass.
+const LONG_ALNUM_RUN = /(?:0x)?[0-9a-f]{10,}/i;
+
+function foldLeet(text) {
+ return String(text || '')
+ .toLowerCase()
+ .split('')
+ .map((ch) => LEET.get(ch) ?? ch)
+ .join('');
+}
+
+// "niiiiigger" → "niigger". Two is enough to leave "aa"/"ll" words intact.
+function collapseRuns(text) {
+ return text.replace(/([a-z])\1{2,}/g, '$1$1');
+}
+
+/**
+ * Canonical form used for matching: lowercase, leet folded, long runs collapsed.
+ * Exported for tests and for the audit script's logging.
+ * @param {string} text
+ * @returns {string}
+ */
+export function normalizeForSlurMatch(text) {
+ return collapseRuns(foldLeet(text));
+}
+
+const STEM_RE = new RegExp(`^(?:${SLUR_STEMS.join('|')})${TAIL}$`);
+
+/**
+ * Which slur stem the text contains, or null. Whole-word only.
+ *
+ * Two passes:
+ * 1. Token pass: split on non-letters, fold each token, require a whole-word hit.
+ * Catches "Real Hood Nigger Shit" and "N1GG3R", and cannot reach inside
+ * "kikel-jina69" or a hex address.
+ * 2. Squeezed pass: join the letters and look for a whole stem, to catch the
+ * deliberately spaced "n.i.g.g.e.r" / "n i g g e r". Skipped entirely when the
+ * text carries a long alphanumeric run (an address), because squeezing one of
+ * those manufactures matches out of nothing.
+ *
+ * @param {string} text a display name, a description, or both concatenated.
+ * @returns {string|null} the matched stem, for logging. Never surfaced to users.
+ */
+export function matchedSlurStem(text) {
+ const raw = String(text || '');
+ if (!raw.trim()) return null;
+
+ // Pass 1: whole-word over folded tokens.
+ for (const token of foldLeet(raw).split(/[^a-z]+/)) {
+ if (!token) continue;
+ const t = collapseRuns(token);
+ const hit = SLUR_STEMS.find((stem) => STEM_RE.test(t) && t.startsWith(stem));
+ if (hit) return hit;
+ }
+
+ // Pass 2: the spaced-out evasion ("n.i.g.g.e.r", "n i g g e r").
+ //
+ // Squeezing text destroys word boundaries, so this pass can only ever be a
+ // substring match, which on ordinary text flags "Spicy Trades" for "spic".
+ // Run it only when the text bears the evasion's signature: a run of isolated
+ // single letters. Real names do not spell themselves out one character at a time.
+ if (LONG_ALNUM_RUN.test(raw)) return null;
+ const tokens = foldLeet(raw).split(/[^a-z]+/).filter(Boolean);
+ const singles = tokens.filter((t) => t.length === 1).length;
+ if (singles < 4) return null;
+
+ const squeezed = collapseRuns(tokens.join(''));
+ if (squeezed.length > 40) return null; // a long description squeezed is a match generator
+ return SLUR_STEMS.find((stem) => squeezed.includes(stem)) ?? null;
+}
+
+/**
+ * True when the text contains an unambiguous hate slur.
+ * @param {string} text
+ * @returns {boolean}
+ */
+export function containsHateSlur(text) {
+ return matchedSlurStem(text) !== null;
+}
diff --git a/multiplayer/src/rooms/ClashRoom.js b/multiplayer/src/rooms/ClashRoom.js
index 19ee0f0fa..5076d43a6 100644
--- a/multiplayer/src/rooms/ClashRoom.js
+++ b/multiplayer/src/rooms/ClashRoom.js
@@ -59,7 +59,13 @@ export class ClashRoom extends Room {
// what makes a clash a battle BETWEEN communities — you can only wear a community's
// colours if you actually hold its coin. The faction must also be one of the two in
// this match. Throw on refusal so the client routes back to its gate.
- static onAuth(client, options) {
+ //
+ // INSTANCE method, not static: Colyseus 0.16 calls a static onAuth as
+ // onAuth(token, options, context) with the HTTP bearer token (undefined for
+ // our clients) as the first argument, so the old static form crashed with a
+ // TypeError on client.userData for EVERY join. Instance onAuth receives the
+ // real client at WS join time. Mirrors the same fix in WalkRoom.
+ onAuth(client, options) {
if (PLAY_GATE_MINT) {
const pass = verifyPlayPass(options?.playPass);
if (!pass) throw new Error('play_pass_required');
diff --git a/multiplayer/src/rooms/WalkRoom.js b/multiplayer/src/rooms/WalkRoom.js
index 58b849ace..f65bec5db 100644
--- a/multiplayer/src/rooms/WalkRoom.js
+++ b/multiplayer/src/rooms/WalkRoom.js
@@ -34,6 +34,7 @@ import { verifyHolderPass } from '../holder-pass.js';
import { socialHub } from '../social-hub.js';
import { verifyPresenceTicket } from '../presence-token.js';
import { verifyPlayPass } from '../play-pass.js';
+import { containsHateSlur } from '../display-name-safety.js';
import { installUnknownMessageGuard, PLAY_PASS_EVICT_CODE } from '../room-compat.js';
import {
restoreProfile, serializeProfile, profileSnapshot,
@@ -94,7 +95,18 @@ const PLAY_GATE_MIN = (() => {
return Number.isFinite(n) && n > 0 ? n : 1;
})();
-const MAX_CLIENTS_PER_ROOM = 50;
+// Room ceiling. When a room fills, Colyseus's joinOrCreate silently spawns a
+// second instance with the same (coin, tier) filter: players past the cap land
+// in a parallel copy of the world with no UI signal that their friends are in
+// the other one. Until that spillover has a real client-side story, keep the
+// cap high enough that a live-event crowd fits in ONE room: at 100 clients the
+// move-sync cost is ~40KB/s down per client (99 peers × ~28B × 15Hz), well
+// inside both the container and a normal connection. Override per-deploy with
+// WALK_ROOM_MAX_CLIENTS; the env guard clamps nonsense values.
+const MAX_CLIENTS_PER_ROOM = (() => {
+ const n = Number(process.env.WALK_ROOM_MAX_CLIENTS);
+ return Number.isFinite(n) && n >= 2 && n <= 500 ? Math.floor(n) : 100;
+})();
const PATCH_RATE_HZ = 15;
const PATCH_RATE_MS = 1000 / PATCH_RATE_HZ;
@@ -285,6 +297,11 @@ const ACTION_RATES = {
// Wheel of Fortune (W09) — deliberate, low-frequency, currency/payment-mutating
// actions, throttled like the boutique's above.
spinInfo: 4, spinFree: 3, spinPaidPrep: 3, spinPaidSettle: 3,
+ // Identity mutations. Each write dirties a synced string field that fans out
+ // to every client in the room, so an unthrottled flood is a broadcast
+ // amplifier: 2/s covers every legitimate use (a typo fix, a mid-session
+ // avatar swap) with a wide margin.
+ rename: 2, avatar: 2, voiceState: 4,
};
// Spatial voice signaling. The room only relays SDP/ICE between two peers (the
@@ -364,8 +381,16 @@ export class WalkRoom extends Room {
// token the API mints after pricing the user's authenticated wallet against
// HOLDER_MIN_USD of this exact coin. We verify the pass here, before onJoin,
// and reject otherwise. Returning false makes Colyseus answer the
- // matchmake/seat request with a 401 the client surfaces as the locked gate.
- static onAuth(client, options) {
+ // join with an auth error the client surfaces as the locked gate.
+ //
+ // INSTANCE method, not static, and that is load-bearing: Colyseus 0.16 calls
+ // a *static* onAuth as onAuth(token, options, context), where token is the
+ // HTTP bearer token (undefined for our clients). The old static declaration
+ // here received that undefined as "client", so every path that assigned
+ // client.userData (the play gate and the whole holder tier) threw a
+ // TypeError on join. The instance form receives the real client at WS join
+ // time and its return value is stored as client.auth.
+ onAuth(client, options) {
// Platform token gate (orthogonal to the per-coin holder tier below). When a
// game token is pinned, no client reaches any world — General or Holders —
// without a play pass proving a signed-in wallet holds ≥ the floor. Throw
@@ -714,7 +739,11 @@ export class WalkRoom extends Room {
}
async onJoin(client, options) {
- const name = clean(options?.name, 24) || `guest-${client.sessionId.slice(0, 4)}`;
+ // A hate-slur display name never reaches a nameplate: fall back to the
+ // guest handle, same narrow whole-word gate the platform uses on indexed
+ // third-party names (see display-name-safety.js).
+ let name = clean(options?.name, 24) || `guest-${client.sessionId.slice(0, 4)}`;
+ if (containsHateSlur(name)) name = `guest-${client.sessionId.slice(0, 4)}`;
const player = new Player();
player.id = client.sessionId;
player.name = name;
@@ -1489,8 +1518,13 @@ export class WalkRoom extends Room {
_handleRename(client, payload) {
const player = this.state.players.get(client.sessionId);
if (!player) return;
+ if (!this._actionOk(client.sessionId, 'rename')) return;
const name = clean(payload?.name, 24);
if (!name) return;
+ // Same narrow whole-word hate-slur gate the platform applies to indexed
+ // display names. A refused rename is a silent no-op: the previous name
+ // stands, and there is nothing to explain to someone probing the filter.
+ if (containsHateSlur(name)) return;
player.name = name;
}
@@ -1525,6 +1559,10 @@ export class WalkRoom extends Room {
if (!player) return;
const text = clean(payload?.text, 200);
if (!text) return;
+ // Narrow whole-word hate-slur gate (see display-name-safety.js): deliberately
+ // NOT a profanity filter (crypto chat is crude by nature), but a slur is
+ // never relayed to fifty screens with our nameplate UI around it.
+ if (containsHateSlur(text)) return;
// One message per 700ms per client — enough for conversation, not spam.
const now = Date.now();
const last = this._chatCooldowns.get(client.sessionId) || 0;
@@ -1540,6 +1578,7 @@ export class WalkRoom extends Room {
// without rejoining the room.
const player = this.state.players.get(client.sessionId);
if (!player) return;
+ if (!this._actionOk(client.sessionId, 'avatar')) return;
const url = cleanAvatarUrl(payload?.avatar);
if (url) player.avatar = url;
if (typeof payload?.agent === 'string') player.agent = clean(payload.agent, 64);
@@ -1552,6 +1591,7 @@ export class WalkRoom extends Room {
_handleVoiceState(client, payload) {
const player = this.state.players.get(client.sessionId);
if (!player) return;
+ if (!this._actionOk(client.sessionId, 'voiceState')) return;
player.voice = !!(payload && payload.on);
}
diff --git a/tests/display-name-safety-mirror.test.js b/tests/display-name-safety-mirror.test.js
new file mode 100644
index 000000000..c9de4987c
--- /dev/null
+++ b/tests/display-name-safety-mirror.test.js
@@ -0,0 +1,20 @@
+// Drift guard: multiplayer/src/display-name-safety.js is a byte-for-byte mirror
+// of api/_lib/display-name-safety.js.
+//
+// Why a copy exists at all: the multiplayer service deploys from the
+// multiplayer/ directory alone (deploy-cloudrun.sh runs `gcloud run deploy
+// --source .` from there), so it cannot import across the repo boundary at
+// runtime. The chat/name gate in WalkRoom therefore ships its own copy. This
+// test is what keeps the copy honest: edit the api/_lib module and this fails
+// until the mirror is re-copied, exactly like the spatial-mcp package mirror.
+
+import { describe, it, expect } from 'vitest';
+import { readFileSync } from 'node:fs';
+
+describe('display-name-safety mirror', () => {
+ it('multiplayer copy is byte-identical to api/_lib source', () => {
+ const source = readFileSync(new URL('../api/_lib/display-name-safety.js', import.meta.url), 'utf8');
+ const mirror = readFileSync(new URL('../multiplayer/src/display-name-safety.js', import.meta.url), 'utf8');
+ expect(mirror).toBe(source);
+ });
+});
diff --git a/tests/room-onauth.test.js b/tests/room-onauth.test.js
new file mode 100644
index 000000000..813634e86
--- /dev/null
+++ b/tests/room-onauth.test.js
@@ -0,0 +1,89 @@
+// Room admission (onAuth): pins the Colyseus 0.16 contract that broke holder
+// worlds in production.
+//
+// Colyseus 0.16 has two distinct onAuth shapes:
+// static onAuth(token, options, context) : token = HTTP bearer token
+// onAuth(client, options, context) : instance method, real client
+//
+// WalkRoom and ClashRoom used to declare `static onAuth(client, options)`,
+// which meant the first argument was actually the bearer token (undefined for
+// colyseus.js clients). Every path that assigned client.userData: the whole
+// holder tier and the platform play gate: threw a TypeError on join. These
+// tests pin (a) that both rooms declare the INSTANCE form and no static
+// override, and (b) the gate behaviour itself: valid pass admits and binds the
+// verified wallet to client.userData, missing/mismatched pass refuses with the
+// tagged error the client gates route on.
+//
+// The pass is minted by the real API signer (api/_lib/holder-pass.js) and
+// verified by the real multiplayer verifier: both fall back to the same dev
+// secret when HOLDER_PASS_SECRET is unset, which is exactly the production
+// wire contract ("byte-for-byte compatible").
+
+import { describe, it, expect } from 'vitest';
+import { WalkRoom } from '../multiplayer/src/rooms/WalkRoom.js';
+import { ClashRoom } from '../multiplayer/src/rooms/ClashRoom.js';
+import { signHolderPass } from '../api/_lib/holder-pass.js';
+
+const MINT = 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump';
+const WALLET = 'So11111111111111111111111111111111111111112';
+
+// onAuth never reads `this`, so bind a bare object: no need to boot a full
+// Colyseus room (schema, clock, presence) just to exercise admission.
+const walkAuth = (client, options) => WalkRoom.prototype.onAuth.call({}, client, options);
+const clashAuth = (client, options) => ClashRoom.prototype.onAuth.call({}, client, options);
+
+describe('onAuth declaration shape', () => {
+ it('WalkRoom declares instance onAuth and no static override', () => {
+ expect(Object.prototype.hasOwnProperty.call(WalkRoom.prototype, 'onAuth')).toBe(true);
+ expect(Object.prototype.hasOwnProperty.call(WalkRoom, 'onAuth')).toBe(false);
+ });
+ it('ClashRoom declares instance onAuth and no static override', () => {
+ expect(Object.prototype.hasOwnProperty.call(ClashRoom.prototype, 'onAuth')).toBe(true);
+ expect(Object.prototype.hasOwnProperty.call(ClashRoom, 'onAuth')).toBe(false);
+ });
+});
+
+describe('WalkRoom.onAuth: holder tier', () => {
+ it('admits the open General world without any pass', () => {
+ const client = {};
+ expect(walkAuth(client, { tier: '' })).toBe(true);
+ expect(client.userData).toBeUndefined();
+ });
+
+ it('admits a holder join with a valid pass and binds the verified wallet', () => {
+ const client = {};
+ const holderPass = signHolderPass({ mint: MINT, wallet: WALLET, usd: 25 });
+ expect(walkAuth(client, { tier: 'holders', coin: MINT, holderPass })).toBe(true);
+ expect(client.userData.holderWallet).toBe(WALLET);
+ expect(client.userData.holderUsd).toBe(25);
+ });
+
+ it('refuses a holder join with no pass', () => {
+ expect(() => walkAuth({}, { tier: 'holders', coin: MINT })).toThrow(/holder_pass_required/);
+ });
+
+ it('refuses a pass minted for a different coin', () => {
+ const holderPass = signHolderPass({ mint: 'OtherMint1111111111111111111111111111111111', wallet: WALLET, usd: 25 });
+ expect(() => walkAuth({}, { tier: 'holders', coin: MINT, holderPass })).toThrow(/holder_pass_mismatch/);
+ });
+
+ it('refuses a tampered pass', () => {
+ const holderPass = signHolderPass({ mint: MINT, wallet: WALLET, usd: 25 });
+ expect(() => walkAuth({}, { tier: 'holders', coin: MINT, holderPass: holderPass.slice(0, -2) + 'xx' }))
+ .toThrow(/holder_pass_required/);
+ });
+});
+
+describe('ClashRoom.onAuth: faction gate', () => {
+ it('admits a fighter holding the coin they fight for', () => {
+ const client = {};
+ const holderPass = signHolderPass({ mint: MINT, wallet: WALLET, usd: 25 });
+ expect(clashAuth(client, { coin: MINT, holderPass })).toBe(true);
+ expect(client.userData.account).toBe(WALLET);
+ expect(client.userData.faction).toBe(MINT);
+ });
+
+ it('refuses a fighter without a pass for their declared faction', () => {
+ expect(() => clashAuth({}, { coin: MINT })).toThrow(/holder_pass_required/);
+ });
+});