From 93d87a8c6912b87ed8dbdce0e1b4d2765bc1df39 Mon Sep 17 00:00:00 2001 From: Yaro Shkvorets Date: Tue, 7 Jan 2025 19:44:52 -0500 Subject: [PATCH] Fix init for events with 2d arrays as params (#1884) * fix tests generation for [][] event params * changeset --- .changeset/quick-zoos-brake.md | 5 +++++ packages/cli/src/scaffold/tests.ts | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/quick-zoos-brake.md diff --git a/.changeset/quick-zoos-brake.md b/.changeset/quick-zoos-brake.md new file mode 100644 index 000000000..0dbd96777 --- /dev/null +++ b/.changeset/quick-zoos-brake.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +`graph init`: fix tests generation for events with [][] params #1878 diff --git a/packages/cli/src/scaffold/tests.ts b/packages/cli/src/scaffold/tests.ts index 4f88ba5c1..2434dab38 100644 --- a/packages/cli/src/scaffold/tests.ts +++ b/packages/cli/src/scaffold/tests.ts @@ -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, Array> -> 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 = (