openclaw-overlay-plugin 0.7.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +406 -0
- package/SKILL.md +78 -0
- package/clawdbot.plugin.json +106 -0
- package/dist/cli-main.d.ts +7 -0
- package/dist/cli-main.js +192 -0
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +14 -0
- package/dist/core/config.d.ts +11 -0
- package/dist/core/config.js +13 -0
- package/dist/core/index.d.ts +25 -0
- package/dist/core/index.js +26 -0
- package/dist/core/payment.d.ts +16 -0
- package/dist/core/payment.js +94 -0
- package/dist/core/types.d.ts +94 -0
- package/dist/core/types.js +4 -0
- package/dist/core/verify.d.ts +28 -0
- package/dist/core/verify.js +104 -0
- package/dist/core/wallet.d.ts +99 -0
- package/dist/core/wallet.js +219 -0
- package/dist/scripts/baemail/commands.d.ts +64 -0
- package/dist/scripts/baemail/commands.js +258 -0
- package/dist/scripts/baemail/handler.d.ts +36 -0
- package/dist/scripts/baemail/handler.js +284 -0
- package/dist/scripts/baemail/index.d.ts +5 -0
- package/dist/scripts/baemail/index.js +5 -0
- package/dist/scripts/config.d.ts +48 -0
- package/dist/scripts/config.js +68 -0
- package/dist/scripts/index.d.ts +7 -0
- package/dist/scripts/index.js +7 -0
- package/dist/scripts/messaging/connect.d.ts +8 -0
- package/dist/scripts/messaging/connect.js +114 -0
- package/dist/scripts/messaging/handlers.d.ts +21 -0
- package/dist/scripts/messaging/handlers.js +334 -0
- package/dist/scripts/messaging/inbox.d.ts +11 -0
- package/dist/scripts/messaging/inbox.js +51 -0
- package/dist/scripts/messaging/index.d.ts +8 -0
- package/dist/scripts/messaging/index.js +8 -0
- package/dist/scripts/messaging/poll.d.ts +7 -0
- package/dist/scripts/messaging/poll.js +52 -0
- package/dist/scripts/messaging/send.d.ts +7 -0
- package/dist/scripts/messaging/send.js +43 -0
- package/dist/scripts/output.d.ts +12 -0
- package/dist/scripts/output.js +19 -0
- package/dist/scripts/overlay/discover.d.ts +7 -0
- package/dist/scripts/overlay/discover.js +72 -0
- package/dist/scripts/overlay/index.d.ts +7 -0
- package/dist/scripts/overlay/index.js +7 -0
- package/dist/scripts/overlay/registration.d.ts +19 -0
- package/dist/scripts/overlay/registration.js +176 -0
- package/dist/scripts/overlay/services.d.ts +29 -0
- package/dist/scripts/overlay/services.js +167 -0
- package/dist/scripts/overlay/transaction.d.ts +42 -0
- package/dist/scripts/overlay/transaction.js +103 -0
- package/dist/scripts/payment/build.d.ts +24 -0
- package/dist/scripts/payment/build.js +54 -0
- package/dist/scripts/payment/commands.d.ts +15 -0
- package/dist/scripts/payment/commands.js +73 -0
- package/dist/scripts/payment/index.d.ts +6 -0
- package/dist/scripts/payment/index.js +6 -0
- package/dist/scripts/payment/types.d.ts +56 -0
- package/dist/scripts/payment/types.js +4 -0
- package/dist/scripts/services/index.d.ts +6 -0
- package/dist/scripts/services/index.js +6 -0
- package/dist/scripts/services/queue.d.ts +11 -0
- package/dist/scripts/services/queue.js +28 -0
- package/dist/scripts/services/request.d.ts +7 -0
- package/dist/scripts/services/request.js +82 -0
- package/dist/scripts/services/respond.d.ts +11 -0
- package/dist/scripts/services/respond.js +132 -0
- package/dist/scripts/types.d.ts +107 -0
- package/dist/scripts/types.js +4 -0
- package/dist/scripts/utils/index.d.ts +6 -0
- package/dist/scripts/utils/index.js +6 -0
- package/dist/scripts/utils/merkle.d.ts +12 -0
- package/dist/scripts/utils/merkle.js +47 -0
- package/dist/scripts/utils/storage.d.ts +66 -0
- package/dist/scripts/utils/storage.js +211 -0
- package/dist/scripts/utils/woc.d.ts +26 -0
- package/dist/scripts/utils/woc.js +91 -0
- package/dist/scripts/wallet/balance.d.ts +22 -0
- package/dist/scripts/wallet/balance.js +240 -0
- package/dist/scripts/wallet/identity.d.ts +70 -0
- package/dist/scripts/wallet/identity.js +151 -0
- package/dist/scripts/wallet/index.d.ts +6 -0
- package/dist/scripts/wallet/index.js +6 -0
- package/dist/scripts/wallet/setup.d.ts +15 -0
- package/dist/scripts/wallet/setup.js +105 -0
- package/dist/scripts/x-verification/commands.d.ts +27 -0
- package/dist/scripts/x-verification/commands.js +222 -0
- package/dist/scripts/x-verification/index.d.ts +4 -0
- package/dist/scripts/x-verification/index.js +4 -0
- package/dist/services/built-in/api-proxy/index.d.ts +6 -0
- package/dist/services/built-in/api-proxy/index.js +23 -0
- package/dist/services/built-in/code-develop/index.d.ts +6 -0
- package/dist/services/built-in/code-develop/index.js +23 -0
- package/dist/services/built-in/code-review/index.d.ts +10 -0
- package/dist/services/built-in/code-review/index.js +51 -0
- package/dist/services/built-in/image-analysis/index.d.ts +6 -0
- package/dist/services/built-in/image-analysis/index.js +33 -0
- package/dist/services/built-in/memory-store/index.d.ts +6 -0
- package/dist/services/built-in/memory-store/index.js +22 -0
- package/dist/services/built-in/roulette/index.d.ts +6 -0
- package/dist/services/built-in/roulette/index.js +27 -0
- package/dist/services/built-in/summarize/index.d.ts +6 -0
- package/dist/services/built-in/summarize/index.js +21 -0
- package/dist/services/built-in/tell-joke/handler.d.ts +7 -0
- package/dist/services/built-in/tell-joke/handler.js +122 -0
- package/dist/services/built-in/tell-joke/index.d.ts +9 -0
- package/dist/services/built-in/tell-joke/index.js +31 -0
- package/dist/services/built-in/translate/index.d.ts +6 -0
- package/dist/services/built-in/translate/index.js +21 -0
- package/dist/services/built-in/web-research/index.d.ts +9 -0
- package/dist/services/built-in/web-research/index.js +51 -0
- package/dist/services/index.d.ts +13 -0
- package/dist/services/index.js +14 -0
- package/dist/services/loader.d.ts +77 -0
- package/dist/services/loader.js +292 -0
- package/dist/services/manager.d.ts +86 -0
- package/dist/services/manager.js +255 -0
- package/dist/services/registry.d.ts +98 -0
- package/dist/services/registry.js +204 -0
- package/dist/services/types.d.ts +230 -0
- package/dist/services/types.js +30 -0
- package/dist/test/cli.test.d.ts +7 -0
- package/dist/test/cli.test.js +329 -0
- package/dist/test/comprehensive-overlay.test.d.ts +13 -0
- package/dist/test/comprehensive-overlay.test.js +593 -0
- package/dist/test/key-derivation.test.d.ts +12 -0
- package/dist/test/key-derivation.test.js +86 -0
- package/dist/test/overlay-submit.test.d.ts +10 -0
- package/dist/test/overlay-submit.test.js +460 -0
- package/dist/test/request-response-flow.test.d.ts +5 -0
- package/dist/test/request-response-flow.test.js +209 -0
- package/dist/test/service-system.test.d.ts +5 -0
- package/dist/test/service-system.test.js +190 -0
- package/dist/test/utils/server-logic.d.ts +98 -0
- package/dist/test/utils/server-logic.js +286 -0
- package/dist/test/wallet.test.d.ts +7 -0
- package/dist/test/wallet.test.js +146 -0
- package/index.ts +1965 -0
- package/openclaw.plugin.json +106 -0
- package/package.json +73 -0
- package/src/cli-main.ts +230 -0
- package/src/cli.ts +16 -0
- package/src/core/README.md +246 -0
- package/src/core/config.ts +21 -0
- package/src/core/index.ts +42 -0
- package/src/core/payment.ts +111 -0
- package/src/core/types.ts +102 -0
- package/src/core/verify.ts +119 -0
- package/src/core/wallet.ts +282 -0
- package/src/scripts/baemail/commands.ts +326 -0
- package/src/scripts/baemail/handler.ts +338 -0
- package/src/scripts/baemail/index.ts +6 -0
- package/src/scripts/config.ts +81 -0
- package/src/scripts/index.ts +8 -0
- package/src/scripts/messaging/connect.ts +121 -0
- package/src/scripts/messaging/handlers.ts +394 -0
- package/src/scripts/messaging/inbox.ts +64 -0
- package/src/scripts/messaging/index.ts +9 -0
- package/src/scripts/messaging/poll.ts +59 -0
- package/src/scripts/messaging/send.ts +54 -0
- package/src/scripts/output.ts +21 -0
- package/src/scripts/overlay/discover.ts +81 -0
- package/src/scripts/overlay/index.ts +8 -0
- package/src/scripts/overlay/registration.ts +199 -0
- package/src/scripts/overlay/services.ts +199 -0
- package/src/scripts/overlay/transaction.ts +124 -0
- package/src/scripts/payment/build.ts +65 -0
- package/src/scripts/payment/commands.ts +92 -0
- package/src/scripts/payment/index.ts +7 -0
- package/src/scripts/payment/types.ts +62 -0
- package/src/scripts/services/index.ts +7 -0
- package/src/scripts/services/queue.ts +35 -0
- package/src/scripts/services/request.ts +98 -0
- package/src/scripts/services/respond.ts +149 -0
- package/src/scripts/types.ts +121 -0
- package/src/scripts/utils/index.ts +7 -0
- package/src/scripts/utils/merkle.ts +57 -0
- package/src/scripts/utils/storage.ts +231 -0
- package/src/scripts/utils/woc.ts +106 -0
- package/src/scripts/wallet/balance.ts +277 -0
- package/src/scripts/wallet/identity.ts +203 -0
- package/src/scripts/wallet/index.ts +7 -0
- package/src/scripts/wallet/setup.ts +121 -0
- package/src/scripts/x-verification/commands.ts +256 -0
- package/src/scripts/x-verification/index.ts +5 -0
- package/src/services/built-in/api-proxy/index.ts +26 -0
- package/src/services/built-in/api-proxy/prompt.md +26 -0
- package/src/services/built-in/code-develop/index.ts +26 -0
- package/src/services/built-in/code-develop/prompt.md +35 -0
- package/src/services/built-in/code-review/index.ts +54 -0
- package/src/services/built-in/code-review/prompt.md +105 -0
- package/src/services/built-in/image-analysis/index.ts +36 -0
- package/src/services/built-in/image-analysis/prompt.md +42 -0
- package/src/services/built-in/memory-store/index.ts +25 -0
- package/src/services/built-in/memory-store/prompt.md +45 -0
- package/src/services/built-in/roulette/index.ts +30 -0
- package/src/services/built-in/roulette/prompt.md +35 -0
- package/src/services/built-in/summarize/index.ts +24 -0
- package/src/services/built-in/summarize/prompt.md +27 -0
- package/src/services/built-in/tell-joke/handler.ts +134 -0
- package/src/services/built-in/tell-joke/index.ts +34 -0
- package/src/services/built-in/tell-joke/prompt.md +59 -0
- package/src/services/built-in/translate/index.ts +24 -0
- package/src/services/built-in/translate/prompt.md +23 -0
- package/src/services/built-in/web-research/index.ts +54 -0
- package/src/services/built-in/web-research/prompt.md +110 -0
- package/src/services/index.ts +16 -0
- package/src/services/loader.ts +344 -0
- package/src/services/manager.ts +304 -0
- package/src/services/registry.ts +246 -0
- package/src/services/types.ts +259 -0
- package/src/test/cli.test.ts +352 -0
- package/src/test/comprehensive-overlay.test.ts +729 -0
- package/src/test/key-derivation.test.ts +102 -0
- package/src/test/overlay-submit.test.ts +570 -0
- package/src/test/request-response-flow.test.ts +252 -0
- package/src/test/service-system.test.ts +241 -0
- package/src/test/utils/server-logic.ts +368 -0
- package/src/test/wallet.test.ts +166 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI test suite — tests the compiled CLI as a subprocess.
|
|
3
|
+
*
|
|
4
|
+
* Uses child_process.execFile to invoke `node dist/cli.js <command>`
|
|
5
|
+
* and validates stdout JSON, stderr, and exit codes.
|
|
6
|
+
*/
|
|
7
|
+
import { execFile } from 'node:child_process';
|
|
8
|
+
import { promisify } from 'node:util';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import os from 'node:os';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
const execFileAsync = promisify(execFile);
|
|
14
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const CLI_PATH = path.resolve(__dirname, '..', '..', 'dist', 'cli.js');
|
|
16
|
+
// Simple test runner (matches project convention — no external framework)
|
|
17
|
+
let passed = 0;
|
|
18
|
+
let failed = 0;
|
|
19
|
+
function test(name, fn) {
|
|
20
|
+
return (async () => {
|
|
21
|
+
try {
|
|
22
|
+
await fn();
|
|
23
|
+
console.log(` ✓ ${name}`);
|
|
24
|
+
passed++;
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
28
|
+
console.log(` ✗ ${name}`);
|
|
29
|
+
console.log(` ${msg}`);
|
|
30
|
+
failed++;
|
|
31
|
+
}
|
|
32
|
+
})();
|
|
33
|
+
}
|
|
34
|
+
function assert(condition, message) {
|
|
35
|
+
if (!condition)
|
|
36
|
+
throw new Error(`Assertion failed: ${message}`);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Run a CLI command, returning parsed JSON output and exit code.
|
|
40
|
+
* For commands that fail (exit 1), we catch the error and parse stderr/stdout.
|
|
41
|
+
*/
|
|
42
|
+
async function runCli(args, env) {
|
|
43
|
+
const mergedEnv = { ...process.env, ...env };
|
|
44
|
+
try {
|
|
45
|
+
const { stdout, stderr } = await execFileAsync('node', [CLI_PATH, ...args], {
|
|
46
|
+
env: mergedEnv,
|
|
47
|
+
timeout: 30000,
|
|
48
|
+
});
|
|
49
|
+
let json = null;
|
|
50
|
+
try {
|
|
51
|
+
json = JSON.parse(stdout.trim());
|
|
52
|
+
}
|
|
53
|
+
catch { /* not JSON */ }
|
|
54
|
+
return { json, exitCode: 0, stdout: stdout.trim(), stderr: stderr.trim() };
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
const stdout = (err.stdout || '').trim();
|
|
58
|
+
const stderr = (err.stderr || '').trim();
|
|
59
|
+
let json = null;
|
|
60
|
+
try {
|
|
61
|
+
json = JSON.parse(stdout);
|
|
62
|
+
}
|
|
63
|
+
catch { /* not JSON */ }
|
|
64
|
+
return { json, exitCode: err.code ?? 1, stdout, stderr };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Create a temporary wallet directory for isolated tests.
|
|
69
|
+
*/
|
|
70
|
+
function makeTmpWalletDir() {
|
|
71
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), 'openclaw-test-'));
|
|
72
|
+
}
|
|
73
|
+
async function run() {
|
|
74
|
+
console.log('CLI tests\n');
|
|
75
|
+
// Verify CLI is compiled
|
|
76
|
+
if (!fs.existsSync(CLI_PATH)) {
|
|
77
|
+
console.error(`CLI not found at ${CLI_PATH}. Run "npm run build" first.`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
// ── Unknown / missing command ─────────────────────────────────────────
|
|
81
|
+
await test('unknown command exits 1 with JSON error', async () => {
|
|
82
|
+
const { json, exitCode } = await runCli(['nonexistent-command']);
|
|
83
|
+
assert(exitCode !== 0, 'should exit with non-zero code');
|
|
84
|
+
assert(json !== null, 'should output JSON');
|
|
85
|
+
assert(json.success === false, 'success should be false');
|
|
86
|
+
assert(typeof json.error === 'string', 'should have error message');
|
|
87
|
+
assert(json.error.includes('Unknown command'), 'error should mention unknown command');
|
|
88
|
+
});
|
|
89
|
+
await test('no command exits 1 with JSON error', async () => {
|
|
90
|
+
const { json, exitCode } = await runCli([]);
|
|
91
|
+
assert(exitCode !== 0, 'should exit with non-zero code');
|
|
92
|
+
assert(json !== null, 'should output JSON');
|
|
93
|
+
assert(json.success === false, 'success should be false');
|
|
94
|
+
});
|
|
95
|
+
// ── Help command ──────────────────────────────────────────────────────
|
|
96
|
+
await test('--help returns JSON with command list', async () => {
|
|
97
|
+
const { json, exitCode } = await runCli(['--help']);
|
|
98
|
+
assert(exitCode === 0, 'should exit 0');
|
|
99
|
+
assert(json !== null, 'should output JSON');
|
|
100
|
+
assert(json.success === true, 'success should be true');
|
|
101
|
+
assert(typeof json.data.commands === 'object', 'should have commands object');
|
|
102
|
+
assert(Array.isArray(json.data.commands.wallet), 'should have wallet commands');
|
|
103
|
+
assert(typeof json.data.usage === 'string', 'should have usage string');
|
|
104
|
+
});
|
|
105
|
+
await test('help returns same as --help', async () => {
|
|
106
|
+
const { json, exitCode } = await runCli(['help']);
|
|
107
|
+
assert(exitCode === 0, 'should exit 0');
|
|
108
|
+
assert(json.success === true, 'success should be true');
|
|
109
|
+
assert(typeof json.data.commands === 'object', 'should have commands');
|
|
110
|
+
});
|
|
111
|
+
// ── Argument validation ───────────────────────────────────────────────
|
|
112
|
+
await test('import without txid fails with usage message', async () => {
|
|
113
|
+
const tmpDir = makeTmpWalletDir();
|
|
114
|
+
try {
|
|
115
|
+
const { json, exitCode } = await runCli(['import'], { BSV_WALLET_DIR: tmpDir });
|
|
116
|
+
assert(exitCode !== 0, 'should exit non-zero');
|
|
117
|
+
assert(json.success === false, 'success should be false');
|
|
118
|
+
assert(json.error.toLowerCase().includes('usage'), 'should show usage');
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
await test('import with invalid txid fails', async () => {
|
|
125
|
+
const tmpDir = makeTmpWalletDir();
|
|
126
|
+
try {
|
|
127
|
+
const { json, exitCode } = await runCli(['import', 'not-a-txid'], { BSV_WALLET_DIR: tmpDir });
|
|
128
|
+
assert(exitCode !== 0, 'should exit non-zero');
|
|
129
|
+
assert(json.success === false, 'success should be false');
|
|
130
|
+
assert(json.error.includes('Invalid txid'), 'should mention invalid txid');
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
await test('refund without address fails with usage', async () => {
|
|
137
|
+
const tmpDir = makeTmpWalletDir();
|
|
138
|
+
try {
|
|
139
|
+
const { json, exitCode } = await runCli(['refund'], { BSV_WALLET_DIR: tmpDir });
|
|
140
|
+
assert(exitCode !== 0, 'should exit non-zero');
|
|
141
|
+
assert(json.success === false, 'success should be false');
|
|
142
|
+
assert(json.error.toLowerCase().includes('usage'), 'should show usage');
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
await test('pay without args fails with usage', async () => {
|
|
149
|
+
const tmpDir = makeTmpWalletDir();
|
|
150
|
+
try {
|
|
151
|
+
const { json, exitCode } = await runCli(['pay'], { BSV_WALLET_DIR: tmpDir });
|
|
152
|
+
assert(exitCode !== 0, 'should exit non-zero');
|
|
153
|
+
assert(json.success === false, 'success should be false');
|
|
154
|
+
assert(json.error.toLowerCase().includes('usage'), 'should show usage');
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
await test('advertise without args fails with usage', async () => {
|
|
161
|
+
const tmpDir = makeTmpWalletDir();
|
|
162
|
+
try {
|
|
163
|
+
const { json, exitCode } = await runCli(['advertise'], { BSV_WALLET_DIR: tmpDir });
|
|
164
|
+
assert(exitCode !== 0, 'should exit non-zero');
|
|
165
|
+
assert(json.success === false, 'success should be false');
|
|
166
|
+
assert(json.error.toLowerCase().includes('usage'), 'should show usage');
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
await test('send without args fails with usage', async () => {
|
|
173
|
+
const tmpDir = makeTmpWalletDir();
|
|
174
|
+
try {
|
|
175
|
+
const { json, exitCode } = await runCli(['send'], { BSV_WALLET_DIR: tmpDir });
|
|
176
|
+
assert(exitCode !== 0, 'should exit non-zero');
|
|
177
|
+
assert(json.success === false, 'success should be false');
|
|
178
|
+
assert(json.error.toLowerCase().includes('usage'), 'should show usage');
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
await test('verify without args fails with usage', async () => {
|
|
185
|
+
const tmpDir = makeTmpWalletDir();
|
|
186
|
+
try {
|
|
187
|
+
const { json, exitCode } = await runCli(['verify'], { BSV_WALLET_DIR: tmpDir });
|
|
188
|
+
assert(exitCode !== 0, 'should exit non-zero');
|
|
189
|
+
assert(json.success === false, 'success should be false');
|
|
190
|
+
assert(json.error.toLowerCase().includes('usage'), 'should show usage');
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
await test('remove without args fails with usage', async () => {
|
|
197
|
+
const tmpDir = makeTmpWalletDir();
|
|
198
|
+
try {
|
|
199
|
+
const { json, exitCode } = await runCli(['remove'], { BSV_WALLET_DIR: tmpDir });
|
|
200
|
+
assert(exitCode !== 0, 'should exit non-zero');
|
|
201
|
+
assert(json.success === false, 'success should be false');
|
|
202
|
+
assert(json.error.toLowerCase().includes('usage'), 'should show usage');
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
// ── Wallet-dependent tests (using temp directory) ─────────────────────
|
|
209
|
+
await test('setup creates wallet in temp dir', async () => {
|
|
210
|
+
const tmpDir = makeTmpWalletDir();
|
|
211
|
+
try {
|
|
212
|
+
const { json, exitCode } = await runCli(['setup'], {
|
|
213
|
+
BSV_WALLET_DIR: tmpDir,
|
|
214
|
+
BSV_NETWORK: 'mainnet',
|
|
215
|
+
});
|
|
216
|
+
assert(exitCode === 0, `should exit 0, got ${exitCode}: ${json?.error || ''}`);
|
|
217
|
+
assert(json.success === true, 'success should be true');
|
|
218
|
+
assert(typeof json.data.identityKey === 'string', 'should return identity key');
|
|
219
|
+
assert(json.data.identityKey.length === 66, 'identity key should be 66 hex chars');
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
await test('setup is idempotent', async () => {
|
|
226
|
+
const tmpDir = makeTmpWalletDir();
|
|
227
|
+
try {
|
|
228
|
+
// First setup
|
|
229
|
+
const first = await runCli(['setup'], { BSV_WALLET_DIR: tmpDir, BSV_NETWORK: 'mainnet' });
|
|
230
|
+
assert(first.exitCode === 0, 'first setup should succeed');
|
|
231
|
+
// Second setup — should return same identity
|
|
232
|
+
const second = await runCli(['setup'], { BSV_WALLET_DIR: tmpDir, BSV_NETWORK: 'mainnet' });
|
|
233
|
+
assert(second.exitCode === 0, 'second setup should succeed');
|
|
234
|
+
assert(first.json.data.identityKey === second.json.data.identityKey, 'identity key should be the same across setups');
|
|
235
|
+
}
|
|
236
|
+
finally {
|
|
237
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
await test('identity returns expected shape after setup', async () => {
|
|
241
|
+
const tmpDir = makeTmpWalletDir();
|
|
242
|
+
try {
|
|
243
|
+
await runCli(['setup'], { BSV_WALLET_DIR: tmpDir, BSV_NETWORK: 'mainnet' });
|
|
244
|
+
const { json, exitCode } = await runCli(['identity'], {
|
|
245
|
+
BSV_WALLET_DIR: tmpDir,
|
|
246
|
+
BSV_NETWORK: 'mainnet',
|
|
247
|
+
});
|
|
248
|
+
assert(exitCode === 0, 'should exit 0');
|
|
249
|
+
assert(json.success === true, 'success should be true');
|
|
250
|
+
assert(typeof json.data.identityKey === 'string', 'should have identityKey');
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
await test('address returns expected shape after setup', async () => {
|
|
257
|
+
const tmpDir = makeTmpWalletDir();
|
|
258
|
+
try {
|
|
259
|
+
await runCli(['setup'], { BSV_WALLET_DIR: tmpDir, BSV_NETWORK: 'mainnet' });
|
|
260
|
+
const { json, exitCode } = await runCli(['address'], {
|
|
261
|
+
BSV_WALLET_DIR: tmpDir,
|
|
262
|
+
BSV_NETWORK: 'mainnet',
|
|
263
|
+
});
|
|
264
|
+
assert(exitCode === 0, 'should exit 0');
|
|
265
|
+
assert(json.success === true, 'success should be true');
|
|
266
|
+
assert(typeof json.data.address === 'string', 'should have address');
|
|
267
|
+
assert(json.data.address.length > 20, 'address should be reasonable length');
|
|
268
|
+
}
|
|
269
|
+
finally {
|
|
270
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
await test('balance returns expected shape after setup', async () => {
|
|
274
|
+
const tmpDir = makeTmpWalletDir();
|
|
275
|
+
try {
|
|
276
|
+
await runCli(['setup'], { BSV_WALLET_DIR: tmpDir, BSV_NETWORK: 'mainnet' });
|
|
277
|
+
const { json, exitCode } = await runCli(['balance'], {
|
|
278
|
+
BSV_WALLET_DIR: tmpDir,
|
|
279
|
+
BSV_NETWORK: 'mainnet',
|
|
280
|
+
});
|
|
281
|
+
assert(exitCode === 0, 'should exit 0');
|
|
282
|
+
assert(json.success === true, 'success should be true');
|
|
283
|
+
assert(typeof json.data.walletBalance === 'number', 'should have walletBalance');
|
|
284
|
+
assert(json.data.walletBalance === 0, 'fresh wallet should have 0 balance');
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
287
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
await test('services returns expected shape', async () => {
|
|
291
|
+
const tmpDir = makeTmpWalletDir();
|
|
292
|
+
try {
|
|
293
|
+
await runCli(['setup'], { BSV_WALLET_DIR: tmpDir, BSV_NETWORK: 'mainnet' });
|
|
294
|
+
const { json, exitCode } = await runCli(['services'], {
|
|
295
|
+
BSV_WALLET_DIR: tmpDir,
|
|
296
|
+
BSV_NETWORK: 'mainnet',
|
|
297
|
+
});
|
|
298
|
+
assert(exitCode === 0, 'should exit 0');
|
|
299
|
+
assert(json.success === true, 'success should be true');
|
|
300
|
+
assert(Array.isArray(json.data.services), 'should have services array');
|
|
301
|
+
assert(typeof json.data.count === 'number', 'should have count');
|
|
302
|
+
}
|
|
303
|
+
finally {
|
|
304
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
// ── Output format consistency ─────────────────────────────────────────
|
|
308
|
+
await test('all error outputs have { success: false, error: string }', async () => {
|
|
309
|
+
// Test a few known-bad commands
|
|
310
|
+
const badCommands = [
|
|
311
|
+
['nonexistent'],
|
|
312
|
+
['import'],
|
|
313
|
+
['pay'],
|
|
314
|
+
['send'],
|
|
315
|
+
['verify'],
|
|
316
|
+
];
|
|
317
|
+
for (const args of badCommands) {
|
|
318
|
+
const { json } = await runCli(args);
|
|
319
|
+
assert(json !== null, `${args.join(' ')} should produce JSON`);
|
|
320
|
+
assert(json.success === false, `${args.join(' ')} should have success=false`);
|
|
321
|
+
assert(typeof json.error === 'string', `${args.join(' ')} should have error string`);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
// ── Summary ───────────────────────────────────────────────────────────
|
|
325
|
+
console.log(`\nCLI tests: ${passed} passed, ${failed} failed\n`);
|
|
326
|
+
if (failed > 0)
|
|
327
|
+
process.exit(1);
|
|
328
|
+
}
|
|
329
|
+
run();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comprehensive Overlay Submission Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests all aspects of overlay submission:
|
|
5
|
+
* - BEEF format and construction
|
|
6
|
+
* - Payload validation (identity, service, revocation)
|
|
7
|
+
* - PushDrop script format
|
|
8
|
+
* - Transaction chain validation
|
|
9
|
+
* - Server response handling
|
|
10
|
+
*
|
|
11
|
+
* Run with: npx tsx src/test/comprehensive-overlay.test.ts
|
|
12
|
+
*/
|
|
13
|
+
export {};
|