@graphprotocol/graph-cli 0.32.0 → 0.34.0-alpha.0

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.
Files changed (42) hide show
  1. package/README.md +2 -2
  2. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/README.md +1 -1
  3. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +200 -0
  4. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +28 -28
  5. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/methods.txt +18 -0
  6. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +1 -1
  7. package/examples/basic-event-handlers/node_modules/keccak/build/Makefile +342 -0
  8. package/examples/basic-event-handlers/node_modules/keccak/build/Release/.deps/Release/obj.target/keccak/src/addon.o.d.raw +69 -0
  9. package/examples/basic-event-handlers/node_modules/keccak/build/binding.Makefile +6 -0
  10. package/examples/basic-event-handlers/node_modules/keccak/build/config.gypi +27 -11
  11. package/examples/basic-event-handlers/node_modules/keccak/build/gyp-mac-tool +772 -0
  12. package/examples/basic-event-handlers/node_modules/keccak/build/keccak.target.mk +207 -0
  13. package/examples/basic-event-handlers/node_modules/websocket/build/Makefile +347 -0
  14. package/examples/basic-event-handlers/node_modules/websocket/build/Release/.deps/Release/obj.target/bufferutil/src/bufferutil.o.d.raw +67 -0
  15. package/examples/basic-event-handlers/node_modules/websocket/build/binding.Makefile +6 -0
  16. package/examples/basic-event-handlers/node_modules/websocket/build/bufferutil.target.mk +190 -0
  17. package/examples/basic-event-handlers/node_modules/websocket/build/config.gypi +23 -7
  18. package/examples/basic-event-handlers/node_modules/websocket/build/gyp-mac-tool +772 -0
  19. package/examples/basic-event-handlers/node_modules/websocket/build/validation.target.mk +190 -0
  20. package/examples/basic-event-handlers/package.json +1 -1
  21. package/examples/basic-event-handlers/yarn.lock +4 -4
  22. package/examples/example-subgraph/package.json +1 -1
  23. package/examples/example-subgraph/yarn.lock +4 -4
  24. package/package.json +1 -1
  25. package/src/codegen/template.js +8 -1
  26. package/src/codegen/types/conversions.js +103 -2
  27. package/src/codegen/types/index.test.js +347 -0
  28. package/src/command-helpers/abi.js +3 -0
  29. package/src/command-helpers/jsonrpc.js +5 -1
  30. package/src/command-helpers/scaffold.js +43 -14
  31. package/src/command-helpers/studio.js +1 -1
  32. package/src/commands/add.js +2 -1
  33. package/src/commands/init.js +6 -6
  34. package/src/commands/test.js +5 -9
  35. package/src/migrations/mapping_api_version_0_0_4.js +1 -1
  36. package/src/migrations/mapping_api_version_0_0_5.js +1 -1
  37. package/src/protocols/index.js +4 -4
  38. package/src/protocols/ipfs/codegen/file_template.js +40 -0
  39. package/src/scaffold/ethereum.test.js +259 -0
  40. package/src/scaffold/index.js +16 -1
  41. package/src/scaffold/tests.js +196 -0
  42. package/src/subgraph.js +10 -4
@@ -191,6 +191,171 @@ describe('ethereum.Value -> AssemblyScript', () => {
191
191
  expect(codegen.ascTypeForEthereum('string[4]')).toBe('Array<string>')
192
192
  expect(codegen.ascTypeForEthereum('string[754]')).toBe('Array<string>')
193
193
  })
194
+
195
+ // Multi dimensional arrays
196
+
197
+ test('address[*][*] -> Array<Array<Address>>', () => {
198
+ expect(codegen.ethereumToAsc('x', 'address[][]')).toBe('x.toAddressMatrix()')
199
+ expect(codegen.ethereumToAsc('x', 'address[5][]')).toBe('x.toAddressMatrix()')
200
+ expect(codegen.ethereumToAsc('x', 'address[][4]')).toBe('x.toAddressMatrix()')
201
+ expect(codegen.ethereumToAsc('x', 'address[1][2]')).toBe('x.toAddressMatrix()')
202
+ expect(codegen.ethereumToAsc('x', 'address[123][321]')).toBe('x.toAddressMatrix()')
203
+
204
+ expect(codegen.ascTypeForEthereum('address[][]')).toBe('Array<Array<Address>>')
205
+ expect(codegen.ascTypeForEthereum('address[5][]')).toBe('Array<Array<Address>>')
206
+ expect(codegen.ascTypeForEthereum('address[][4]')).toBe('Array<Array<Address>>')
207
+ expect(codegen.ascTypeForEthereum('address[1][2]')).toBe('Array<Array<Address>>')
208
+ expect(codegen.ascTypeForEthereum('address[123][321]')).toBe('Array<Array<Address>>')
209
+ })
210
+
211
+ test('bool[*][*] -> Array<Array<boolean>>', () => {
212
+ expect(codegen.ethereumToAsc('x', 'bool[][]')).toBe('x.toBooleanMatrix()')
213
+ expect(codegen.ethereumToAsc('x', 'bool[1][]')).toBe('x.toBooleanMatrix()')
214
+ expect(codegen.ethereumToAsc('x', 'bool[][3]')).toBe('x.toBooleanMatrix()')
215
+ expect(codegen.ethereumToAsc('x', 'bool[5][2]')).toBe('x.toBooleanMatrix()')
216
+ expect(codegen.ethereumToAsc('x', 'bool[275][572]')).toBe('x.toBooleanMatrix()')
217
+
218
+ expect(codegen.ascTypeForEthereum('bool[][]')).toBe('Array<Array<boolean>>')
219
+ expect(codegen.ascTypeForEthereum('bool[1][]')).toBe('Array<Array<boolean>>')
220
+ expect(codegen.ascTypeForEthereum('bool[][3]')).toBe('Array<Array<boolean>>')
221
+ expect(codegen.ascTypeForEthereum('bool[5][2]')).toBe('Array<Array<boolean>>')
222
+ expect(codegen.ascTypeForEthereum('bool[275][572]')).toBe('Array<Array<boolean>>')
223
+ })
224
+
225
+ test('byte[*][*] -> Array<Array<Bytes>>', () => {
226
+ expect(codegen.ethereumToAsc('x', 'byte[][]')).toBe('x.toBytesMatrix()')
227
+ expect(codegen.ethereumToAsc('x', 'byte[7][]')).toBe('x.toBytesMatrix()')
228
+ expect(codegen.ethereumToAsc('x', 'byte[][8]')).toBe('x.toBytesMatrix()')
229
+ expect(codegen.ethereumToAsc('x', 'byte[553][355]')).toBe('x.toBytesMatrix()')
230
+
231
+ expect(codegen.ascTypeForEthereum('byte[][]')).toBe('Array<Array<Bytes>>')
232
+ expect(codegen.ascTypeForEthereum('byte[7][]')).toBe('Array<Array<Bytes>>')
233
+ expect(codegen.ascTypeForEthereum('byte[][8]')).toBe('Array<Array<Bytes>>')
234
+ expect(codegen.ascTypeForEthereum('byte[553][355]')).toBe('Array<Array<Bytes>>')
235
+ })
236
+
237
+ test('bytes[*][*] -> Array<Array<Bytes>>', () => {
238
+ expect(codegen.ethereumToAsc('x', 'bytes[][]')).toBe('x.toBytesMatrix()')
239
+ expect(codegen.ethereumToAsc('x', 'bytes[14][]')).toBe('x.toBytesMatrix()')
240
+ expect(codegen.ethereumToAsc('x', 'bytes[][41]')).toBe('x.toBytesMatrix()')
241
+ expect(codegen.ethereumToAsc('x', 'bytes[444][555]')).toBe('x.toBytesMatrix()')
242
+
243
+ expect(codegen.ascTypeForEthereum('bytes[][]')).toBe('Array<Array<Bytes>>')
244
+ expect(codegen.ascTypeForEthereum('bytes[14][]')).toBe('Array<Array<Bytes>>')
245
+ expect(codegen.ascTypeForEthereum('bytes[][41]')).toBe('Array<Array<Bytes>>')
246
+ expect(codegen.ascTypeForEthereum('bytes[444][555]')).toBe('Array<Array<Bytes>>')
247
+ })
248
+
249
+ test('bytes0[*][*] (invalid)', () => {
250
+ expect(() => codegen.ethereumToAsc('x', 'bytes0[][]')).toThrow()
251
+ expect(() => codegen.ethereumToAsc('x', 'bytes0[83][]')).toThrow()
252
+ expect(() => codegen.ethereumToAsc('x', 'bytes0[][83]')).toThrow()
253
+ expect(() => codegen.ethereumToAsc('x', 'bytes0[123][321]')).toThrow()
254
+
255
+ expect(() => codegen.ascTypeForEthereum('bytes0[][]')).toThrow()
256
+ expect(() => codegen.ascTypeForEthereum('bytes0[83][]')).toThrow()
257
+ expect(() => codegen.ascTypeForEthereum('bytes0[][83]')).toThrow()
258
+ expect(() => codegen.ascTypeForEthereum('bytes0[123][321]')).toThrow()
259
+ })
260
+
261
+ test('bytes1..32[*][*] -> Array<Array<Bytes>>', () => {
262
+ for (let i = 1; i <= 32; i++) {
263
+ expect(codegen.ethereumToAsc('x', `bytes${i}[][]`)).toBe('x.toBytesMatrix()')
264
+ expect(codegen.ethereumToAsc('x', `bytes${i}[7][]`)).toBe('x.toBytesMatrix()')
265
+ expect(codegen.ethereumToAsc('x', `bytes${i}[][7]`)).toBe('x.toBytesMatrix()')
266
+ expect(codegen.ethereumToAsc('x', `bytes${i}[432][234]`)).toBe('x.toBytesMatrix()')
267
+
268
+ expect(codegen.ascTypeForEthereum(`bytes${i}[][]`)).toBe('Array<Array<Bytes>>')
269
+ expect(codegen.ascTypeForEthereum(`bytes${i}[6][]`)).toBe('Array<Array<Bytes>>')
270
+ expect(codegen.ascTypeForEthereum(`bytes${i}[][7]`)).toBe('Array<Array<Bytes>>')
271
+ expect(codegen.ascTypeForEthereum(`bytes${i}[432][234]`)).toBe('Array<Array<Bytes>>')
272
+ }
273
+ })
274
+
275
+ test('bytes33[*][*] (invalid)', () => {
276
+ expect(() => codegen.ethereumToAsc('x', 'bytes33[][]')).toThrow()
277
+ expect(() => codegen.ethereumToAsc('x', 'bytes33[58][]')).toThrow()
278
+ expect(() => codegen.ethereumToAsc('x', 'bytes33[][85]')).toThrow()
279
+ expect(() => codegen.ethereumToAsc('x', 'bytes33[394][493]')).toThrow()
280
+
281
+ expect(() => codegen.ascTypeForEthereum('bytes33[][]')).toThrow()
282
+ expect(() => codegen.ascTypeForEthereum('bytes33[58][]')).toThrow()
283
+ expect(() => codegen.ascTypeForEthereum('bytes33[][85]')).toThrow()
284
+ expect(() => codegen.ascTypeForEthereum('bytes33[394][493]')).toThrow()
285
+ })
286
+
287
+ test('int8..32[*][*], uint8..24[*][*] -> Array<Array<i32>>', () => {
288
+ for (let i = 8; i <= 32; i += 8) {
289
+ expect(codegen.ethereumToAsc('x', `int${i}[][]`)).toBe('x.toI32Matrix()')
290
+ expect(codegen.ethereumToAsc('x', `int${i}[6][]`)).toBe('x.toI32Matrix()')
291
+ expect(codegen.ethereumToAsc('x', `int${i}[][6]`)).toBe('x.toI32Matrix()')
292
+ expect(codegen.ethereumToAsc('x', `int${i}[4638][8364]`)).toBe('x.toI32Matrix()')
293
+
294
+ expect(codegen.ascTypeForEthereum(`int${i}[][]`)).toBe('Array<Array<i32>>')
295
+ expect(codegen.ascTypeForEthereum(`int${i}[6][]`)).toBe('Array<Array<i32>>')
296
+ expect(codegen.ascTypeForEthereum(`int${i}[][6]`)).toBe('Array<Array<i32>>')
297
+ expect(codegen.ascTypeForEthereum(`int${i}[4638][8364]`)).toBe('Array<Array<i32>>')
298
+ }
299
+ for (let i = 8; i <= 24; i += 8) {
300
+ expect(codegen.ethereumToAsc('x', `uint${i}[][]`)).toBe('x.toI32Matrix()')
301
+ expect(codegen.ethereumToAsc('x', `uint${i}[6][]`)).toBe('x.toI32Matrix()')
302
+ expect(codegen.ethereumToAsc('x', `uint${i}[][6]`)).toBe('x.toI32Matrix()')
303
+ expect(codegen.ethereumToAsc('x', `uint${i}[593][395]`)).toBe('x.toI32Matrix()')
304
+
305
+ expect(codegen.ascTypeForEthereum(`uint${i}[][]`)).toBe('Array<Array<i32>>')
306
+ expect(codegen.ascTypeForEthereum(`uint${i}[6][]`)).toBe('Array<Array<i32>>')
307
+ expect(codegen.ascTypeForEthereum(`uint${i}[][6]`)).toBe('Array<Array<i32>>')
308
+ expect(codegen.ascTypeForEthereum(`uint${i}[593][395]`)).toBe('Array<Array<i32>>')
309
+ }
310
+ })
311
+
312
+ test('uint32[*][*] -> Array<Array<BigInt>>', () => {
313
+ expect(codegen.ethereumToAsc('x', `uint32[][]`)).toBe('x.toBigIntMatrix()')
314
+ expect(codegen.ethereumToAsc('x', `uint32[6][]`)).toBe('x.toBigIntMatrix()')
315
+ expect(codegen.ethereumToAsc('x', `uint32[][6]`)).toBe('x.toBigIntMatrix()')
316
+ expect(codegen.ethereumToAsc('x', `uint32[593][395]`)).toBe('x.toBigIntMatrix()')
317
+
318
+ expect(codegen.ascTypeForEthereum(`uint32[][]`)).toBe('Array<Array<BigInt>>')
319
+ expect(codegen.ascTypeForEthereum(`uint32[6][]`)).toBe('Array<Array<BigInt>>')
320
+ expect(codegen.ascTypeForEthereum(`uint32[][5]`)).toBe('Array<Array<BigInt>>')
321
+ expect(codegen.ascTypeForEthereum(`uint32[593][395]`)).toBe('Array<Array<BigInt>>')
322
+ })
323
+
324
+ test('(u)int40..256[*][*] -> Array<Array<BigInt>>', () => {
325
+ for (let i = 40; i <= 256; i += 8) {
326
+ expect(codegen.ethereumToAsc('x', `int${i}[][]`)).toBe('x.toBigIntMatrix()')
327
+ expect(codegen.ethereumToAsc('x', `int${i}[7][]`)).toBe('x.toBigIntMatrix()')
328
+ expect(codegen.ethereumToAsc('x', `int${i}[][7]`)).toBe('x.toBigIntMatrix()')
329
+ expect(codegen.ethereumToAsc('x', `int${i}[6833][3386]`)).toBe('x.toBigIntMatrix()')
330
+
331
+ expect(codegen.ascTypeForEthereum(`int${i}[][]`)).toBe('Array<Array<BigInt>>')
332
+ expect(codegen.ascTypeForEthereum(`int${i}[7][]`)).toBe('Array<Array<BigInt>>')
333
+ expect(codegen.ascTypeForEthereum(`int${i}[][7]`)).toBe('Array<Array<BigInt>>')
334
+ expect(codegen.ascTypeForEthereum(`int${i}[6833][3386]`)).toBe('Array<Array<BigInt>>')
335
+
336
+ expect(codegen.ethereumToAsc('x', `uint${i}[][]`)).toBe('x.toBigIntMatrix()')
337
+ expect(codegen.ethereumToAsc('x', `uint${i}[23][]`)).toBe('x.toBigIntMatrix()')
338
+ expect(codegen.ethereumToAsc('x', `uint${i}[][32]`)).toBe('x.toBigIntMatrix()')
339
+ expect(codegen.ethereumToAsc('x', `uint${i}[467][764]`)).toBe('x.toBigIntMatrix()')
340
+
341
+ expect(codegen.ascTypeForEthereum(`uint${i}[][]`)).toBe('Array<Array<BigInt>>')
342
+ expect(codegen.ascTypeForEthereum(`uint${i}[23][]`)).toBe('Array<Array<BigInt>>')
343
+ expect(codegen.ascTypeForEthereum(`uint${i}[][32]`)).toBe('Array<Array<BigInt>>')
344
+ expect(codegen.ascTypeForEthereum(`uint${i}[467][764]`)).toBe('Array<Array<BigInt>>')
345
+ }
346
+ })
347
+
348
+ test('string[*][*] -> Array<Array<string>>', () => {
349
+ expect(codegen.ethereumToAsc('x', 'string[][]')).toBe('x.toStringMatrix()')
350
+ expect(codegen.ethereumToAsc('x', 'string[4][]')).toBe('x.toStringMatrix()')
351
+ expect(codegen.ethereumToAsc('x', 'string[][3]')).toBe('x.toStringMatrix()')
352
+ expect(codegen.ethereumToAsc('x', 'string[754][457]')).toBe('x.toStringMatrix()')
353
+
354
+ expect(codegen.ascTypeForEthereum('string[][]')).toBe('Array<Array<string>>')
355
+ expect(codegen.ascTypeForEthereum('string[4][]')).toBe('Array<Array<string>>')
356
+ expect(codegen.ascTypeForEthereum('string[][3]')).toBe('Array<Array<string>>')
357
+ expect(codegen.ascTypeForEthereum('string[754][457]')).toBe('Array<Array<string>>')
358
+ })
194
359
  })
195
360
 
196
361
  describe('AssemblyScript -> ethereum.Value', () => {
@@ -409,6 +574,188 @@ describe('AssemblyScript -> ethereum.Value', () => {
409
574
  'ethereum.Value.fromStringArray(x)',
410
575
  )
411
576
  })
577
+
578
+ // Multidimensional arrays
579
+
580
+ test('Array<Array<Address>> -> address[*][*]', () => {
581
+ expect(codegen.ethereumFromAsc('x', 'address[][]')).toBe(
582
+ 'ethereum.Value.fromAddressMatrix(x)',
583
+ )
584
+ expect(codegen.ethereumFromAsc('x', 'address[1][]')).toBe(
585
+ 'ethereum.Value.fromAddressMatrix(x)',
586
+ )
587
+ expect(codegen.ethereumFromAsc('x', 'address[][2]')).toBe(
588
+ 'ethereum.Value.fromAddressMatrix(x)',
589
+ )
590
+ expect(codegen.ethereumFromAsc('x', 'address[123][321]')).toBe(
591
+ 'ethereum.Value.fromAddressMatrix(x)',
592
+ )
593
+ })
594
+
595
+ test('Array<Array<boolean>> -> bool[*][*]', () => {
596
+ expect(codegen.ethereumFromAsc('x', 'bool[][]')).toBe(
597
+ 'ethereum.Value.fromBooleanMatrix(x)',
598
+ )
599
+ expect(codegen.ethereumFromAsc('x', 'bool[5][]')).toBe(
600
+ 'ethereum.Value.fromBooleanMatrix(x)',
601
+ )
602
+ expect(codegen.ethereumFromAsc('x', 'bool[][5]')).toBe(
603
+ 'ethereum.Value.fromBooleanMatrix(x)',
604
+ )
605
+ expect(codegen.ethereumFromAsc('x', 'bool[275][572]')).toBe(
606
+ 'ethereum.Value.fromBooleanMatrix(x)',
607
+ )
608
+ })
609
+
610
+ test('Array<Array<Bytes>> -> byte[*][*]', () => {
611
+ expect(codegen.ethereumFromAsc('x', 'byte[][]')).toBe(
612
+ 'ethereum.Value.fromFixedBytesMatrix(x)',
613
+ )
614
+ expect(codegen.ethereumFromAsc('x', 'byte[7][]')).toBe(
615
+ 'ethereum.Value.fromFixedBytesMatrix(x)',
616
+ )
617
+ expect(codegen.ethereumFromAsc('x', 'byte[][6]')).toBe(
618
+ 'ethereum.Value.fromFixedBytesMatrix(x)',
619
+ )
620
+ expect(codegen.ethereumFromAsc('x', 'byte[553][355]')).toBe(
621
+ 'ethereum.Value.fromFixedBytesMatrix(x)',
622
+ )
623
+ })
624
+
625
+ test('Array<Array<Bytes>> -> bytes[*][*]', () => {
626
+ expect(codegen.ethereumFromAsc('x', 'bytes[][]')).toBe(
627
+ 'ethereum.Value.fromBytesMatrix(x)',
628
+ )
629
+ expect(codegen.ethereumFromAsc('x', 'bytes[14][]')).toBe(
630
+ 'ethereum.Value.fromBytesMatrix(x)',
631
+ )
632
+ expect(codegen.ethereumFromAsc('x', 'bytes[][41]')).toBe(
633
+ 'ethereum.Value.fromBytesMatrix(x)',
634
+ )
635
+ expect(codegen.ethereumFromAsc('x', 'bytes[444][333]')).toBe(
636
+ 'ethereum.Value.fromBytesMatrix(x)',
637
+ )
638
+ })
639
+
640
+ test('bytes0[*][*] (invalid)', () => {
641
+ expect(() => codegen.ethereumFromAsc('x', 'bytes0[][]')).toThrow()
642
+ expect(() => codegen.ethereumFromAsc('x', 'bytes0[83][]')).toThrow()
643
+ expect(() => codegen.ethereumFromAsc('x', 'bytes0[][38]')).toThrow()
644
+ expect(() => codegen.ethereumFromAsc('x', 'bytes0[123][321]')).toThrow()
645
+ })
646
+
647
+ test('Array<Array<Bytes>> -> bytes1..32[*][*]', () => {
648
+ for (let i = 1; i <= 32; i++) {
649
+ expect(codegen.ethereumFromAsc('x', `bytes${i}[][]`)).toBe(
650
+ 'ethereum.Value.fromFixedBytesMatrix(x)',
651
+ )
652
+ expect(codegen.ethereumFromAsc('x', `bytes${i}[7][]`)).toBe(
653
+ 'ethereum.Value.fromFixedBytesMatrix(x)',
654
+ )
655
+ expect(codegen.ethereumFromAsc('x', `bytes${i}[][7]`)).toBe(
656
+ 'ethereum.Value.fromFixedBytesMatrix(x)',
657
+ )
658
+ expect(codegen.ethereumFromAsc('x', `bytes${i}[432][234]`)).toBe(
659
+ 'ethereum.Value.fromFixedBytesMatrix(x)',
660
+ )
661
+ }
662
+ })
663
+
664
+ test('bytes33[*][*] (invalid)', () => {
665
+ expect(() => codegen.ethereumFromAsc('x', 'bytes33[][]')).toThrow()
666
+ expect(() => codegen.ethereumFromAsc('x', 'bytes33[58][]')).toThrow()
667
+ expect(() => codegen.ethereumFromAsc('x', 'bytes33[][85]')).toThrow()
668
+ expect(() => codegen.ethereumFromAsc('x', 'bytes33[394][493]')).toThrow()
669
+ })
670
+
671
+ test('Array<Array<i32>> -> int8..32[*][*], uint8..24[*][*]', () => {
672
+ for (let i = 8; i <= 32; i += 8) {
673
+ expect(codegen.ethereumFromAsc('x', `int${i}[][]`)).toBe(
674
+ 'ethereum.Value.fromI32Matrix(x)',
675
+ )
676
+ expect(codegen.ethereumFromAsc('x', `int${i}[6][]`)).toBe(
677
+ 'ethereum.Value.fromI32Matrix(x)',
678
+ )
679
+ expect(codegen.ethereumFromAsc('x', `int${i}[][5]`)).toBe(
680
+ 'ethereum.Value.fromI32Matrix(x)',
681
+ )
682
+ expect(codegen.ethereumFromAsc('x', `int${i}[4638][8364]`)).toBe(
683
+ 'ethereum.Value.fromI32Matrix(x)',
684
+ )
685
+ }
686
+
687
+ for (let i = 8; i <= 24; i += 8) {
688
+ expect(codegen.ethereumFromAsc('x', `uint${i}[][]`)).toBe(
689
+ 'ethereum.Value.fromI32Matrix(x)',
690
+ )
691
+ expect(codegen.ethereumFromAsc('x', `uint${i}[6][]`)).toBe(
692
+ 'ethereum.Value.fromI32Matrix(x)',
693
+ )
694
+ expect(codegen.ethereumFromAsc('x', `uint${i}[][5]`)).toBe(
695
+ 'ethereum.Value.fromI32Matrix(x)',
696
+ )
697
+ expect(codegen.ethereumFromAsc('x', `uint${i}[593][395]`)).toBe(
698
+ 'ethereum.Value.fromI32Matrix(x)',
699
+ )
700
+ }
701
+ })
702
+
703
+ test('Array<Array<BigInt>> -> uint32[*][*]', () => {
704
+ expect(codegen.ethereumFromAsc('x', `uint32[][]`)).toBe(
705
+ 'ethereum.Value.fromUnsignedBigIntMatrix(x)',
706
+ )
707
+ expect(codegen.ethereumFromAsc('x', `uint32[6][]`)).toBe(
708
+ 'ethereum.Value.fromUnsignedBigIntMatrix(x)',
709
+ )
710
+ expect(codegen.ethereumFromAsc('x', `uint32[][5]`)).toBe(
711
+ 'ethereum.Value.fromUnsignedBigIntMatrix(x)',
712
+ )
713
+ expect(codegen.ethereumFromAsc('x', `uint32[593][395]`)).toBe(
714
+ 'ethereum.Value.fromUnsignedBigIntMatrix(x)',
715
+ )
716
+ })
717
+
718
+ test('Array<Array<BigInt>> -> (u)int40..256[*][*]', () => {
719
+ for (let i = 40; i <= 256; i += 8) {
720
+ expect(codegen.ethereumFromAsc('x', `int${i}[][]`)).toBe(
721
+ 'ethereum.Value.fromSignedBigIntMatrix(x)',
722
+ )
723
+ expect(codegen.ethereumFromAsc('x', `int${i}[8][]`)).toBe(
724
+ 'ethereum.Value.fromSignedBigIntMatrix(x)',
725
+ )
726
+ expect(codegen.ethereumFromAsc('x', `int${i}[][7]`)).toBe(
727
+ 'ethereum.Value.fromSignedBigIntMatrix(x)',
728
+ )
729
+ expect(codegen.ethereumFromAsc('x', `int${i}[6833][3386]`)).toBe(
730
+ 'ethereum.Value.fromSignedBigIntMatrix(x)',
731
+ )
732
+
733
+ expect(codegen.ethereumFromAsc('x', `uint${i}[][]`)).toBe(
734
+ 'ethereum.Value.fromUnsignedBigIntMatrix(x)',
735
+ )
736
+ expect(codegen.ethereumFromAsc('x', `uint${i}[23][]`)).toBe(
737
+ 'ethereum.Value.fromUnsignedBigIntMatrix(x)',
738
+ )
739
+ expect(codegen.ethereumFromAsc('x', `uint${i}[][32]`)).toBe(
740
+ 'ethereum.Value.fromUnsignedBigIntMatrix(x)',
741
+ )
742
+ expect(codegen.ethereumFromAsc('x', `uint${i}[467][764]`)).toBe(
743
+ 'ethereum.Value.fromUnsignedBigIntMatrix(x)',
744
+ )
745
+ }
746
+ })
747
+
748
+ test('Array<Array<String>> -> string[*][*]', () => {
749
+ expect(codegen.ethereumFromAsc('x', 'string[]')).toBe(
750
+ 'ethereum.Value.fromStringArray(x)',
751
+ )
752
+ expect(codegen.ethereumFromAsc('x', 'string[4]')).toBe(
753
+ 'ethereum.Value.fromStringArray(x)',
754
+ )
755
+ expect(codegen.ethereumFromAsc('x', 'string[754]')).toBe(
756
+ 'ethereum.Value.fromStringArray(x)',
757
+ )
758
+ })
412
759
  })
413
760
 
414
761
  describe('Value -> AssemblyScript', () => {
@@ -60,6 +60,9 @@ const getEtherscanLikeAPIUrl = (network) => {
60
60
  case "aurora-testnet": return `https://api-testnet.aurorascan.dev/api`
61
61
  case "optimism-kovan": return `https://api-kovan-optimistic.etherscan.io/api`
62
62
  case "optimism": return `https://api-optimistic.etherscan.io/api`
63
+ case "moonbeam": return `https://api-moonbeam.moonscan.io/api`
64
+ case "moonriver": return `https://api-moonriver.moonscan.io/api`
65
+ case "mbase": return `https://api-moonbase.moonscan.io/api`
63
66
  case "avalanche": return `https://api.snowtrace.io/api`;
64
67
  case "fuji": return `https://api-testnet.snowtrace.io/api`;
65
68
  default: return `https://api-${network}.etherscan.io/api`
@@ -3,12 +3,16 @@ const toolbox = require('gluegun/toolbox')
3
3
 
4
4
  const createJsonRpcClient = url => {
5
5
  let params = {
6
- auth: url.auth,
7
6
  host: url.hostname,
8
7
  port: url.port,
9
8
  path: url.pathname,
10
9
  }
11
10
 
11
+ // username may be empty
12
+ if (url.password) {
13
+ params.auth = `${url.username}:${url.password}`
14
+ }
15
+
12
16
  if (url.protocol === 'https:') {
13
17
  return jayson.Client.https(params)
14
18
  } else if (url.protocol === 'http:') {
@@ -7,10 +7,17 @@ const { step } = require('./spinner')
7
7
  const Scaffold = require('../scaffold')
8
8
  const { generateEventIndexingHandlers } = require('../scaffold/mapping')
9
9
  const { generateEventType, abiEvents } = require('../scaffold/schema')
10
+ const { generateTestsFiles } = require('../scaffold/tests')
10
11
  const { strings } = require('gluegun')
11
12
  const { Map } = require('immutable')
12
13
 
13
- const generateDataSource = async (protocol, contractName, network, contractAddress, abi) => {
14
+ const generateDataSource = async (
15
+ protocol,
16
+ contractName,
17
+ network,
18
+ contractAddress,
19
+ abi,
20
+ ) => {
14
21
  const protocolManifest = protocol.getManifestScaffold()
15
22
 
16
23
  return Map.of(
@@ -89,13 +96,13 @@ const writeABI = async (abi, contractName) => {
89
96
 
90
97
  const writeSchema = async (abi, protocol, schemaPath, entities) => {
91
98
  const events = protocol.hasEvents()
92
- ? abiEvents(abi).filter(event => entities.indexOf(event.get('name')) === -1).toJS()
99
+ ? abiEvents(abi)
100
+ .filter(event => entities.indexOf(event.get('name')) === -1)
101
+ .toJS()
93
102
  : []
94
103
 
95
104
  let data = prettier.format(
96
- events.map(
97
- event => generateEventType(event, protocol.name)
98
- ).join('\n\n'),
105
+ events.map(event => generateEventType(event, protocol.name)).join('\n\n'),
99
106
  {
100
107
  parser: 'graphql',
101
108
  },
@@ -106,18 +113,39 @@ const writeSchema = async (abi, protocol, schemaPath, entities) => {
106
113
 
107
114
  const writeMapping = async (abi, protocol, contractName, entities) => {
108
115
  const events = protocol.hasEvents()
109
- ? abiEvents(abi).filter(event => entities.indexOf(event.get('name')) === -1).toJS()
116
+ ? abiEvents(abi)
117
+ .filter(event => entities.indexOf(event.get('name')) === -1)
118
+ .toJS()
110
119
  : []
111
120
 
112
- let mapping = prettier.format(
113
- generateEventIndexingHandlers(
114
- events,
115
- contractName,
116
- ),
117
- { parser: 'typescript', semi: false },
118
- )
121
+ let mapping = prettier.format(generateEventIndexingHandlers(events, contractName), {
122
+ parser: 'typescript',
123
+ semi: false,
124
+ })
125
+
126
+ await fs.writeFile(`./src/${strings.kebabCase(contractName)}.ts`, mapping, {
127
+ encoding: 'utf-8',
128
+ })
129
+ }
119
130
 
120
- await fs.writeFile(`./src/${strings.kebabCase(contractName)}.ts`, mapping, { encoding: 'utf-8' })
131
+ const writeTestsFiles = async (abi, protocol, contractName) => {
132
+ const hasEvents = protocol.hasEvents()
133
+ const events = hasEvents
134
+ ? abiEvents(abi).toJS()
135
+ : []
136
+
137
+ if(events.length > 0) {
138
+ // If a contract is added to a subgraph that has no tests folder
139
+ await fs.ensureDir('./tests/')
140
+
141
+ const testsFiles = generateTestsFiles(contractName, events, true)
142
+
143
+ for (const [fileName, content] of Object.entries(testsFiles)) {
144
+ await fs.writeFile(`./tests/${fileName}`, content, {
145
+ encoding: 'utf-8',
146
+ })
147
+ }
148
+ }
121
149
  }
122
150
 
123
151
  module.exports = {
@@ -128,4 +156,5 @@ module.exports = {
128
156
  writeABI,
129
157
  writeSchema,
130
158
  writeMapping,
159
+ writeTestsFiles,
131
160
  }
@@ -1,4 +1,4 @@
1
- const allowedStudioNetworks = ['mainnet', 'rinkeby']
1
+ const allowedStudioNetworks = ['mainnet', 'rinkeby', 'goerli']
2
2
 
3
3
  const validateStudioNetwork = ({ studio, product, network }) => {
4
4
  let isStudio = studio || product === 'subgraph-studio'
@@ -5,7 +5,7 @@ const { withSpinner } = require('../command-helpers/spinner')
5
5
  const Subgraph = require('../subgraph')
6
6
  const Protocol = require('../protocols')
7
7
  const DataSourcesExtractor = require('../command-helpers/data-sources')
8
- const { generateDataSource, writeABI, writeSchema, writeMapping } = require('../command-helpers/scaffold')
8
+ const { generateDataSource, writeABI, writeSchema, writeMapping, writeTestsFiles } = require('../command-helpers/scaffold')
9
9
  const { loadAbiFromEtherscan, loadAbiFromBlockScout } = require('../command-helpers/abi')
10
10
  const EthereumABI = require('../protocols/ethereum/abi')
11
11
  const { fixParameters } = require('../command-helpers/gluegun')
@@ -102,6 +102,7 @@ module.exports = {
102
102
  await writeABI(ethabi, contractName)
103
103
  await writeSchema(ethabi, protocol, result.getIn(['schema', 'file']), collisionEntities)
104
104
  await writeMapping(ethabi, protocol, contractName, collisionEntities)
105
+ await writeTestsFiles(ethabi, protocol, contractName)
105
106
 
106
107
  let dataSources = result.get('dataSources')
107
108
  let dataSource = await generateDataSource(protocol,
@@ -827,7 +827,7 @@ const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
827
827
  if (addContractConfirmation) {
828
828
  let abiFromFile
829
829
  let ProtocolContract = protocolInstance.getContract()
830
-
830
+
831
831
  let questions = [
832
832
  {
833
833
  type: 'input',
@@ -866,16 +866,16 @@ const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
866
866
 
867
867
  // Get the cwd before process.chdir in order to switch back in the end of command execution
868
868
  const cwd = process.cwd();
869
-
869
+
870
870
  try {
871
871
  let { abi, contract, contractName } = await toolbox.prompt.ask(questions)
872
-
872
+
873
873
  if (fs.existsSync(directory)) {
874
874
  process.chdir(directory)
875
875
  }
876
-
876
+
877
877
  let commandLine = ['add', contract, '--contract-name', contractName]
878
-
878
+
879
879
  if (abiFromFile) {
880
880
  if (abi.includes(directory)) {
881
881
  commandLine.push('--abi', path.normalize(abi.replace(directory, '')))
@@ -895,4 +895,4 @@ const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
895
895
  }
896
896
 
897
897
  return addContractConfirmation
898
- }
898
+ }
@@ -168,7 +168,7 @@ async function getPlatform(logsOpt) {
168
168
  const type = os.type()
169
169
  const arch = os.arch()
170
170
  const cpuCore = os.cpus()[0]
171
- const isM1 = (arch === 'arm64' && /Apple (M1|processor)/.test(cpuCore.model))
171
+ const isAppleSilicon = (arch === 'arm64' && /Apple (M1|M2|processor)/.test(cpuCore.model))
172
172
  const linuxInfo = type === 'Linux' ? await getLinuxInfo() : {}
173
173
  const linuxDistro = linuxInfo.name
174
174
  const release = linuxInfo.version || os.release()
@@ -178,13 +178,11 @@ async function getPlatform(logsOpt) {
178
178
  print.info(`OS type: ${linuxDistro || type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
179
179
  }
180
180
 
181
- if (arch === 'x64' || isM1) {
181
+ if (arch === 'x64' || isAppleSilicon) {
182
182
  if (type === 'Darwin') {
183
- if (majorVersion === 19) {
184
- return 'binary-macos-10.15'
185
- } else if (majorVersion === 18) {
186
- return 'binary-macos-10.14'
187
- } else if (isM1) {
183
+ if (majorVersion === 18 || majorVersion === 19) {
184
+ return 'binary-macos-10.15' // GitHub dropped support for macOS 10.14 in Actions, but it seems 10.15 binary works on 10.14 too
185
+ } else if (isAppleSilicon) {
188
186
  return 'binary-macos-11-m1'
189
187
  }
190
188
  return 'binary-macos-11'
@@ -196,8 +194,6 @@ async function getPlatform(logsOpt) {
196
194
  } else {
197
195
  return 'binary-linux-20'
198
196
  }
199
- } else if (type === 'Windows_NT') {
200
- return 'binary-windows'
201
197
  }
202
198
  }
203
199
 
@@ -19,7 +19,7 @@ module.exports = {
19
19
  return 'graph-ts dependency not installed yet'
20
20
  }
21
21
 
22
- let manifest = loadManifest(manifestFile)
22
+ let manifest = await loadManifest(manifestFile)
23
23
  return (
24
24
  // Only migrate if the graph-ts version is >= 0.22.0...
25
25
  // Coerce needed because we may be dealing with an alpha version
@@ -19,7 +19,7 @@ module.exports = {
19
19
  return 'graph-ts dependency not installed yet'
20
20
  }
21
21
 
22
- let manifest = loadManifest(manifestFile)
22
+ let manifest = await loadManifest(manifestFile)
23
23
  return (
24
24
  // Only migrate if the graph-ts version is >= 0.24.0...
25
25
  // Coerce needed because we may be dealing with an alpha version
@@ -42,9 +42,7 @@ module.exports = class Protocol {
42
42
  arweave: ['arweave-mainnet'],
43
43
  ethereum: [
44
44
  'mainnet',
45
- 'kovan',
46
45
  'rinkeby',
47
- 'ropsten',
48
46
  'goerli',
49
47
  'poa-core',
50
48
  'poa-sokol',
@@ -74,9 +72,11 @@ module.exports = class Protocol {
74
72
  near: ['near-mainnet', 'near-testnet'],
75
73
  cosmos: [
76
74
  'cosmoshub-4',
77
- 'theta-testnet-001',
75
+ 'theta-testnet-001', // CosmosHub testnet
78
76
  'osmosis-1',
79
- 'osmo-test-4'
77
+ 'osmo-test-4', // Osmosis testnet
78
+ 'juno-1',
79
+ 'uni-3' // Juno testnet
80
80
  ],
81
81
  })
82
82
  }
@@ -0,0 +1,40 @@
1
+ const tsCodegen = require('../../../codegen/typescript')
2
+
3
+ module.exports = class IpfsFileTemplateCodeGen {
4
+ constructor(template) {
5
+ this.template = template
6
+ }
7
+
8
+ generateModuleImports() {
9
+ return []
10
+ }
11
+
12
+ generateCreateMethod() {
13
+ const name = this.template.get('name')
14
+
15
+ return tsCodegen.staticMethod(
16
+ 'create',
17
+ [tsCodegen.param('cid', tsCodegen.namedType('string'))],
18
+ tsCodegen.namedType('void'),
19
+ `
20
+ DataSourceTemplate.create('${name}', [cid])
21
+ `,
22
+ )
23
+ }
24
+
25
+ generateCreateWithContextMethod() {
26
+ const name = this.template.get('name')
27
+
28
+ return tsCodegen.staticMethod(
29
+ 'createWithContext',
30
+ [
31
+ tsCodegen.param('cid', tsCodegen.namedType('string')),
32
+ tsCodegen.param('context', tsCodegen.namedType('DataSourceContext')),
33
+ ],
34
+ tsCodegen.namedType('void'),
35
+ `
36
+ DataSourceTemplate.createWithContext('${name}', [cid], context)
37
+ `,
38
+ )
39
+ }
40
+ }