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.

test(legal): cover the deposit address gate and keep money handler suites testing their own guards behind a signed agreement

nirholas7d5f9b760fb6
diff --git a/tests/agent-trade-endpoint.test.js b/tests/agent-trade-endpoint.test.js
index 6751cfab2..a1a1f1868 100644
--- a/tests/agent-trade-endpoint.test.js
+++ b/tests/agent-trade-endpoint.test.js
@@ -29,6 +29,14 @@ const sqlState = {
calls: [],
};
+// The real-funds agreement gate is covered by tests/real-funds-agreement.test.js;
+// here the account has signed, so the handler's own guards are what is under test.
+vi.mock('../api/_lib/real-funds-agreement.js', () => ({
+ requireRealFundsAgreement: vi.fn(async () => true),
+ currentSignatureFor: vi.fn(async () => ({ signedAt: '2026-09-17T00:00:00.000Z', signatureName: 'Test Signer', context: null })),
+ agreementRequirement: () => ({ version: 2, sign_url: 'https://three.ws/legal/agreements', documents: [] }),
+}));
+
vi.mock('../api/_lib/db.js', () => ({
sql: vi.fn(async (strings, ...values) => {
const q = (typeof strings === 'string' ? strings : strings.join('?')).toLowerCase();
diff --git a/tests/agent-wallet-deposit-tab.test.js b/tests/agent-wallet-deposit-tab.test.js
index 3d3aef17d..8659b1700 100644
--- a/tests/agent-wallet-deposit-tab.test.js
+++ b/tests/agent-wallet-deposit-tab.test.js
@@ -11,6 +11,19 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
const fetchAgentSolanaWallet = vi.fn();
const fetchAgentSolanaActivity = vi.fn();
+// The deposit address is revealed only after the real-funds agreements are
+// signed. Most tests here cover the signed funding surface; the gate itself is
+// exercised in its own describe block below.
+const agreement = { signed: true };
+const ensureRiskAck = vi.fn(async () => {
+ agreement.signed = true;
+ return true;
+});
+vi.mock('../src/shared/risk-ack.js', () => ({
+ hasRiskAckVerified: vi.fn(async () => agreement.signed),
+ ensureRiskAck: (...a) => ensureRiskAck(...a),
+}));
+
vi.mock('../src/agent-solana-wallet.js', () => ({
fetchAgentSolanaWallet: (...a) => fetchAgentSolanaWallet(...a),
fetchAgentSolanaActivity: (...a) => fetchAgentSolanaActivity(...a),
@@ -54,6 +67,8 @@ function mountTab(ctx = makeCtx()) {
}
beforeEach(() => {
+ agreement.signed = true;
+ ensureRiskAck.mockClear();
fetchAgentSolanaWallet.mockReset();
fetchAgentSolanaActivity.mockReset();
fetchAgentSolanaActivity.mockResolvedValue({ signatures: [] });
@@ -216,3 +231,58 @@ describe('Deposit tab — public funding surface', () => {
inst.destroy();
});
});
+
+describe('Deposit tab: real-funds agreement gate', () => {
+ it('hides the address, QR, and copy control on mainnet until the visitor signs', async () => {
+ agreement.signed = false;
+ fetchAgentSolanaWallet.mockResolvedValue({ status: 'ok', data: { address: ADDR, sol: 0, deposits_enabled: true } });
+ const { panel, inst } = mountTab();
+ inst.onShow();
+ await tick();
+ expect(panel.textContent).not.toContain(ADDR);
+ expect(panel.querySelector('a.awh-dep-qr')).toBeNull();
+ expect(panel.querySelector('[data-act="copy"]')).toBeNull();
+ expect(panel.querySelector('a[href="/legal/agent-wallet"]')).toBeTruthy();
+ expect(panel.textContent).toMatch(/not responsible for any loss/i);
+ inst.destroy();
+ });
+
+ it('reveals the address after signing', async () => {
+ agreement.signed = false;
+ fetchAgentSolanaWallet.mockResolvedValue({ status: 'ok', data: { address: ADDR, sol: 0, deposits_enabled: true } });
+ const { panel, inst } = mountTab();
+ inst.onShow();
+ await tick();
+ panel.querySelector('[data-act="sign"]').click();
+ await tick();
+ await tick();
+ expect(ensureRiskAck).toHaveBeenCalledWith({ context: 'deposit' });
+ expect(panel.textContent).toContain(ADDR);
+ expect(panel.querySelector('a[href="/legal/agent-wallet"]')).toBeTruthy();
+ inst.destroy();
+ });
+
+ it('keeps the address hidden when the visitor declines', async () => {
+ agreement.signed = false;
+ ensureRiskAck.mockImplementationOnce(async () => false);
+ fetchAgentSolanaWallet.mockResolvedValue({ status: 'ok', data: { address: ADDR, sol: 0, deposits_enabled: true } });
+ const { panel, inst } = mountTab();
+ inst.onShow();
+ await tick();
+ panel.querySelector('[data-act="sign"]').click();
+ await tick();
+ await tick();
+ expect(panel.textContent).not.toContain(ADDR);
+ inst.destroy();
+ });
+
+ it('never gates devnet', async () => {
+ agreement.signed = false;
+ fetchAgentSolanaWallet.mockResolvedValue({ status: 'ok', data: { address: ADDR, sol: 0, deposits_enabled: true } });
+ const { panel, inst } = mountTab(makeCtx({ network: 'devnet', getNetwork: () => 'devnet' }));
+ inst.onShow();
+ await tick();
+ expect(panel.textContent).toContain(ADDR);
+ inst.destroy();
+ });
+});
diff --git a/tests/agent-wallet-trade.test.js b/tests/agent-wallet-trade.test.js
index f2b2ce59c..e76c6e949 100644
--- a/tests/agent-wallet-trade.test.js
+++ b/tests/agent-wallet-trade.test.js
@@ -25,6 +25,14 @@ const MINT = Keypair.generate().publicKey.toBase58();
// ── auth ────────────────────────────────────────────────────────────────────
const authState = { session: { id: 'owner-1' } };
+// The real-funds agreement gate is covered by tests/real-funds-agreement.test.js;
+// here the account has signed, so the handler's own guards are what is under test.
+vi.mock('../api/_lib/real-funds-agreement.js', () => ({
+ requireRealFundsAgreement: vi.fn(async () => true),
+ currentSignatureFor: vi.fn(async () => ({ signedAt: '2026-09-17T00:00:00.000Z', signatureName: 'Test Signer', context: null })),
+ agreementRequirement: () => ({ version: 2, sign_url: 'https://three.ws/legal/agreements', documents: [] }),
+}));
+
vi.mock('../api/_lib/auth.js', () => ({
getSessionUser: vi.fn(async () => authState.session),
authenticateBearer: vi.fn(async () => null),
diff --git a/tests/agent-wallet-withdraw.test.js b/tests/agent-wallet-withdraw.test.js
index b0ea96021..9d77a22e0 100644
--- a/tests/agent-wallet-withdraw.test.js
+++ b/tests/agent-wallet-withdraw.test.js
@@ -20,6 +20,14 @@ process.env.JWT_SECRET = process.env.JWT_SECRET || 'test-secret-for-custody-with
// ── auth ────────────────────────────────────────────────────────────────────
const authState = { session: { id: 'user-1' } };
+// The real-funds agreement gate is covered by tests/real-funds-agreement.test.js;
+// here the account has signed, so the handler's own guards are what is under test.
+vi.mock('../api/_lib/real-funds-agreement.js', () => ({
+ requireRealFundsAgreement: vi.fn(async () => true),
+ currentSignatureFor: vi.fn(async () => ({ signedAt: '2026-09-17T00:00:00.000Z', signatureName: 'Test Signer', context: null })),
+ agreementRequirement: () => ({ version: 2, sign_url: 'https://three.ws/legal/agreements', documents: [] }),
+}));
+
vi.mock('../api/_lib/auth.js', () => ({
getSessionUser: vi.fn(async () => authState.session),
authenticateBearer: vi.fn(async () => null),
diff --git a/tests/agents-subresource-handlers.test.js b/tests/agents-subresource-handlers.test.js
index f547f4a2c..bb2d4f1d4 100644
--- a/tests/agents-subresource-handlers.test.js
+++ b/tests/agents-subresource-handlers.test.js
@@ -23,6 +23,14 @@ const THREE = 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump';
let sessionUser = { id: OWNER };
let agentRow = { id: AGENT, user_id: OWNER, name: 'Test Agent', meta: { solana_address: THREE } };
+// The real-funds agreement gate is covered by tests/real-funds-agreement.test.js;
+// here the account has signed, so the handler's own guards are what is under test.
+vi.mock('../api/_lib/real-funds-agreement.js', () => ({
+ requireRealFundsAgreement: vi.fn(async () => true),
+ currentSignatureFor: vi.fn(async () => ({ signedAt: '2026-09-17T00:00:00.000Z', signatureName: 'Test Signer', context: null })),
+ agreementRequirement: () => ({ version: 2, sign_url: 'https://three.ws/legal/agreements', documents: [] }),
+}));
+
vi.mock('../api/_lib/http.js', () => ({
wrap: (fn) => fn,
cors: () => false,
diff --git a/tests/api/portfolio-action.test.js b/tests/api/portfolio-action.test.js
index 5c083b9d5..5724ea39f 100644
--- a/tests/api/portfolio-action.test.js
+++ b/tests/api/portfolio-action.test.js
@@ -19,6 +19,14 @@ import { describe, it, expect, beforeEach, vi } from 'vitest';
import { makeReq, makeRes } from '../_helpers/monetization.js';
const authState = { session: null };
+// The real-funds agreement gate is covered by tests/real-funds-agreement.test.js;
+// here the account has signed, so the handler's own guards are what is under test.
+vi.mock('../../api/_lib/real-funds-agreement.js', () => ({
+ requireRealFundsAgreement: vi.fn(async () => true),
+ currentSignatureFor: vi.fn(async () => ({ signedAt: '2026-09-17T00:00:00.000Z', signatureName: 'Test Signer', context: null })),
+ agreementRequirement: () => ({ version: 2, sign_url: 'https://three.ws/legal/agreements', documents: [] }),
+}));
+
vi.mock('../../api/_lib/auth.js', () => ({
getSessionUser: vi.fn(async () => authState.session),
isSameSiteOrigin: vi.fn(() => true),
diff --git a/tests/api/purchase-as-agent.test.js b/tests/api/purchase-as-agent.test.js
index 2a531a086..65d51d692 100644
--- a/tests/api/purchase-as-agent.test.js
+++ b/tests/api/purchase-as-agent.test.js
@@ -10,6 +10,14 @@ import { Readable } from 'node:stream';
// ── Mock layer ──────────────────────────────────────────────────────────────
const authState = { session: null };
+// The real-funds agreement gate is covered by tests/real-funds-agreement.test.js;
+// here the account has signed, so the handler's own guards are what is under test.
+vi.mock('../../api/_lib/real-funds-agreement.js', () => ({
+ requireRealFundsAgreement: vi.fn(async () => true),
+ currentSignatureFor: vi.fn(async () => ({ signedAt: '2026-09-17T00:00:00.000Z', signatureName: 'Test Signer', context: null })),
+ agreementRequirement: () => ({ version: 2, sign_url: 'https://three.ws/legal/agreements', documents: [] }),
+}));
+
vi.mock('../../api/_lib/auth.js', () => ({
getSessionUser: vi.fn(async () => authState.session),
authenticateBearer: vi.fn(async () => null),
diff --git a/tests/api/security-csrf-gates.test.js b/tests/api/security-csrf-gates.test.js
index cb0de3f6f..2943c370b 100644
--- a/tests/api/security-csrf-gates.test.js
+++ b/tests/api/security-csrf-gates.test.js
@@ -19,6 +19,14 @@ const sqlState = {
csrfRows: new Map(), // token → { user_id, expires_at }
};
+// The real-funds agreement gate is covered by tests/real-funds-agreement.test.js;
+// here the account has signed, so the handler's own guards are what is under test.
+vi.mock('../../api/_lib/real-funds-agreement.js', () => ({
+ requireRealFundsAgreement: vi.fn(async () => true),
+ currentSignatureFor: vi.fn(async () => ({ signedAt: '2026-09-17T00:00:00.000Z', signatureName: 'Test Signer', context: null })),
+ agreementRequirement: () => ({ version: 2, sign_url: 'https://three.ws/legal/agreements', documents: [] }),
+}));
+
vi.mock('../../api/_lib/auth.js', () => ({
getSessionUser: vi.fn(async () => authState.session),
authenticateBearer: vi.fn(async () => authState.bearer),
diff --git a/tests/autopilot-run-dry-run-default.test.js b/tests/autopilot-run-dry-run-default.test.js
index 2130e1027..b00b03e25 100644
--- a/tests/autopilot-run-dry-run-default.test.js
+++ b/tests/autopilot-run-dry-run-default.test.js
@@ -11,6 +11,14 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
const runAutopilotCycleMock = vi.fn(async () => ({ ran: true, results: [] }));
+// The real-funds agreement gate is covered by tests/real-funds-agreement.test.js;
+// here the account has signed, so the handler's own guards are what is under test.
+vi.mock('../api/_lib/real-funds-agreement.js', () => ({
+ requireRealFundsAgreement: vi.fn(async () => true),
+ currentSignatureFor: vi.fn(async () => ({ signedAt: '2026-09-17T00:00:00.000Z', signatureName: 'Test Signer', context: null })),
+ agreementRequirement: () => ({ version: 2, sign_url: 'https://three.ws/legal/agreements', documents: [] }),
+}));
+
vi.mock('../api/_lib/treasury-autopilot.js', () => ({
getAutopilot: vi.fn(() => ({ armed: true })),
setAutopilot: vi.fn(async () => ({})),
diff --git a/tests/oracle/watch-live-arm.test.js b/tests/oracle/watch-live-arm.test.js
index 94a1726bf..160847bc7 100644
--- a/tests/oracle/watch-live-arm.test.js
+++ b/tests/oracle/watch-live-arm.test.js
@@ -14,6 +14,14 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
+// The real-funds agreement gate is covered by tests/real-funds-agreement.test.js;
+// here the account has signed, so the handler's own guards are what is under test.
+vi.mock('../../api/_lib/real-funds-agreement.js', () => ({
+ requireRealFundsAgreement: vi.fn(async () => true),
+ currentSignatureFor: vi.fn(async () => ({ signedAt: '2026-09-17T00:00:00.000Z', signatureName: 'Test Signer', context: null })),
+ agreementRequirement: () => ({ version: 2, sign_url: 'https://three.ws/legal/agreements', documents: [] }),
+}));
+
vi.mock('../../api/_lib/http.js', async () => {
const actual = await vi.importActual('../../api/_lib/http.js');
return {
diff --git a/tests/solana-trade-guards.test.js b/tests/solana-trade-guards.test.js
index b4774a68e..8d781cafb 100644
--- a/tests/solana-trade-guards.test.js
+++ b/tests/solana-trade-guards.test.js
@@ -14,6 +14,14 @@ const AGENT_ADDR = Keypair.generate().publicKey.toBase58();
const MINT = Keypair.generate().publicKey.toBase58();
const sqlState = { agent: null, existingCustody: null };
+// The real-funds agreement gate is covered by tests/real-funds-agreement.test.js;
+// here the account has signed, so the handler's own guards are what is under test.
+vi.mock('../api/_lib/real-funds-agreement.js', () => ({
+ requireRealFundsAgreement: vi.fn(async () => true),
+ currentSignatureFor: vi.fn(async () => ({ signedAt: '2026-09-17T00:00:00.000Z', signatureName: 'Test Signer', context: null })),
+ agreementRequirement: () => ({ version: 2, sign_url: 'https://three.ws/legal/agreements', documents: [] }),
+}));
+
vi.mock('../api/_lib/db.js', () => ({
sql: vi.fn(async (strings) => {
const q = (typeof strings === 'string' ? strings : strings.join('?')).toLowerCase();
diff --git a/tests/vaults-api-guards.test.js b/tests/vaults-api-guards.test.js
index 19c8ba20d..53e21636c 100644
--- a/tests/vaults-api-guards.test.js
+++ b/tests/vaults-api-guards.test.js
@@ -17,6 +17,14 @@ const MINT = 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump';
const authWriteMock = vi.fn();
const resolveUserIdMock = vi.fn();
const loadOwnedAgentMock = vi.fn();
+// The real-funds agreement gate is covered by tests/real-funds-agreement.test.js;
+// here the account has signed, so the handler's own guards are what is under test.
+vi.mock('../api/_lib/real-funds-agreement.js', () => ({
+ requireRealFundsAgreement: vi.fn(async () => true),
+ currentSignatureFor: vi.fn(async () => ({ signedAt: '2026-09-17T00:00:00.000Z', signatureName: 'Test Signer', context: null })),
+ agreementRequirement: () => ({ version: 2, sign_url: 'https://three.ws/legal/agreements', documents: [] }),
+}));
+
vi.mock('../api/_lib/vault-auth.js', () => ({
authWrite: (...a) => authWriteMock(...a),
resolveUserId: (...a) => resolveUserIdMock(...a),