|
1 | | -import {describe, it, expect} from "vitest"; |
2 | | -import {execSync} from "child_process"; |
| 1 | +import { describe, it, expect } from 'vitest' |
| 2 | +import { execSync } from 'child_process' |
3 | 3 |
|
4 | 4 | // Helper to run CLI commands |
5 | | -function runCli(args: string): {stdout: string; exitCode: number} { |
| 5 | +function runCli(args: string): { stdout: string; exitCode: number } { |
6 | 6 | try { |
7 | 7 | const stdout = execSync(`pnpm dev ${args}`, { |
8 | 8 | cwd: process.cwd(), |
9 | | - encoding: "utf-8", |
| 9 | + encoding: 'utf-8', |
10 | 10 | timeout: 30000, |
11 | | - stdio: ["pipe", "pipe", "pipe"] |
12 | | - }); |
13 | | - return {stdout, exitCode: 0}; |
| 11 | + stdio: ['pipe', 'pipe', 'pipe'], |
| 12 | + }) |
| 13 | + return { stdout, exitCode: 0 } |
14 | 14 | } catch (error: any) { |
15 | 15 | return { |
16 | 16 | stdout: error.stdout || error.stderr || error.message, |
17 | | - exitCode: error.status || 1 |
18 | | - }; |
| 17 | + exitCode: error.status || 1, |
| 18 | + } |
19 | 19 | } |
20 | 20 | } |
21 | 21 |
|
22 | | -describe("CLI commands", () => { |
23 | | - describe("--help", () => { |
24 | | - it("should display main help", () => { |
25 | | - const result = runCli("--help"); |
26 | | - expect(result.stdout).toContain("CLI for Sequence Builder"); |
27 | | - expect(result.stdout).toContain("create-wallet"); |
28 | | - expect(result.stdout).toContain("login"); |
29 | | - expect(result.stdout).toContain("projects"); |
30 | | - expect(result.stdout).toContain("apikeys"); |
31 | | - expect(result.stdout).toContain("transfer"); |
32 | | - expect(result.stdout).toContain("indexer"); |
33 | | - expect(result.stdout).toContain("wallet-info"); |
34 | | - }); |
35 | | - }); |
36 | | - |
37 | | - describe("create-wallet", () => { |
38 | | - it("should generate a new wallet", () => { |
39 | | - const result = runCli("create-wallet"); |
40 | | - expect(result.stdout).toContain("Wallet created successfully"); |
41 | | - expect(result.stdout).toContain("Private Key:"); |
42 | | - expect(result.stdout).toContain("Address:"); |
43 | | - }); |
44 | | - |
45 | | - it("should output JSON format with --json flag", () => { |
46 | | - const result = runCli("create-wallet --json"); |
47 | | - const output = result.stdout.trim().split("\n").slice(-4).join("\n"); // Get JSON part |
48 | | - expect(() => JSON.parse(output)).not.toThrow(); |
49 | | - const json = JSON.parse(output); |
50 | | - expect(json).toHaveProperty("privateKey"); |
51 | | - expect(json).toHaveProperty("address"); |
52 | | - expect(json.privateKey).toMatch(/^0x[a-fA-F0-9]{64}$/); |
53 | | - expect(json.address).toMatch(/^0x[a-fA-F0-9]{40}$/); |
54 | | - }); |
55 | | - }); |
56 | | - |
57 | | - describe("wallet-info", () => { |
58 | | - it("should show help without private key", () => { |
59 | | - const result = runCli("wallet-info --help"); |
60 | | - expect(result.stdout).toContain("private-key"); |
61 | | - expect(result.stdout).toContain("access-key"); |
62 | | - }); |
63 | | - |
64 | | - it("should require private key", () => { |
65 | | - const result = runCli("wallet-info"); |
66 | | - expect(result.exitCode).not.toBe(0); |
67 | | - }); |
68 | | - }); |
69 | | - |
70 | | - describe("login", () => { |
71 | | - it("should show help", () => { |
72 | | - const result = runCli("login --help"); |
73 | | - expect(result.stdout).toContain("private-key"); |
74 | | - expect(result.stdout).toContain("Authenticate"); |
75 | | - }); |
76 | | - |
77 | | - it("should fail without required private key", () => { |
78 | | - const result = runCli("login"); |
79 | | - expect(result.exitCode).not.toBe(0); |
80 | | - }); |
81 | | - }); |
82 | | - |
83 | | - describe("projects", () => { |
84 | | - it("should show subcommands in help", () => { |
85 | | - const result = runCli("projects --help"); |
86 | | - expect(result.stdout).toContain("list"); |
87 | | - expect(result.stdout).toContain("get"); |
88 | | - expect(result.stdout).toContain("create"); |
89 | | - }); |
90 | | - }); |
91 | | - |
92 | | - describe("apikeys", () => { |
93 | | - it("should show subcommands in help", () => { |
94 | | - const result = runCli("apikeys --help"); |
95 | | - expect(result.stdout).toContain("list"); |
96 | | - expect(result.stdout).toContain("default"); |
97 | | - }); |
98 | | - }); |
99 | | - |
100 | | - describe("transfer", () => { |
101 | | - it("should show help", () => { |
102 | | - const result = runCli("transfer --help"); |
103 | | - expect(result.stdout).toContain("private-key"); |
104 | | - expect(result.stdout).toContain("access-key"); |
105 | | - expect(result.stdout).toContain("recipient"); |
106 | | - expect(result.stdout).toContain("amount"); |
107 | | - expect(result.stdout).toContain("token"); |
108 | | - expect(result.stdout).toContain("chain-id"); |
109 | | - }); |
110 | | - }); |
111 | | - |
112 | | - describe("indexer", () => { |
113 | | - it("should show subcommands in help", () => { |
114 | | - const result = runCli("indexer --help"); |
115 | | - expect(result.stdout).toContain("balances"); |
116 | | - expect(result.stdout).toContain("native-balance"); |
117 | | - expect(result.stdout).toContain("history"); |
118 | | - expect(result.stdout).toContain("token-info"); |
119 | | - }); |
120 | | - |
121 | | - it("should show balances help", () => { |
122 | | - const result = runCli("indexer balances --help"); |
123 | | - expect(result.stdout).toContain("access-key"); |
124 | | - expect(result.stdout).toContain("chain-id"); |
125 | | - expect(result.stdout).toContain("address"); |
126 | | - }); |
127 | | - |
128 | | - it("should show native-balance help", () => { |
129 | | - const result = runCli("indexer native-balance --help"); |
130 | | - expect(result.stdout).toContain("access-key"); |
131 | | - expect(result.stdout).toContain("chain-id"); |
132 | | - expect(result.stdout).toContain("address"); |
133 | | - }); |
134 | | - |
135 | | - it("should show history help", () => { |
136 | | - const result = runCli("indexer history --help"); |
137 | | - expect(result.stdout).toContain("access-key"); |
138 | | - expect(result.stdout).toContain("chain-id"); |
139 | | - expect(result.stdout).toContain("address"); |
140 | | - }); |
141 | | - |
142 | | - it("should show token-info help", () => { |
143 | | - const result = runCli("indexer token-info --help"); |
144 | | - expect(result.stdout).toContain("access-key"); |
145 | | - expect(result.stdout).toContain("chain-id"); |
146 | | - }); |
147 | | - }); |
148 | | -}); |
| 22 | +describe('CLI commands', () => { |
| 23 | + describe('--help', () => { |
| 24 | + it('should display main help', () => { |
| 25 | + const result = runCli('--help') |
| 26 | + expect(result.stdout).toContain('CLI for Sequence Builder') |
| 27 | + expect(result.stdout).toContain('create-wallet') |
| 28 | + expect(result.stdout).toContain('login') |
| 29 | + expect(result.stdout).toContain('projects') |
| 30 | + expect(result.stdout).toContain('apikeys') |
| 31 | + expect(result.stdout).toContain('transfer') |
| 32 | + expect(result.stdout).toContain('indexer') |
| 33 | + expect(result.stdout).toContain('wallet-info') |
| 34 | + }) |
| 35 | + }) |
| 36 | + |
| 37 | + describe('create-wallet', () => { |
| 38 | + it('should generate a new wallet', () => { |
| 39 | + const result = runCli('create-wallet') |
| 40 | + expect(result.stdout).toContain('Wallet created successfully') |
| 41 | + expect(result.stdout).toContain('Private Key:') |
| 42 | + expect(result.stdout).toContain('Address:') |
| 43 | + }) |
| 44 | + |
| 45 | + it('should output JSON format with --json flag', () => { |
| 46 | + const result = runCli('create-wallet --json') |
| 47 | + const output = result.stdout.trim().split('\n').slice(-4).join('\n') // Get JSON part |
| 48 | + expect(() => JSON.parse(output)).not.toThrow() |
| 49 | + const json = JSON.parse(output) |
| 50 | + expect(json).toHaveProperty('privateKey') |
| 51 | + expect(json).toHaveProperty('address') |
| 52 | + expect(json.privateKey).toMatch(/^0x[a-fA-F0-9]{64}$/) |
| 53 | + expect(json.address).toMatch(/^0x[a-fA-F0-9]{40}$/) |
| 54 | + }) |
| 55 | + }) |
| 56 | + |
| 57 | + describe('wallet-info', () => { |
| 58 | + it('should show help without private key', () => { |
| 59 | + const result = runCli('wallet-info --help') |
| 60 | + expect(result.stdout).toContain('private-key') |
| 61 | + expect(result.stdout).toContain('access-key') |
| 62 | + }) |
| 63 | + |
| 64 | + it('should require private key', () => { |
| 65 | + const result = runCli('wallet-info') |
| 66 | + expect(result.exitCode).not.toBe(0) |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
| 70 | + describe('login', () => { |
| 71 | + it('should show help', () => { |
| 72 | + const result = runCli('login --help') |
| 73 | + expect(result.stdout).toContain('private-key') |
| 74 | + expect(result.stdout).toContain('Authenticate') |
| 75 | + }) |
| 76 | + |
| 77 | + it('should fail without required private key', () => { |
| 78 | + const result = runCli('login') |
| 79 | + expect(result.exitCode).not.toBe(0) |
| 80 | + }) |
| 81 | + }) |
| 82 | + |
| 83 | + describe('projects', () => { |
| 84 | + it('should show subcommands in help', () => { |
| 85 | + const result = runCli('projects --help') |
| 86 | + expect(result.stdout).toContain('list') |
| 87 | + expect(result.stdout).toContain('get') |
| 88 | + expect(result.stdout).toContain('create') |
| 89 | + }) |
| 90 | + }) |
| 91 | + |
| 92 | + describe('apikeys', () => { |
| 93 | + it('should show subcommands in help', () => { |
| 94 | + const result = runCli('apikeys --help') |
| 95 | + expect(result.stdout).toContain('list') |
| 96 | + expect(result.stdout).toContain('default') |
| 97 | + }) |
| 98 | + }) |
| 99 | + |
| 100 | + describe('transfer', () => { |
| 101 | + it('should show help', () => { |
| 102 | + const result = runCli('transfer --help') |
| 103 | + expect(result.stdout).toContain('private-key') |
| 104 | + expect(result.stdout).toContain('access-key') |
| 105 | + expect(result.stdout).toContain('recipient') |
| 106 | + expect(result.stdout).toContain('amount') |
| 107 | + expect(result.stdout).toContain('token') |
| 108 | + expect(result.stdout).toContain('chain-id') |
| 109 | + }) |
| 110 | + }) |
| 111 | + |
| 112 | + describe('indexer', () => { |
| 113 | + it('should show subcommands in help', () => { |
| 114 | + const result = runCli('indexer --help') |
| 115 | + expect(result.stdout).toContain('balances') |
| 116 | + expect(result.stdout).toContain('native-balance') |
| 117 | + expect(result.stdout).toContain('history') |
| 118 | + expect(result.stdout).toContain('token-info') |
| 119 | + }) |
| 120 | + |
| 121 | + it('should show balances help', () => { |
| 122 | + const result = runCli('indexer balances --help') |
| 123 | + expect(result.stdout).toContain('access-key') |
| 124 | + expect(result.stdout).toContain('chain-id') |
| 125 | + expect(result.stdout).toContain('address') |
| 126 | + }) |
| 127 | + |
| 128 | + it('should show native-balance help', () => { |
| 129 | + const result = runCli('indexer native-balance --help') |
| 130 | + expect(result.stdout).toContain('access-key') |
| 131 | + expect(result.stdout).toContain('chain-id') |
| 132 | + expect(result.stdout).toContain('address') |
| 133 | + }) |
| 134 | + |
| 135 | + it('should show history help', () => { |
| 136 | + const result = runCli('indexer history --help') |
| 137 | + expect(result.stdout).toContain('access-key') |
| 138 | + expect(result.stdout).toContain('chain-id') |
| 139 | + expect(result.stdout).toContain('address') |
| 140 | + }) |
| 141 | + |
| 142 | + it('should show token-info help', () => { |
| 143 | + const result = runCli('indexer token-info --help') |
| 144 | + expect(result.stdout).toContain('access-key') |
| 145 | + expect(result.stdout).toContain('chain-id') |
| 146 | + }) |
| 147 | + }) |
| 148 | +}) |
0 commit comments