@0xsequence/catapult 1.3.5 → 1.3.6

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.
@@ -0,0 +1,689 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const resolver_1 = require("../../core/resolver");
4
+ const context_1 = require("../../core/context");
5
+ const repository_1 = require("../../contracts/repository");
6
+ describe("ResolveJsonValue", () => {
7
+ let resolver;
8
+ let context;
9
+ let mockNetwork;
10
+ let mockRegistry;
11
+ beforeEach(async () => {
12
+ resolver = new resolver_1.ValueResolver();
13
+ mockRegistry = new repository_1.ContractRepository();
14
+ const rpcUrl = "http://127.0.0.1:8545";
15
+ mockNetwork = {
16
+ name: "testnet",
17
+ chainId: 999,
18
+ rpcUrl,
19
+ supports: ["sourcify", "etherscan_v2"],
20
+ gasLimit: 10000000,
21
+ evmVersion: "cancun",
22
+ };
23
+ const mockPrivateKey = "0x0000000000000000000000000000000000000000000000000000000000000001";
24
+ context = new context_1.ExecutionContext(mockNetwork, mockPrivateKey, mockRegistry);
25
+ });
26
+ afterEach(async () => {
27
+ if (context) {
28
+ try {
29
+ await context.dispose();
30
+ }
31
+ catch (error) {
32
+ }
33
+ }
34
+ });
35
+ describe("type definition", () => {
36
+ it("should have correct type structure for basic JSON", () => {
37
+ const value = {
38
+ type: "resolve-json",
39
+ arguments: { name: "John", age: 30 },
40
+ };
41
+ expect(value.type).toBe("resolve-json");
42
+ expect(value.arguments).toEqual({ name: "John", age: 30 });
43
+ });
44
+ it("should support nested JSON objects", () => {
45
+ const value = {
46
+ type: "resolve-json",
47
+ arguments: {
48
+ user: {
49
+ profile: {
50
+ name: "Alice",
51
+ settings: {
52
+ theme: "dark",
53
+ notifications: true,
54
+ },
55
+ },
56
+ },
57
+ },
58
+ };
59
+ expect(value.arguments.user.profile.name).toBe("Alice");
60
+ expect(value.arguments.user.profile.settings.theme).toBe("dark");
61
+ });
62
+ it("should support arrays in JSON", () => {
63
+ const value = {
64
+ type: "resolve-json",
65
+ arguments: {
66
+ items: ["first", "second", "third"],
67
+ numbers: [1, 2, 3, 4, 5],
68
+ },
69
+ };
70
+ expect(value.arguments.items).toEqual(["first", "second", "third"]);
71
+ expect(value.arguments.numbers).toEqual([1, 2, 3, 4, 5]);
72
+ });
73
+ it("should support mixed data types", () => {
74
+ const value = {
75
+ type: "resolve-json",
76
+ arguments: {
77
+ string: "hello",
78
+ number: 42,
79
+ boolean: true,
80
+ nullValue: null,
81
+ array: [1, "two", false],
82
+ object: { nested: "value" },
83
+ },
84
+ };
85
+ expect(value.arguments.string).toBe("hello");
86
+ expect(value.arguments.number).toBe(42);
87
+ expect(value.arguments.boolean).toBe(true);
88
+ expect(value.arguments.nullValue).toBeNull();
89
+ expect(value.arguments.array).toEqual([1, "two", false]);
90
+ expect(value.arguments.object.nested).toBe("value");
91
+ });
92
+ });
93
+ describe("basic resolution", () => {
94
+ it("should resolve simple JSON object with primitive values", async () => {
95
+ const value = {
96
+ type: "resolve-json",
97
+ arguments: { name: "John", age: 30, active: true },
98
+ };
99
+ const result = await resolver.resolve(value, context);
100
+ expect(result).toEqual({ name: "John", age: 30, active: true });
101
+ });
102
+ it("should resolve nested JSON object", async () => {
103
+ const value = {
104
+ type: "resolve-json",
105
+ arguments: {
106
+ user: {
107
+ id: 1,
108
+ profile: {
109
+ name: "Alice",
110
+ email: "alice@example.com",
111
+ },
112
+ },
113
+ },
114
+ };
115
+ const result = await resolver.resolve(value, context);
116
+ expect(result).toEqual({
117
+ user: {
118
+ id: 1,
119
+ profile: {
120
+ name: "Alice",
121
+ email: "alice@example.com",
122
+ },
123
+ },
124
+ });
125
+ });
126
+ it("should resolve array of primitive values", async () => {
127
+ const value = {
128
+ type: "resolve-json",
129
+ arguments: [1, 2, 3, "four", "five"],
130
+ };
131
+ const result = await resolver.resolve(value, context);
132
+ expect(result).toEqual([1, 2, 3, "four", "five"]);
133
+ });
134
+ it("should resolve array of objects", async () => {
135
+ const value = {
136
+ type: "resolve-json",
137
+ arguments: [
138
+ { id: 1, name: "First" },
139
+ { id: 2, name: "Second" },
140
+ { id: 3, name: "Third" },
141
+ ],
142
+ };
143
+ const result = await resolver.resolve(value, context);
144
+ expect(result).toEqual([
145
+ { id: 1, name: "First" },
146
+ { id: 2, name: "Second" },
147
+ { id: 3, name: "Third" },
148
+ ]);
149
+ });
150
+ it("should resolve mixed array with objects and primitives", async () => {
151
+ const value = {
152
+ type: "resolve-json",
153
+ arguments: [
154
+ "string",
155
+ { id: 1, value: "object" },
156
+ 42,
157
+ { nested: { deep: "value" } },
158
+ false,
159
+ ],
160
+ };
161
+ const result = await resolver.resolve(value, context);
162
+ expect(result).toEqual([
163
+ "string",
164
+ { id: 1, value: "object" },
165
+ 42,
166
+ { nested: { deep: "value" } },
167
+ false,
168
+ ]);
169
+ });
170
+ });
171
+ describe("template variable resolution", () => {
172
+ it("should resolve template variables in JSON object", async () => {
173
+ context.setOutput("userName", "Alice");
174
+ context.setOutput("userAge", "25");
175
+ const value = {
176
+ type: "resolve-json",
177
+ arguments: {
178
+ name: "{{userName}}",
179
+ age: "{{userAge}}",
180
+ status: "active",
181
+ },
182
+ };
183
+ const result = await resolver.resolve(value, context);
184
+ expect(result).toEqual({
185
+ name: "Alice",
186
+ age: "25",
187
+ status: "active",
188
+ });
189
+ });
190
+ it("should resolve template variables in nested objects", async () => {
191
+ context.setOutput("theme", "dark");
192
+ context.setOutput("notifications", "true");
193
+ const value = {
194
+ type: "resolve-json",
195
+ arguments: {
196
+ user: {
197
+ settings: {
198
+ theme: "{{theme}}",
199
+ notifications: "{{notifications}}",
200
+ },
201
+ },
202
+ },
203
+ };
204
+ const result = await resolver.resolve(value, context);
205
+ expect(result).toEqual({
206
+ user: {
207
+ settings: {
208
+ theme: "dark",
209
+ notifications: "true",
210
+ },
211
+ },
212
+ });
213
+ });
214
+ it("should resolve template variables in arrays", async () => {
215
+ context.setOutput("firstItem", "item1");
216
+ context.setOutput("secondItem", "item2");
217
+ const value = {
218
+ type: "resolve-json",
219
+ arguments: ["{{firstItem}}", "{{secondItem}}", "static"],
220
+ };
221
+ const result = await resolver.resolve(value, context);
222
+ expect(result).toEqual(["item1", "item2", "static"]);
223
+ });
224
+ it("should resolve template variables in array of objects", async () => {
225
+ context.setOutput("id1", "1");
226
+ context.setOutput("name1", "First");
227
+ context.setOutput("id2", "2");
228
+ context.setOutput("name2", "Second");
229
+ const value = {
230
+ type: "resolve-json",
231
+ arguments: [
232
+ { id: "{{id1}}", name: "{{name1}}" },
233
+ { id: "{{id2}}", name: "{{name2}}" },
234
+ ],
235
+ };
236
+ const result = await resolver.resolve(value, context);
237
+ expect(result).toEqual([
238
+ { id: "1", name: "First" },
239
+ { id: "2", name: "Second" },
240
+ ]);
241
+ });
242
+ it("should resolve deeply nested template variables", async () => {
243
+ context.setOutput("contractAddress", "0x1234567890123456789012345678901234567890");
244
+ context.setOutput("functionName", "transfer");
245
+ context.setOutput("amount", "1000000000000000000");
246
+ const value = {
247
+ type: "resolve-json",
248
+ arguments: {
249
+ transaction: {
250
+ to: "{{contractAddress}}",
251
+ data: {
252
+ function: "{{functionName}}",
253
+ params: {
254
+ amount: "{{amount}}",
255
+ },
256
+ },
257
+ },
258
+ },
259
+ };
260
+ const result = await resolver.resolve(value, context);
261
+ expect(result).toEqual({
262
+ transaction: {
263
+ to: "0x1234567890123456789012345678901234567890",
264
+ data: {
265
+ function: "transfer",
266
+ params: {
267
+ amount: "1000000000000000000",
268
+ },
269
+ },
270
+ },
271
+ });
272
+ });
273
+ });
274
+ describe("complex nested structures", () => {
275
+ it("should resolve complex nested structure with arrays and objects", async () => {
276
+ const value = {
277
+ type: "resolve-json",
278
+ arguments: {
279
+ blockchain: {
280
+ ethereum: {
281
+ mainnet: {
282
+ contracts: {
283
+ erc20: [
284
+ {
285
+ address: "0xA0b86a33E6441e6e80D0c4C6C7527d72e1d7e4e1",
286
+ symbol: "USDC",
287
+ decimals: 6,
288
+ },
289
+ {
290
+ address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
291
+ symbol: "DAI",
292
+ decimals: 18,
293
+ },
294
+ ],
295
+ },
296
+ },
297
+ },
298
+ },
299
+ },
300
+ };
301
+ const result = await resolver.resolve(value, context);
302
+ expect(result).toEqual({
303
+ blockchain: {
304
+ ethereum: {
305
+ mainnet: {
306
+ contracts: {
307
+ erc20: [
308
+ {
309
+ address: "0xA0b86a33E6441e6e80D0c4C6C7527d72e1d7e4e1",
310
+ symbol: "USDC",
311
+ decimals: 6,
312
+ },
313
+ {
314
+ address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
315
+ symbol: "DAI",
316
+ decimals: 18,
317
+ },
318
+ ],
319
+ },
320
+ },
321
+ },
322
+ },
323
+ });
324
+ });
325
+ it("should resolve structure with mixed template variables and static values", async () => {
326
+ context.setOutput("networkName", "mainnet");
327
+ context.setOutput("chainId", "1");
328
+ context.setOutput("rpcUrl", "https://mainnet.infura.io/v3/abc123");
329
+ const value = {
330
+ type: "resolve-json",
331
+ arguments: {
332
+ network: {
333
+ name: "{{networkName}}",
334
+ chainId: "{{chainId}}",
335
+ rpcUrl: "{{rpcUrl}}",
336
+ supports: ["etherscan", "sourcify"],
337
+ gasLimit: 10000000,
338
+ },
339
+ contracts: [
340
+ { name: "Token", address: "0x123" },
341
+ { name: "Factory", address: "0x456" },
342
+ ],
343
+ },
344
+ };
345
+ const result = await resolver.resolve(value, context);
346
+ expect(result).toEqual({
347
+ network: {
348
+ name: "mainnet",
349
+ chainId: "1",
350
+ rpcUrl: "https://mainnet.infura.io/v3/abc123",
351
+ supports: ["etherscan", "sourcify"],
352
+ gasLimit: 10000000,
353
+ },
354
+ contracts: [
355
+ { name: "Token", address: "0x123" },
356
+ { name: "Factory", address: "0x456" },
357
+ ],
358
+ });
359
+ });
360
+ });
361
+ describe("edge cases", () => {
362
+ it("should handle empty object", async () => {
363
+ const value = {
364
+ type: "resolve-json",
365
+ arguments: {},
366
+ };
367
+ const result = await resolver.resolve(value, context);
368
+ expect(result).toEqual({});
369
+ });
370
+ it("should handle empty array", async () => {
371
+ const value = {
372
+ type: "resolve-json",
373
+ arguments: [],
374
+ };
375
+ const result = await resolver.resolve(value, context);
376
+ expect(result).toEqual([]);
377
+ });
378
+ it("should handle null values", async () => {
379
+ const value = {
380
+ type: "resolve-json",
381
+ arguments: {
382
+ nullValue: null,
383
+ undefinedValue: undefined,
384
+ emptyString: "",
385
+ zero: 0,
386
+ falseValue: false,
387
+ },
388
+ };
389
+ const result = await resolver.resolve(value, context);
390
+ expect(result).toEqual({
391
+ nullValue: null,
392
+ undefinedValue: undefined,
393
+ emptyString: "",
394
+ zero: 0,
395
+ falseValue: false,
396
+ });
397
+ });
398
+ it("should handle primitive values directly", async () => {
399
+ const stringValue = {
400
+ type: "resolve-json",
401
+ arguments: "hello world",
402
+ };
403
+ const numberValue = {
404
+ type: "resolve-json",
405
+ arguments: 42,
406
+ };
407
+ const booleanValue = {
408
+ type: "resolve-json",
409
+ arguments: true,
410
+ };
411
+ expect(await resolver.resolve(stringValue, context)).toBe("hello world");
412
+ expect(await resolver.resolve(numberValue, context)).toBe(42);
413
+ expect(await resolver.resolve(booleanValue, context)).toBe(true);
414
+ });
415
+ it("should handle deeply nested arrays", async () => {
416
+ const value = {
417
+ type: "resolve-json",
418
+ arguments: [
419
+ [
420
+ [1, 2, 3],
421
+ ["a", "b", "c"],
422
+ ],
423
+ [[{ id: 1 }, { id: 2 }], [{ name: "test" }]],
424
+ ],
425
+ };
426
+ const result = await resolver.resolve(value, context);
427
+ expect(result).toEqual([
428
+ [
429
+ [1, 2, 3],
430
+ ["a", "b", "c"],
431
+ ],
432
+ [[{ id: 1 }, { id: 2 }], [{ name: "test" }]],
433
+ ]);
434
+ });
435
+ it("should handle large numbers and special values", async () => {
436
+ const value = {
437
+ type: "resolve-json",
438
+ arguments: {
439
+ largeNumber: 115792089237316195423570985008687907853269984665640564039457584007913129639935n,
440
+ floatNumber: 3.14159,
441
+ negativeNumber: -42,
442
+ scientificNotation: 1e18,
443
+ },
444
+ };
445
+ const result = await resolver.resolve(value, context);
446
+ expect(result).toEqual({
447
+ largeNumber: 115792089237316195423570985008687907853269984665640564039457584007913129639935n,
448
+ floatNumber: 3.14159,
449
+ negativeNumber: -42,
450
+ scientificNotation: 1e18,
451
+ });
452
+ });
453
+ });
454
+ describe("recursive resolution", () => {
455
+ it("should recursively resolve all nested values", async () => {
456
+ context.setOutput("level1", "resolved1");
457
+ context.setOutput("level2", "resolved2");
458
+ context.setOutput("level3", "resolved3");
459
+ const value = {
460
+ type: "resolve-json",
461
+ arguments: {
462
+ level1: "{{level1}}",
463
+ nested: {
464
+ level2: "{{level2}}",
465
+ deeper: {
466
+ level3: "{{level3}}",
467
+ array: ["{{level1}}", { value: "{{level2}}" }],
468
+ },
469
+ },
470
+ },
471
+ };
472
+ const result = await resolver.resolve(value, context);
473
+ expect(result).toEqual({
474
+ level1: "resolved1",
475
+ nested: {
476
+ level2: "resolved2",
477
+ deeper: {
478
+ level3: "resolved3",
479
+ array: ["resolved1", { value: "resolved2" }],
480
+ },
481
+ },
482
+ });
483
+ });
484
+ it("should handle circular-like structures without infinite recursion", async () => {
485
+ const value = {
486
+ type: "resolve-json",
487
+ arguments: {
488
+ a: {
489
+ b: {
490
+ c: {
491
+ d: "value",
492
+ },
493
+ },
494
+ },
495
+ e: [
496
+ {
497
+ f: {
498
+ g: "another value",
499
+ },
500
+ },
501
+ ],
502
+ },
503
+ };
504
+ const result = await resolver.resolve(value, context);
505
+ expect(result).toEqual({
506
+ a: {
507
+ b: {
508
+ c: {
509
+ d: "value",
510
+ },
511
+ },
512
+ },
513
+ e: [
514
+ {
515
+ f: {
516
+ g: "another value",
517
+ },
518
+ },
519
+ ],
520
+ });
521
+ });
522
+ });
523
+ describe("integration with other value types", () => {
524
+ it("should work with basic-arithmetic values in JSON", async () => {
525
+ const value = {
526
+ type: "resolve-json",
527
+ arguments: {
528
+ calculation: {
529
+ type: "basic-arithmetic",
530
+ arguments: { operation: "add", values: [10, 20] },
531
+ },
532
+ static: "value",
533
+ },
534
+ };
535
+ const result = await resolver.resolve(value, context);
536
+ expect(result).toEqual({
537
+ calculation: "30",
538
+ static: "value",
539
+ });
540
+ });
541
+ it("should work with read-json values in JSON", async () => {
542
+ const value = {
543
+ type: "resolve-json",
544
+ arguments: {
545
+ data: {
546
+ type: "read-json",
547
+ arguments: {
548
+ json: { name: "John", age: 30 },
549
+ path: "name",
550
+ },
551
+ },
552
+ metadata: "extracted",
553
+ },
554
+ };
555
+ const result = await resolver.resolve(value, context);
556
+ expect(result).toEqual({
557
+ data: "John",
558
+ metadata: "extracted",
559
+ });
560
+ });
561
+ it("should work with nested resolve-json values", async () => {
562
+ const value = {
563
+ type: "resolve-json",
564
+ arguments: {
565
+ outer: {
566
+ type: "resolve-json",
567
+ arguments: {
568
+ inner: {
569
+ type: "resolve-json",
570
+ arguments: {
571
+ value: "deeply nested",
572
+ },
573
+ },
574
+ },
575
+ },
576
+ },
577
+ };
578
+ const result = await resolver.resolve(value, context);
579
+ expect(result).toEqual({
580
+ outer: {
581
+ inner: {
582
+ value: "deeply nested",
583
+ },
584
+ },
585
+ });
586
+ });
587
+ it("should work with Network() expressions in JSON", async () => {
588
+ const value = {
589
+ type: "resolve-json",
590
+ arguments: {
591
+ network: {
592
+ chainId: "{{Network().chainId}}",
593
+ name: "{{Network().name}}",
594
+ rpcUrl: "{{Network().rpcUrl}}",
595
+ },
596
+ static: "value",
597
+ },
598
+ };
599
+ const result = await resolver.resolve(value, context);
600
+ expect(result).toEqual({
601
+ network: {
602
+ chainId: 999,
603
+ name: "testnet",
604
+ rpcUrl: "http://127.0.0.1:8545",
605
+ },
606
+ static: "value",
607
+ });
608
+ });
609
+ it("should work with Network() expressions deeply nested in JSON", async () => {
610
+ const value = {
611
+ type: "resolve-json",
612
+ arguments: {
613
+ config: {
614
+ blockchain: {
615
+ ethereum: {
616
+ networks: {
617
+ mainnet: {
618
+ chainId: "{{Network().chainId}}",
619
+ name: "{{Network().name}}",
620
+ rpcUrl: "{{Network().rpcUrl}}",
621
+ supports: "{{Network().supports}}",
622
+ gasLimit: "{{Network().gasLimit}}",
623
+ },
624
+ },
625
+ settings: {
626
+ evmVersion: "{{Network().evmVersion}}",
627
+ testnet: "{{Network().testnet}}",
628
+ },
629
+ },
630
+ },
631
+ metadata: {
632
+ source: "catapult",
633
+ version: "1.0.0",
634
+ },
635
+ },
636
+ contracts: [
637
+ {
638
+ name: "Token",
639
+ network: "{{Network().name}}",
640
+ chainId: "{{Network().chainId}}",
641
+ },
642
+ {
643
+ name: "Factory",
644
+ rpcUrl: "{{Network().rpcUrl}}",
645
+ },
646
+ ],
647
+ },
648
+ };
649
+ const result = await resolver.resolve(value, context);
650
+ expect(result).toEqual({
651
+ config: {
652
+ blockchain: {
653
+ ethereum: {
654
+ networks: {
655
+ mainnet: {
656
+ chainId: 999,
657
+ name: "testnet",
658
+ rpcUrl: "http://127.0.0.1:8545",
659
+ supports: ["sourcify", "etherscan_v2"],
660
+ gasLimit: 10000000,
661
+ },
662
+ },
663
+ settings: {
664
+ evmVersion: "cancun",
665
+ testnet: false,
666
+ },
667
+ },
668
+ },
669
+ metadata: {
670
+ source: "catapult",
671
+ version: "1.0.0",
672
+ },
673
+ },
674
+ contracts: [
675
+ {
676
+ name: "Token",
677
+ network: "testnet",
678
+ chainId: 999,
679
+ },
680
+ {
681
+ name: "Factory",
682
+ rpcUrl: "http://127.0.0.1:8545",
683
+ },
684
+ ],
685
+ });
686
+ });
687
+ });
688
+ });
689
+ //# sourceMappingURL=resolve-json-value.spec.js.map