Skip to content

Commit

Permalink
Fix init for events with 2d arrays as params (#1884)
Browse files Browse the repository at this point in the history
* fix tests generation for [][] event params

* changeset
  • Loading branch information
YaroShkvorets authored Jan 8, 2025
1 parent e085e39 commit 93d87a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/quick-zoos-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

`graph init`: fix tests generation for events with [][] params #1878
8 changes: 7 additions & 1 deletion packages/cli/src/scaffold/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ const isNativeType = (type: string) => {
return natives.some(rx => rx.test(type));
};

const fetchArrayInnerType = (type: string) => type.match(/Array<(.*?)>/);
// get inner type: Array<T> -> T, Array<Array<T>> -> T
const fetchArrayInnerType = (type: string): RegExpMatchArray | null => {
const match = type.match(/Array<(.+)>/);
if (!match) return null;

return fetchArrayInnerType(match[1]) || match;
};

// Generates the example test.ts file
const generateExampleTest = (
Expand Down

0 comments on commit 93d87a8

Please sign in to comment.