@manifest-network/manifest-mcp-browser 0.1.6 → 0.1.8
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 +5 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -10
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -7
- package/dist/index.js.map +1 -1
- package/dist/modules.d.ts.map +1 -1
- package/dist/modules.js +42 -0
- package/dist/modules.js.map +1 -1
- package/dist/queries/group.d.ts +12 -0
- package/dist/queries/group.d.ts.map +1 -0
- package/dist/queries/group.js +107 -0
- package/dist/queries/group.js.map +1 -0
- package/dist/queries/index.d.ts +2 -0
- package/dist/queries/index.d.ts.map +1 -1
- package/dist/queries/index.js +2 -0
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/utils.d.ts +3 -18
- package/dist/queries/utils.d.ts.map +1 -1
- package/dist/queries/utils.js +2 -17
- package/dist/queries/utils.js.map +1 -1
- package/dist/transactions/bank.d.ts.map +1 -1
- package/dist/transactions/bank.js +7 -5
- package/dist/transactions/bank.js.map +1 -1
- package/dist/transactions/gov.d.ts.map +1 -1
- package/dist/transactions/gov.js +9 -30
- package/dist/transactions/gov.js.map +1 -1
- package/dist/transactions/group.d.ts +7 -0
- package/dist/transactions/group.d.ts.map +1 -0
- package/dist/transactions/group.js +339 -0
- package/dist/transactions/group.js.map +1 -0
- package/dist/transactions/index.d.ts +2 -0
- package/dist/transactions/index.d.ts.map +1 -1
- package/dist/transactions/index.js +2 -0
- package/dist/transactions/index.js.map +1 -1
- package/dist/transactions/utils.d.ts +37 -0
- package/dist/transactions/utils.d.ts.map +1 -1
- package/dist/transactions/utils.js +43 -0
- package/dist/transactions/utils.js.map +1 -1
- package/dist/types.d.ts +31 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +5 -2
- package/.github/workflows/ci.yml +0 -37
- package/.github/workflows/publish.yml +0 -53
- package/CLAUDE.md +0 -111
- package/dist/config.test.d.ts +0 -2
- package/dist/config.test.d.ts.map +0 -1
- package/dist/config.test.js +0 -251
- package/dist/config.test.js.map +0 -1
- package/dist/modules.test.d.ts +0 -2
- package/dist/modules.test.d.ts.map +0 -1
- package/dist/modules.test.js +0 -159
- package/dist/modules.test.js.map +0 -1
- package/dist/queries/utils.test.d.ts +0 -2
- package/dist/queries/utils.test.d.ts.map +0 -1
- package/dist/queries/utils.test.js +0 -117
- package/dist/queries/utils.test.js.map +0 -1
- package/dist/transactions/utils.test.d.ts +0 -2
- package/dist/transactions/utils.test.d.ts.map +0 -1
- package/dist/transactions/utils.test.js +0 -471
- package/dist/transactions/utils.test.js.map +0 -1
- package/src/client.ts +0 -288
- package/src/config.test.ts +0 -299
- package/src/config.ts +0 -174
- package/src/cosmos.ts +0 -106
- package/src/index.ts +0 -478
- package/src/modules.test.ts +0 -189
- package/src/modules.ts +0 -428
- package/src/queries/auth.ts +0 -97
- package/src/queries/bank.ts +0 -99
- package/src/queries/billing.ts +0 -124
- package/src/queries/distribution.ts +0 -114
- package/src/queries/gov.ts +0 -104
- package/src/queries/index.ts +0 -16
- package/src/queries/sku.ts +0 -85
- package/src/queries/staking.ts +0 -154
- package/src/queries/utils.test.ts +0 -156
- package/src/queries/utils.ts +0 -145
- package/src/transactions/bank.ts +0 -86
- package/src/transactions/billing.ts +0 -286
- package/src/transactions/distribution.ts +0 -76
- package/src/transactions/gov.ts +0 -191
- package/src/transactions/index.ts +0 -7
- package/src/transactions/manifest.ts +0 -67
- package/src/transactions/sku.ts +0 -232
- package/src/transactions/staking.ts +0 -85
- package/src/transactions/utils.test.ts +0 -518
- package/src/transactions/utils.ts +0 -348
- package/src/types.ts +0 -497
- package/src/wallet/index.ts +0 -2
- package/src/wallet/mnemonic.ts +0 -146
- package/tsconfig.json +0 -23
|
@@ -1,518 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { toBech32 } from '@cosmjs/encoding';
|
|
3
|
-
import { parseAmount, parseBigInt, extractFlag, filterConsumedArgs, parseColonPair, validateAddress, validateMemo, validateArgsLength, requireArgs, parseHexBytes, bytesToHex } from './utils.js';
|
|
4
|
-
import { ManifestMCPError, ManifestMCPErrorCode } from '../types.js';
|
|
5
|
-
|
|
6
|
-
describe('parseAmount', () => {
|
|
7
|
-
it('should parse valid amount strings', () => {
|
|
8
|
-
expect(parseAmount('1000umfx')).toEqual({ amount: '1000', denom: 'umfx' });
|
|
9
|
-
expect(parseAmount('1uatom')).toEqual({ amount: '1', denom: 'uatom' });
|
|
10
|
-
expect(parseAmount('999999999token')).toEqual({ amount: '999999999', denom: 'token' });
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should handle denominations with numbers', () => {
|
|
14
|
-
expect(parseAmount('100ibc123')).toEqual({ amount: '100', denom: 'ibc123' });
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should handle factory denoms with slashes', () => {
|
|
18
|
-
expect(parseAmount('1000000factory/manifest1abc123/upwr')).toEqual({
|
|
19
|
-
amount: '1000000',
|
|
20
|
-
denom: 'factory/manifest1abc123/upwr',
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should handle IBC denoms with slashes', () => {
|
|
25
|
-
expect(parseAmount('500ibc/ABC123DEF456')).toEqual({
|
|
26
|
-
amount: '500',
|
|
27
|
-
denom: 'ibc/ABC123DEF456',
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should handle denoms with underscores', () => {
|
|
32
|
-
expect(parseAmount('100my_token')).toEqual({ amount: '100', denom: 'my_token' });
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should throw ManifestMCPError for invalid format', () => {
|
|
36
|
-
expect(() => parseAmount('')).toThrow(ManifestMCPError);
|
|
37
|
-
expect(() => parseAmount('umfx')).toThrow(ManifestMCPError);
|
|
38
|
-
expect(() => parseAmount('1000')).toThrow(ManifestMCPError);
|
|
39
|
-
expect(() => parseAmount('abc123')).toThrow(ManifestMCPError);
|
|
40
|
-
expect(() => parseAmount('1000 umfx')).toThrow(ManifestMCPError);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should have correct error code for invalid format', () => {
|
|
44
|
-
try {
|
|
45
|
-
parseAmount('invalid');
|
|
46
|
-
} catch (error) {
|
|
47
|
-
expect(error).toBeInstanceOf(ManifestMCPError);
|
|
48
|
-
expect((error as ManifestMCPError).code).toBe(ManifestMCPErrorCode.TX_FAILED);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should provide helpful hint for empty string', () => {
|
|
53
|
-
try {
|
|
54
|
-
parseAmount('');
|
|
55
|
-
} catch (error) {
|
|
56
|
-
expect((error as ManifestMCPError).message).toContain('Received empty string');
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should provide helpful hint for amount with space', () => {
|
|
61
|
-
try {
|
|
62
|
-
parseAmount('1000 umfx');
|
|
63
|
-
} catch (error) {
|
|
64
|
-
expect((error as ManifestMCPError).message).toContain('Remove the space');
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should provide helpful hint for amount with comma', () => {
|
|
69
|
-
try {
|
|
70
|
-
parseAmount('1,000umfx');
|
|
71
|
-
} catch (error) {
|
|
72
|
-
expect((error as ManifestMCPError).message).toContain('Do not use commas');
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should provide helpful hint for missing denomination', () => {
|
|
77
|
-
try {
|
|
78
|
-
parseAmount('1000');
|
|
79
|
-
} catch (error) {
|
|
80
|
-
expect((error as ManifestMCPError).message).toContain('Missing denomination');
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should provide helpful hint for denom-first format', () => {
|
|
85
|
-
try {
|
|
86
|
-
parseAmount('umfx1000');
|
|
87
|
-
} catch (error) {
|
|
88
|
-
expect((error as ManifestMCPError).message).toContain('must start with a number');
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should include details with received value and example', () => {
|
|
93
|
-
try {
|
|
94
|
-
parseAmount('bad');
|
|
95
|
-
} catch (error) {
|
|
96
|
-
const details = (error as ManifestMCPError).details;
|
|
97
|
-
expect(details?.receivedValue).toBe('bad');
|
|
98
|
-
expect(details?.example).toBe('1000000umfx');
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe('parseBigInt', () => {
|
|
104
|
-
it('should parse valid integer strings', () => {
|
|
105
|
-
expect(parseBigInt('0', 'test')).toBe(BigInt(0));
|
|
106
|
-
expect(parseBigInt('123', 'test')).toBe(BigInt(123));
|
|
107
|
-
expect(parseBigInt('9999999999999999999', 'test')).toBe(BigInt('9999999999999999999'));
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should throw ManifestMCPError for invalid integers', () => {
|
|
111
|
-
expect(() => parseBigInt('abc', 'field')).toThrow(ManifestMCPError);
|
|
112
|
-
expect(() => parseBigInt('12.34', 'field')).toThrow(ManifestMCPError);
|
|
113
|
-
expect(() => parseBigInt('1e10', 'field')).toThrow(ManifestMCPError);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should throw ManifestMCPError for empty string', () => {
|
|
117
|
-
// Empty string should be rejected for security (prevents accidental 0 values)
|
|
118
|
-
expect(() => parseBigInt('', 'field')).toThrow(ManifestMCPError);
|
|
119
|
-
expect(() => parseBigInt(' ', 'field')).toThrow(ManifestMCPError);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should include field name in error message', () => {
|
|
123
|
-
try {
|
|
124
|
-
parseBigInt('invalid', 'proposal-id');
|
|
125
|
-
} catch (error) {
|
|
126
|
-
expect(error).toBeInstanceOf(ManifestMCPError);
|
|
127
|
-
expect((error as ManifestMCPError).message).toContain('proposal-id');
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('extractFlag', () => {
|
|
133
|
-
it('should extract flag value when present', () => {
|
|
134
|
-
const result = extractFlag(['--memo', 'hello'], '--memo', 'test');
|
|
135
|
-
expect(result.value).toBe('hello');
|
|
136
|
-
expect(result.consumedIndices).toEqual([0, 1]);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('should return undefined when flag not present', () => {
|
|
140
|
-
const result = extractFlag(['arg1', 'arg2'], '--memo', 'test');
|
|
141
|
-
expect(result.value).toBeUndefined();
|
|
142
|
-
expect(result.consumedIndices).toEqual([]);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('should handle flag in middle of args', () => {
|
|
146
|
-
const result = extractFlag(['arg1', '--memo', 'hello', 'arg2'], '--memo', 'test');
|
|
147
|
-
expect(result.value).toBe('hello');
|
|
148
|
-
expect(result.consumedIndices).toEqual([1, 2]);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('should throw when flag has no value', () => {
|
|
152
|
-
expect(() => extractFlag(['--memo'], '--memo', 'test')).toThrow(ManifestMCPError);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('should throw when flag value looks like another flag', () => {
|
|
156
|
-
expect(() => extractFlag(['--memo', '--other'], '--memo', 'test')).toThrow(ManifestMCPError);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('should include context in error message', () => {
|
|
160
|
-
try {
|
|
161
|
-
extractFlag(['--memo'], '--memo', 'bank send');
|
|
162
|
-
} catch (error) {
|
|
163
|
-
expect((error as ManifestMCPError).message).toContain('bank send');
|
|
164
|
-
expect((error as ManifestMCPError).message).toContain('--memo');
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('filterConsumedArgs', () => {
|
|
170
|
-
it('should filter out consumed indices', () => {
|
|
171
|
-
const result = filterConsumedArgs(['a', 'b', 'c', 'd'], [1, 2]);
|
|
172
|
-
expect(result).toEqual(['a', 'd']);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it('should return original array when no indices consumed', () => {
|
|
176
|
-
const result = filterConsumedArgs(['a', 'b', 'c'], []);
|
|
177
|
-
expect(result).toEqual(['a', 'b', 'c']);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('should handle all indices consumed', () => {
|
|
181
|
-
const result = filterConsumedArgs(['a', 'b'], [0, 1]);
|
|
182
|
-
expect(result).toEqual([]);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('should handle non-contiguous indices', () => {
|
|
186
|
-
const result = filterConsumedArgs(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]);
|
|
187
|
-
expect(result).toEqual(['b', 'd']);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
describe('parseColonPair', () => {
|
|
192
|
-
it('should parse valid colon-separated pairs', () => {
|
|
193
|
-
expect(parseColonPair('address:amount', 'address', 'amount', 'test')).toEqual(['address', 'amount']);
|
|
194
|
-
expect(parseColonPair('key:value', 'key', 'value', 'test')).toEqual(['key', 'value']);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('should handle values with colons (takes first colon as separator)', () => {
|
|
198
|
-
const result = parseColonPair('address:100:extra', 'address', 'amount', 'test');
|
|
199
|
-
expect(result).toEqual(['address', '100:extra']);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('should throw for missing colon', () => {
|
|
203
|
-
expect(() => parseColonPair('nodelimiter', 'left', 'right', 'test')).toThrow(ManifestMCPError);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('should throw for empty left side', () => {
|
|
207
|
-
expect(() => parseColonPair(':value', 'left', 'right', 'test')).toThrow(ManifestMCPError);
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('should throw for empty right side', () => {
|
|
211
|
-
expect(() => parseColonPair('key:', 'left', 'right', 'test')).toThrow(ManifestMCPError);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('should include context and field names in error messages', () => {
|
|
215
|
-
try {
|
|
216
|
-
parseColonPair('invalid', 'address', 'amount', 'multi-send');
|
|
217
|
-
} catch (error) {
|
|
218
|
-
const message = (error as ManifestMCPError).message;
|
|
219
|
-
expect(message).toContain('multi-send');
|
|
220
|
-
expect(message).toContain('address');
|
|
221
|
-
expect(message).toContain('amount');
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it('should provide specific error for missing left value', () => {
|
|
226
|
-
try {
|
|
227
|
-
parseColonPair(':value', 'address', 'amount', 'test');
|
|
228
|
-
} catch (error) {
|
|
229
|
-
expect((error as ManifestMCPError).message).toContain('Missing address');
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('should provide specific error for missing right value', () => {
|
|
234
|
-
try {
|
|
235
|
-
parseColonPair('key:', 'address', 'amount', 'test');
|
|
236
|
-
} catch (error) {
|
|
237
|
-
expect((error as ManifestMCPError).message).toContain('Missing amount');
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
describe('validateAddress', () => {
|
|
243
|
-
// Generate valid bech32 addresses programmatically using @cosmjs/encoding
|
|
244
|
-
// 20 bytes is the standard Cosmos address length
|
|
245
|
-
const validManifestAddress = toBech32('manifest', new Uint8Array(20));
|
|
246
|
-
const validCosmosAddress = toBech32('cosmos', new Uint8Array(20));
|
|
247
|
-
|
|
248
|
-
it('should accept valid bech32 addresses', () => {
|
|
249
|
-
expect(() => validateAddress(validManifestAddress, 'test')).not.toThrow();
|
|
250
|
-
expect(() => validateAddress(validCosmosAddress, 'test')).not.toThrow();
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it('should throw for empty address', () => {
|
|
254
|
-
expect(() => validateAddress('', 'recipient')).toThrow(ManifestMCPError);
|
|
255
|
-
expect(() => validateAddress(' ', 'recipient')).toThrow(ManifestMCPError);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it('should throw for invalid bech32 address', () => {
|
|
259
|
-
expect(() => validateAddress('notanaddress', 'recipient')).toThrow(ManifestMCPError);
|
|
260
|
-
expect(() => validateAddress('manifest1invalid', 'recipient')).toThrow(ManifestMCPError);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it('should use INVALID_ADDRESS error code', () => {
|
|
264
|
-
try {
|
|
265
|
-
validateAddress('invalid', 'recipient');
|
|
266
|
-
} catch (error) {
|
|
267
|
-
expect((error as ManifestMCPError).code).toBe(ManifestMCPErrorCode.INVALID_ADDRESS);
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it('should include field name in error message', () => {
|
|
272
|
-
try {
|
|
273
|
-
validateAddress('invalid', 'validator address');
|
|
274
|
-
} catch (error) {
|
|
275
|
-
expect((error as ManifestMCPError).message).toContain('validator address');
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it('should validate expected prefix when provided', () => {
|
|
280
|
-
// Should pass when prefix matches
|
|
281
|
-
expect(() => validateAddress(validManifestAddress, 'test', 'manifest')).not.toThrow();
|
|
282
|
-
|
|
283
|
-
// Should fail when prefix doesn't match
|
|
284
|
-
expect(() => validateAddress(validManifestAddress, 'test', 'cosmos')).toThrow(ManifestMCPError);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('should include expected prefix in error message', () => {
|
|
288
|
-
try {
|
|
289
|
-
validateAddress(validManifestAddress, 'recipient', 'cosmos');
|
|
290
|
-
} catch (error) {
|
|
291
|
-
const message = (error as ManifestMCPError).message;
|
|
292
|
-
expect(message).toContain('cosmos');
|
|
293
|
-
expect(message).toContain('manifest');
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
describe('validateMemo', () => {
|
|
299
|
-
it('should accept memo within limit', () => {
|
|
300
|
-
expect(() => validateMemo('')).not.toThrow();
|
|
301
|
-
expect(() => validateMemo('short memo')).not.toThrow();
|
|
302
|
-
expect(() => validateMemo('a'.repeat(256))).not.toThrow();
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it('should throw for memo exceeding 256 characters', () => {
|
|
306
|
-
expect(() => validateMemo('a'.repeat(257))).toThrow(ManifestMCPError);
|
|
307
|
-
expect(() => validateMemo('a'.repeat(500))).toThrow(ManifestMCPError);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it('should use TX_FAILED error code', () => {
|
|
311
|
-
try {
|
|
312
|
-
validateMemo('a'.repeat(300));
|
|
313
|
-
} catch (error) {
|
|
314
|
-
expect((error as ManifestMCPError).code).toBe(ManifestMCPErrorCode.TX_FAILED);
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
it('should include length info in error message', () => {
|
|
319
|
-
try {
|
|
320
|
-
validateMemo('a'.repeat(300));
|
|
321
|
-
} catch (error) {
|
|
322
|
-
const message = (error as ManifestMCPError).message;
|
|
323
|
-
expect(message).toContain('300');
|
|
324
|
-
expect(message).toContain('256');
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
describe('validateArgsLength', () => {
|
|
330
|
-
it('should accept args within limit', () => {
|
|
331
|
-
expect(() => validateArgsLength([], 'test')).not.toThrow();
|
|
332
|
-
expect(() => validateArgsLength(['a', 'b', 'c'], 'test')).not.toThrow();
|
|
333
|
-
expect(() => validateArgsLength(new Array(100).fill('arg'), 'test')).not.toThrow();
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
it('should throw for args exceeding 100 items', () => {
|
|
337
|
-
expect(() => validateArgsLength(new Array(101).fill('arg'), 'test')).toThrow(ManifestMCPError);
|
|
338
|
-
expect(() => validateArgsLength(new Array(200).fill('arg'), 'test')).toThrow(ManifestMCPError);
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it('should use TX_FAILED error code', () => {
|
|
342
|
-
try {
|
|
343
|
-
validateArgsLength(new Array(150).fill('arg'), 'test');
|
|
344
|
-
} catch (error) {
|
|
345
|
-
expect((error as ManifestMCPError).code).toBe(ManifestMCPErrorCode.TX_FAILED);
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it('should include context and count in error message', () => {
|
|
350
|
-
try {
|
|
351
|
-
validateArgsLength(new Array(150).fill('arg'), 'bank send');
|
|
352
|
-
} catch (error) {
|
|
353
|
-
const message = (error as ManifestMCPError).message;
|
|
354
|
-
expect(message).toContain('bank send');
|
|
355
|
-
expect(message).toContain('150');
|
|
356
|
-
expect(message).toContain('100');
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
describe('requireArgs', () => {
|
|
362
|
-
it('should pass when args meet minimum count', () => {
|
|
363
|
-
expect(() => requireArgs(['a', 'b'], 2, ['arg1', 'arg2'], 'test')).not.toThrow();
|
|
364
|
-
expect(() => requireArgs(['a', 'b', 'c'], 2, ['arg1', 'arg2'], 'test')).not.toThrow();
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
it('should pass when zero args required', () => {
|
|
368
|
-
expect(() => requireArgs([], 0, [], 'test')).not.toThrow();
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
it('should throw when args below minimum count', () => {
|
|
372
|
-
expect(() => requireArgs(['a'], 2, ['arg1', 'arg2'], 'test')).toThrow(ManifestMCPError);
|
|
373
|
-
expect(() => requireArgs([], 1, ['arg1'], 'test')).toThrow(ManifestMCPError);
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
it('should use TX_FAILED error code by default', () => {
|
|
377
|
-
try {
|
|
378
|
-
requireArgs([], 1, ['arg1'], 'test');
|
|
379
|
-
} catch (error) {
|
|
380
|
-
expect((error as ManifestMCPError).code).toBe(ManifestMCPErrorCode.TX_FAILED);
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
it('should include context in error message', () => {
|
|
385
|
-
try {
|
|
386
|
-
requireArgs(['a'], 2, ['recipient', 'amount'], 'bank send');
|
|
387
|
-
} catch (error) {
|
|
388
|
-
const message = (error as ManifestMCPError).message;
|
|
389
|
-
expect(message).toContain('bank send');
|
|
390
|
-
expect(message).toContain('recipient');
|
|
391
|
-
expect(message).toContain('amount');
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
it('should include received args in error message', () => {
|
|
396
|
-
try {
|
|
397
|
-
requireArgs(['value1'], 2, ['arg1', 'arg2'], 'test');
|
|
398
|
-
} catch (error) {
|
|
399
|
-
const message = (error as ManifestMCPError).message;
|
|
400
|
-
expect(message).toContain('"value1"');
|
|
401
|
-
expect(message).toContain('Received 1');
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
it('should show "none" when no args received', () => {
|
|
406
|
-
try {
|
|
407
|
-
requireArgs([], 1, ['arg1'], 'test');
|
|
408
|
-
} catch (error) {
|
|
409
|
-
const message = (error as ManifestMCPError).message;
|
|
410
|
-
expect(message).toContain('none');
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
it('should include details with expected and received args', () => {
|
|
415
|
-
try {
|
|
416
|
-
requireArgs(['a'], 2, ['arg1', 'arg2'], 'test');
|
|
417
|
-
} catch (error) {
|
|
418
|
-
const details = (error as ManifestMCPError).details;
|
|
419
|
-
expect(details?.expectedArgs).toEqual(['arg1', 'arg2']);
|
|
420
|
-
expect(details?.receivedArgs).toEqual(['a']);
|
|
421
|
-
expect(details?.receivedCount).toBe(1);
|
|
422
|
-
expect(details?.requiredCount).toBe(2);
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
it('should accept custom error code', () => {
|
|
427
|
-
try {
|
|
428
|
-
requireArgs([], 1, ['arg1'], 'test', ManifestMCPErrorCode.QUERY_FAILED);
|
|
429
|
-
} catch (error) {
|
|
430
|
-
expect((error as ManifestMCPError).code).toBe(ManifestMCPErrorCode.QUERY_FAILED);
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
describe('parseHexBytes', () => {
|
|
436
|
-
it('should parse valid hex strings', () => {
|
|
437
|
-
expect(parseHexBytes('deadbeef', 'test', 100)).toEqual(new Uint8Array([0xde, 0xad, 0xbe, 0xef]));
|
|
438
|
-
expect(parseHexBytes('00', 'test', 100)).toEqual(new Uint8Array([0x00]));
|
|
439
|
-
expect(parseHexBytes('ff', 'test', 100)).toEqual(new Uint8Array([0xff]));
|
|
440
|
-
expect(parseHexBytes('0123456789abcdef', 'test', 100)).toEqual(
|
|
441
|
-
new Uint8Array([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef])
|
|
442
|
-
);
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
it('should be case-insensitive', () => {
|
|
446
|
-
expect(parseHexBytes('DEADBEEF', 'test', 100)).toEqual(new Uint8Array([0xde, 0xad, 0xbe, 0xef]));
|
|
447
|
-
expect(parseHexBytes('DeAdBeEf', 'test', 100)).toEqual(new Uint8Array([0xde, 0xad, 0xbe, 0xef]));
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
it('should throw for empty string', () => {
|
|
451
|
-
expect(() => parseHexBytes('', 'field', 100)).toThrow(ManifestMCPError);
|
|
452
|
-
expect(() => parseHexBytes(' ', 'field', 100)).toThrow(ManifestMCPError);
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
it('should throw for odd-length hex strings', () => {
|
|
456
|
-
expect(() => parseHexBytes('abc', 'field', 100)).toThrow(ManifestMCPError);
|
|
457
|
-
expect(() => parseHexBytes('1', 'field', 100)).toThrow(ManifestMCPError);
|
|
458
|
-
expect(() => parseHexBytes('12345', 'field', 100)).toThrow(ManifestMCPError);
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
it('should throw for exceeding max bytes', () => {
|
|
462
|
-
expect(() => parseHexBytes('deadbeef', 'field', 2)).toThrow(ManifestMCPError);
|
|
463
|
-
expect(() => parseHexBytes('0102030405', 'field', 2)).toThrow(ManifestMCPError);
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
it('should accept exactly max bytes', () => {
|
|
467
|
-
expect(parseHexBytes('deadbeef', 'test', 4)).toEqual(new Uint8Array([0xde, 0xad, 0xbe, 0xef]));
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
it('should throw for invalid hex characters', () => {
|
|
471
|
-
expect(() => parseHexBytes('ghij', 'field', 100)).toThrow(ManifestMCPError);
|
|
472
|
-
expect(() => parseHexBytes('12gg', 'field', 100)).toThrow(ManifestMCPError);
|
|
473
|
-
expect(() => parseHexBytes('xy00', 'field', 100)).toThrow(ManifestMCPError);
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
it('should use TX_FAILED error code by default', () => {
|
|
477
|
-
try {
|
|
478
|
-
parseHexBytes('', 'field', 100);
|
|
479
|
-
} catch (error) {
|
|
480
|
-
expect((error as ManifestMCPError).code).toBe(ManifestMCPErrorCode.TX_FAILED);
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
it('should accept custom error code', () => {
|
|
485
|
-
try {
|
|
486
|
-
parseHexBytes('', 'field', 100, ManifestMCPErrorCode.QUERY_FAILED);
|
|
487
|
-
} catch (error) {
|
|
488
|
-
expect((error as ManifestMCPError).code).toBe(ManifestMCPErrorCode.QUERY_FAILED);
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
it('should include field name in error message', () => {
|
|
493
|
-
try {
|
|
494
|
-
parseHexBytes('', 'my-custom-field', 100);
|
|
495
|
-
} catch (error) {
|
|
496
|
-
expect((error as ManifestMCPError).message).toContain('my-custom-field');
|
|
497
|
-
}
|
|
498
|
-
});
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
describe('bytesToHex', () => {
|
|
502
|
-
it('should convert bytes to hex string', () => {
|
|
503
|
-
expect(bytesToHex(new Uint8Array([0xde, 0xad, 0xbe, 0xef]))).toBe('deadbeef');
|
|
504
|
-
expect(bytesToHex(new Uint8Array([0x00]))).toBe('00');
|
|
505
|
-
expect(bytesToHex(new Uint8Array([0xff]))).toBe('ff');
|
|
506
|
-
expect(bytesToHex(new Uint8Array([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]))).toBe('0123456789abcdef');
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
it('should handle empty array', () => {
|
|
510
|
-
expect(bytesToHex(new Uint8Array([]))).toBe('');
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
it('should round-trip with parseHexBytes', () => {
|
|
514
|
-
const original = 'deadbeefcafe1234';
|
|
515
|
-
const bytes = parseHexBytes(original, 'test', 100);
|
|
516
|
-
expect(bytesToHex(bytes)).toBe(original);
|
|
517
|
-
});
|
|
518
|
-
});
|