@apibara/starknet 2.1.0-beta.23 → 2.1.0-beta.25

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.
@@ -1,832 +0,0 @@
1
- import { Schema } from "@effect/schema";
2
- import { describe, expect, it } from "vitest";
3
-
4
- import {
5
- ContractChangeFilter,
6
- EventFilter,
7
- HeaderFilter,
8
- Key,
9
- NonceUpdateFilter,
10
- StorageDiffFilter,
11
- TransactionFilter,
12
- mergeFilter,
13
- } from "./filter";
14
-
15
- describe("HeaderFilter", () => {
16
- const encode = Schema.encodeSync(HeaderFilter);
17
- const decode = Schema.decodeSync(HeaderFilter);
18
-
19
- it("should encode and decode", () => {
20
- const always = "always";
21
-
22
- const proto = encode(always);
23
- const decoded = decode(proto);
24
- expect(decoded).toEqual(always);
25
- });
26
- });
27
-
28
- describe("Key", () => {
29
- const encode = Schema.encodeSync(Key);
30
- const decode = Schema.decodeSync(Key);
31
-
32
- it("should encode null values", () => {
33
- const proto = encode(null);
34
- expect(proto).toMatchInlineSnapshot(`
35
- {
36
- "value": undefined,
37
- }
38
- `);
39
- const decoded = decode(proto);
40
- expect(decoded).toBe(null);
41
- });
42
-
43
- it("should encode field elements", () => {
44
- const proto = encode("0x1234");
45
- expect(proto).toMatchInlineSnapshot(`
46
- {
47
- "value": {
48
- "x0": 0n,
49
- "x1": 0n,
50
- "x2": 0n,
51
- "x3": 4660n,
52
- },
53
- }
54
- `);
55
- const decoded = decode(proto);
56
- expect(decoded).toMatchInlineSnapshot(
57
- `"0x0000000000000000000000000000000000000000000000000000000000001234"`,
58
- );
59
- });
60
- });
61
-
62
- describe("EventFilter", () => {
63
- const encode = Schema.encodeSync(EventFilter);
64
- const decode = Schema.decodeSync(EventFilter);
65
-
66
- it("should encode and decode default values", () => {
67
- const proto = encode({});
68
- expect(proto).toMatchInlineSnapshot("{}");
69
- const decoded = decode(proto);
70
- expect(decoded).toMatchInlineSnapshot("{}");
71
- });
72
-
73
- it("should encode and decode all values", () => {
74
- const proto = encode({
75
- address: "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
76
- keys: [
77
- "0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
78
- null,
79
- null,
80
- "0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
81
- ],
82
- strict: true,
83
- transactionStatus: "all",
84
- includeTransaction: true,
85
- includeReceipt: true,
86
- includeMessages: true,
87
- includeSiblings: true,
88
- });
89
- expect(proto).toMatchInlineSnapshot(`
90
- {
91
- "address": {
92
- "x0": 0n,
93
- "x1": 170n,
94
- "x2": 12297829382473034410n,
95
- "x3": 12297829382473034410n,
96
- },
97
- "includeMessages": true,
98
- "includeReceipt": true,
99
- "includeSiblings": true,
100
- "includeTransaction": true,
101
- "keys": [
102
- {
103
- "value": {
104
- "x0": 0n,
105
- "x1": 187n,
106
- "x2": 13527612320720337851n,
107
- "x3": 13527612320720337851n,
108
- },
109
- },
110
- {
111
- "value": undefined,
112
- },
113
- {
114
- "value": undefined,
115
- },
116
- {
117
- "value": {
118
- "x0": 0n,
119
- "x1": 0n,
120
- "x2": 14757395258967641292n,
121
- "x3": 14757395258967641292n,
122
- },
123
- },
124
- ],
125
- "strict": true,
126
- "transactionStatus": 3,
127
- }
128
- `);
129
- const decoded = decode(proto);
130
- expect(decoded).toMatchInlineSnapshot(`
131
- {
132
- "address": "0x000000000000000000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
133
- "includeMessages": true,
134
- "includeReceipt": true,
135
- "includeSiblings": true,
136
- "includeTransaction": true,
137
- "keys": [
138
- "0x000000000000000000000000000000bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
139
- null,
140
- null,
141
- "0x00000000000000000000000000000000cccccccccccccccccccccccccccccccc",
142
- ],
143
- "strict": true,
144
- "transactionStatus": "all",
145
- }
146
- `);
147
- });
148
- });
149
-
150
- describe("TransactionFilter", () => {
151
- const encode = Schema.encodeSync(TransactionFilter);
152
- const decode = Schema.decodeSync(TransactionFilter);
153
-
154
- it("should encode and decode default values", () => {
155
- const proto = encode({});
156
- expect(proto).toMatchInlineSnapshot("{}");
157
- const decoded = decode(proto);
158
- expect(decoded).toMatchInlineSnapshot("{}");
159
- });
160
-
161
- it("should encode and decode extra fields", () => {
162
- const proto = encode({
163
- includeEvents: true,
164
- includeMessages: true,
165
- includeReceipt: true,
166
- transactionStatus: "reverted",
167
- });
168
- expect(proto).toMatchInlineSnapshot(`
169
- {
170
- "includeEvents": true,
171
- "includeMessages": true,
172
- "includeReceipt": true,
173
- "transactionStatus": 2,
174
- }
175
- `);
176
- const decoded = decode(proto);
177
- expect(decoded).toMatchInlineSnapshot(`
178
- {
179
- "includeEvents": true,
180
- "includeMessages": true,
181
- "includeReceipt": true,
182
- "transactionStatus": "reverted",
183
- }
184
- `);
185
- });
186
-
187
- it("should encode and decode invoke transaction v0", () => {
188
- const proto = encode({
189
- transactionType: {
190
- _tag: "invokeV0",
191
- invokeV0: {},
192
- },
193
- });
194
- expect(proto).toMatchInlineSnapshot(`
195
- {
196
- "transactionType": {
197
- "$case": "invokeV0",
198
- "invokeV0": {},
199
- },
200
- }
201
- `);
202
- const decoded = decode(proto);
203
- expect(decoded).toMatchInlineSnapshot(`
204
- {
205
- "transactionType": {
206
- "_tag": "invokeV0",
207
- "invokeV0": {},
208
- },
209
- }
210
- `);
211
- });
212
-
213
- it("should encode and decode invoke transaction v1", () => {
214
- const proto = encode({
215
- transactionType: {
216
- _tag: "invokeV1",
217
- invokeV1: {},
218
- },
219
- });
220
- expect(proto).toMatchInlineSnapshot(`
221
- {
222
- "transactionType": {
223
- "$case": "invokeV1",
224
- "invokeV1": {},
225
- },
226
- }
227
- `);
228
- const decoded = decode(proto);
229
- expect(decoded).toMatchInlineSnapshot(`
230
- {
231
- "transactionType": {
232
- "_tag": "invokeV1",
233
- "invokeV1": {},
234
- },
235
- }
236
- `);
237
- });
238
-
239
- it("should encode and decode invoke transaction v3", () => {
240
- const proto = encode({
241
- transactionType: {
242
- _tag: "invokeV3",
243
- invokeV3: {},
244
- },
245
- });
246
- expect(proto).toMatchInlineSnapshot(`
247
- {
248
- "transactionType": {
249
- "$case": "invokeV3",
250
- "invokeV3": {},
251
- },
252
- }
253
- `);
254
- const decoded = decode(proto);
255
- expect(decoded).toMatchInlineSnapshot(`
256
- {
257
- "transactionType": {
258
- "_tag": "invokeV3",
259
- "invokeV3": {},
260
- },
261
- }
262
- `);
263
- });
264
-
265
- it("should encode and decode deploy transaction", () => {
266
- const proto = encode({
267
- transactionType: {
268
- _tag: "deploy",
269
- deploy: {},
270
- },
271
- });
272
- expect(proto).toMatchInlineSnapshot(`
273
- {
274
- "transactionType": {
275
- "$case": "deploy",
276
- "deploy": {},
277
- },
278
- }
279
- `);
280
- const decoded = decode(proto);
281
- expect(decoded).toMatchInlineSnapshot(`
282
- {
283
- "transactionType": {
284
- "_tag": "deploy",
285
- "deploy": {},
286
- },
287
- }
288
- `);
289
- });
290
-
291
- it("should encode and decode declare transaction v0", () => {
292
- const proto = encode({
293
- transactionType: {
294
- _tag: "declareV0",
295
- declareV0: {},
296
- },
297
- });
298
- expect(proto).toMatchInlineSnapshot(`
299
- {
300
- "transactionType": {
301
- "$case": "declareV0",
302
- "declareV0": {},
303
- },
304
- }
305
- `);
306
- const decoded = decode(proto);
307
- expect(decoded).toMatchInlineSnapshot(`
308
- {
309
- "transactionType": {
310
- "_tag": "declareV0",
311
- "declareV0": {},
312
- },
313
- }
314
- `);
315
- });
316
-
317
- it("should encode and decode declare transaction v1", () => {
318
- const proto = encode({
319
- transactionType: {
320
- _tag: "declareV1",
321
- declareV1: {},
322
- },
323
- });
324
- expect(proto).toMatchInlineSnapshot(`
325
- {
326
- "transactionType": {
327
- "$case": "declareV1",
328
- "declareV1": {},
329
- },
330
- }
331
- `);
332
- const decoded = decode(proto);
333
- expect(decoded).toMatchInlineSnapshot(`
334
- {
335
- "transactionType": {
336
- "_tag": "declareV1",
337
- "declareV1": {},
338
- },
339
- }
340
- `);
341
- });
342
-
343
- it("should encode and decode declare transaction v2", () => {
344
- const proto = encode({
345
- transactionType: {
346
- _tag: "declareV2",
347
- declareV2: {},
348
- },
349
- });
350
- expect(proto).toMatchInlineSnapshot(`
351
- {
352
- "transactionType": {
353
- "$case": "declareV2",
354
- "declareV2": {},
355
- },
356
- }
357
- `);
358
- const decoded = decode(proto);
359
- expect(decoded).toMatchInlineSnapshot(`
360
- {
361
- "transactionType": {
362
- "_tag": "declareV2",
363
- "declareV2": {},
364
- },
365
- }
366
- `);
367
- });
368
-
369
- it("should encode and decode declare transaction v3", () => {
370
- const proto = encode({
371
- transactionType: {
372
- _tag: "declareV3",
373
- declareV3: {},
374
- },
375
- });
376
- expect(proto).toMatchInlineSnapshot(`
377
- {
378
- "transactionType": {
379
- "$case": "declareV3",
380
- "declareV3": {},
381
- },
382
- }
383
- `);
384
- const decoded = decode(proto);
385
- expect(decoded).toMatchInlineSnapshot(`
386
- {
387
- "transactionType": {
388
- "_tag": "declareV3",
389
- "declareV3": {},
390
- },
391
- }
392
- `);
393
- });
394
-
395
- it("should encode and decode l1 handler transaction", () => {
396
- const proto = encode({
397
- transactionType: {
398
- _tag: "l1Handler",
399
- l1Handler: {},
400
- },
401
- });
402
- expect(proto).toMatchInlineSnapshot(`
403
- {
404
- "transactionType": {
405
- "$case": "l1Handler",
406
- "l1Handler": {},
407
- },
408
- }
409
- `);
410
- const decoded = decode(proto);
411
- expect(decoded).toMatchInlineSnapshot(`
412
- {
413
- "transactionType": {
414
- "_tag": "l1Handler",
415
- "l1Handler": {},
416
- },
417
- }
418
- `);
419
- });
420
-
421
- it("should encode and decode deploy account transaction v1", () => {
422
- const proto = encode({
423
- transactionType: {
424
- _tag: "deployAccountV1",
425
- deployAccountV1: {},
426
- },
427
- });
428
- expect(proto).toMatchInlineSnapshot(`
429
- {
430
- "transactionType": {
431
- "$case": "deployAccountV1",
432
- "deployAccountV1": {},
433
- },
434
- }
435
- `);
436
- const decoded = decode(proto);
437
- expect(decoded).toMatchInlineSnapshot(`
438
- {
439
- "transactionType": {
440
- "_tag": "deployAccountV1",
441
- "deployAccountV1": {},
442
- },
443
- }
444
- `);
445
- });
446
-
447
- it("should encode and decode deploy account transaction v3", () => {
448
- const proto = encode({
449
- transactionType: {
450
- _tag: "deployAccountV3",
451
- deployAccountV3: {},
452
- },
453
- });
454
- expect(proto).toMatchInlineSnapshot(`
455
- {
456
- "transactionType": {
457
- "$case": "deployAccountV3",
458
- "deployAccountV3": {},
459
- },
460
- }
461
- `);
462
- const decoded = decode(proto);
463
- expect(decoded).toMatchInlineSnapshot(`
464
- {
465
- "transactionType": {
466
- "_tag": "deployAccountV3",
467
- "deployAccountV3": {},
468
- },
469
- }
470
- `);
471
- });
472
- });
473
-
474
- describe("StorageDiffFilter", () => {
475
- const encode = Schema.encodeSync(StorageDiffFilter);
476
- const decode = Schema.decodeSync(StorageDiffFilter);
477
-
478
- it("should encode and decode storage diffs", () => {
479
- const proto = encode({
480
- contractAddress: "0xAABBCCDD",
481
- });
482
-
483
- expect(proto).toMatchInlineSnapshot(`
484
- {
485
- "contractAddress": {
486
- "x0": 0n,
487
- "x1": 0n,
488
- "x2": 0n,
489
- "x3": 2864434397n,
490
- },
491
- }
492
- `);
493
- const decoded = decode(proto);
494
- expect(decoded).toMatchInlineSnapshot(`
495
- {
496
- "contractAddress": "0x00000000000000000000000000000000000000000000000000000000aabbccdd",
497
- }
498
- `);
499
- });
500
- });
501
-
502
- describe("ContractChangeFilter", () => {
503
- const encode = Schema.encodeSync(ContractChangeFilter);
504
- const decode = Schema.decodeSync(ContractChangeFilter);
505
-
506
- it("should encode and decode declared class changes", () => {
507
- const proto = encode({
508
- change: {
509
- _tag: "declaredClass",
510
- declaredClass: {},
511
- },
512
- });
513
- expect(proto).toMatchInlineSnapshot(`
514
- {
515
- "change": {
516
- "$case": "declaredClass",
517
- "declaredClass": {},
518
- },
519
- }
520
- `);
521
- const decoded = decode(proto);
522
- expect(decoded).toMatchInlineSnapshot(`
523
- {
524
- "change": {
525
- "_tag": "declaredClass",
526
- "declaredClass": {},
527
- },
528
- }
529
- `);
530
- });
531
-
532
- it("should encode and decode replaced class changes", () => {
533
- const proto = encode({
534
- change: {
535
- _tag: "replacedClass",
536
- replacedClass: {},
537
- },
538
- });
539
- expect(proto).toMatchInlineSnapshot(`
540
- {
541
- "change": {
542
- "$case": "replacedClass",
543
- "replacedClass": {},
544
- },
545
- }
546
- `);
547
- const decoded = decode(proto);
548
- expect(decoded).toMatchInlineSnapshot(`
549
- {
550
- "change": {
551
- "_tag": "replacedClass",
552
- "replacedClass": {},
553
- },
554
- }
555
- `);
556
- });
557
-
558
- it("should encode and decode deployed contract changes", () => {
559
- const proto = encode({
560
- change: {
561
- _tag: "deployedContract",
562
- deployedContract: {},
563
- },
564
- });
565
- expect(proto).toMatchInlineSnapshot(`
566
- {
567
- "change": {
568
- "$case": "deployedContract",
569
- "deployedContract": {},
570
- },
571
- }
572
- `);
573
- const decoded = decode(proto);
574
- expect(decoded).toMatchInlineSnapshot(`
575
- {
576
- "change": {
577
- "_tag": "deployedContract",
578
- "deployedContract": {},
579
- },
580
- }
581
- `);
582
- });
583
- });
584
-
585
- describe("NonceUpdateFilter", () => {
586
- const encode = Schema.encodeSync(NonceUpdateFilter);
587
- const decode = Schema.decodeSync(NonceUpdateFilter);
588
-
589
- it("should encode and decode nonce updates", () => {
590
- const proto = encode({
591
- contractAddress: "0xAABBCCDD",
592
- });
593
-
594
- expect(proto).toMatchInlineSnapshot(`
595
- {
596
- "contractAddress": {
597
- "x0": 0n,
598
- "x1": 0n,
599
- "x2": 0n,
600
- "x3": 2864434397n,
601
- },
602
- }
603
- `);
604
- const decoded = decode(proto);
605
- expect(decoded).toMatchInlineSnapshot(`
606
- {
607
- "contractAddress": "0x00000000000000000000000000000000000000000000000000000000aabbccdd",
608
- }
609
- `);
610
- });
611
- });
612
-
613
- describe("mergeFilter", () => {
614
- it("returns header.always if any has it", () => {
615
- const fa = mergeFilter({}, { header: "always" });
616
- expect(fa).toMatchInlineSnapshot(`
617
- {
618
- "contractChanges": [],
619
- "events": [],
620
- "header": "always",
621
- "messages": [],
622
- "nonceUpdates": [],
623
- "storageDiffs": [],
624
- "transactions": [],
625
- }
626
- `);
627
- const fb = mergeFilter({ header: "always" }, {});
628
- expect(fb).toMatchInlineSnapshot(`
629
- {
630
- "contractChanges": [],
631
- "events": [],
632
- "header": "always",
633
- "messages": [],
634
- "nonceUpdates": [],
635
- "storageDiffs": [],
636
- "transactions": [],
637
- }
638
- `);
639
- });
640
-
641
- it("returns an empty header by default", () => {
642
- const f = mergeFilter({}, {});
643
- expect(f).toMatchInlineSnapshot(`
644
- {
645
- "contractChanges": [],
646
- "events": [],
647
- "header": undefined,
648
- "messages": [],
649
- "nonceUpdates": [],
650
- "storageDiffs": [],
651
- "transactions": [],
652
- }
653
- `);
654
- });
655
-
656
- it("concatenates transactions", () => {
657
- const f = mergeFilter(
658
- {
659
- transactions: [{ transactionType: { _tag: "invokeV0", invokeV0: {} } }],
660
- },
661
- {
662
- transactions: [{ transactionType: { _tag: "invokeV3", invokeV3: {} } }],
663
- },
664
- );
665
- expect(f).toMatchInlineSnapshot(`
666
- {
667
- "contractChanges": [],
668
- "events": [],
669
- "header": undefined,
670
- "messages": [],
671
- "nonceUpdates": [],
672
- "storageDiffs": [],
673
- "transactions": [
674
- {
675
- "transactionType": {
676
- "_tag": "invokeV0",
677
- "invokeV0": {},
678
- },
679
- },
680
- {
681
- "transactionType": {
682
- "_tag": "invokeV3",
683
- "invokeV3": {},
684
- },
685
- },
686
- ],
687
- }
688
- `);
689
- });
690
-
691
- it("concatenates events", () => {
692
- const f = mergeFilter(
693
- { events: [{ address: "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }] },
694
- { events: [{ address: "0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }] },
695
- );
696
- expect(f).toMatchInlineSnapshot(`
697
- {
698
- "contractChanges": [],
699
- "events": [
700
- {
701
- "address": "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
702
- },
703
- {
704
- "address": "0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
705
- },
706
- ],
707
- "header": undefined,
708
- "messages": [],
709
- "nonceUpdates": [],
710
- "storageDiffs": [],
711
- "transactions": [],
712
- }
713
- `);
714
- });
715
-
716
- it("concatenates messages", () => {
717
- const f = mergeFilter(
718
- { messages: [{ fromAddress: "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }] },
719
- { messages: [{ fromAddress: "0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }] },
720
- );
721
- expect(f).toMatchInlineSnapshot(`
722
- {
723
- "contractChanges": [],
724
- "events": [],
725
- "header": undefined,
726
- "messages": [
727
- {
728
- "fromAddress": "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
729
- },
730
- {
731
- "fromAddress": "0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
732
- },
733
- ],
734
- "nonceUpdates": [],
735
- "storageDiffs": [],
736
- "transactions": [],
737
- }
738
- `);
739
- });
740
-
741
- it("concatenates storage diffs", () => {
742
- const f = mergeFilter(
743
- { storageDiffs: [{ contractAddress: "0xAABBCCDD" }] },
744
- { storageDiffs: [{ contractAddress: "0xBBBBCCDD" }] },
745
- );
746
-
747
- expect(f).toMatchInlineSnapshot(`
748
- {
749
- "contractChanges": [],
750
- "events": [],
751
- "header": undefined,
752
- "messages": [],
753
- "nonceUpdates": [],
754
- "storageDiffs": [
755
- {
756
- "contractAddress": "0xAABBCCDD",
757
- },
758
- {
759
- "contractAddress": "0xBBBBCCDD",
760
- },
761
- ],
762
- "transactions": [],
763
- }
764
- `);
765
- });
766
-
767
- it("concatenates contract changes", () => {
768
- const f = mergeFilter(
769
- {
770
- contractChanges: [
771
- { change: { _tag: "declaredClass", declaredClass: {} } },
772
- ],
773
- },
774
- {
775
- contractChanges: [
776
- { change: { _tag: "replacedClass", replacedClass: {} } },
777
- ],
778
- },
779
- );
780
-
781
- expect(f).toMatchInlineSnapshot(`
782
- {
783
- "contractChanges": [
784
- {
785
- "change": {
786
- "_tag": "declaredClass",
787
- "declaredClass": {},
788
- },
789
- },
790
- {
791
- "change": {
792
- "_tag": "replacedClass",
793
- "replacedClass": {},
794
- },
795
- },
796
- ],
797
- "events": [],
798
- "header": undefined,
799
- "messages": [],
800
- "nonceUpdates": [],
801
- "storageDiffs": [],
802
- "transactions": [],
803
- }
804
- `);
805
- });
806
-
807
- it("concatenates nonce updates", () => {
808
- const f = mergeFilter(
809
- { nonceUpdates: [{ contractAddress: "0xAABBCCDD" }] },
810
- { nonceUpdates: [{ contractAddress: "0xBBBBCCDD" }] },
811
- );
812
-
813
- expect(f).toMatchInlineSnapshot(`
814
- {
815
- "contractChanges": [],
816
- "events": [],
817
- "header": undefined,
818
- "messages": [],
819
- "nonceUpdates": [
820
- {
821
- "contractAddress": "0xAABBCCDD",
822
- },
823
- {
824
- "contractAddress": "0xBBBBCCDD",
825
- },
826
- ],
827
- "storageDiffs": [],
828
- "transactions": [],
829
- }
830
- `);
831
- });
832
- });