Skip to content

Commit 135f6ce

Browse files
dk1akrzkaczor
andauthoredNov 27, 2021
Fix structName for nested array of struct (#560)
Co-authored-by: Kris Kaczor <chris@kaczor.io>
1 parent ef4ffe6 commit 135f6ce

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed
 

Diff for: ‎.changeset/silver-foxes-remember.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"typechain": patch
3+
---
4+
5+
Fix `structName` for nested array of struct

Diff for: ‎packages/typechain/src/parser/parseEvmType.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ export function extractStructNameIfAvailable(internalType: string | undefined):
131131
if (internalType?.startsWith('struct ')) {
132132
// get rid of "struct " in the beginning
133133
let nameStr = internalType.slice(7)
134-
// get rid of the array sign at the end
135-
const arrayMarker = nameStr.match(/(\[\d*\])$/)?.[1]
134+
// get rid of all array signs at the end
135+
const arrayMarker = nameStr.match(/((?:\[\d*\])+)$/)?.[1]
136136
if (arrayMarker) {
137137
nameStr = nameStr.slice(0, nameStr.length - arrayMarker.length)
138138
}

Diff for: ‎packages/typechain/test/parser/parseEvmType.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,34 @@ describe('parseEvmType function', () => {
134134
})
135135
})
136136

137+
it('parses struct nested array', () => {
138+
const parsedType = parseEvmType(
139+
'tuple[][]',
140+
[
141+
{ name: 'target', type: { type: 'address', originalType: 'address' } },
142+
{ name: 'callData', type: { type: 'dynamic-bytes', originalType: 'bytes' } },
143+
],
144+
'struct Multicall.Call[][]',
145+
)
146+
expect(parsedType).toEqual({
147+
type: 'array',
148+
itemType: {
149+
type: 'array',
150+
itemType: {
151+
type: 'tuple',
152+
components: [
153+
{ name: 'target', type: { type: 'address', originalType: 'address' } },
154+
{ name: 'callData', type: { type: 'dynamic-bytes', originalType: 'bytes' } },
155+
],
156+
originalType: 'tuple',
157+
},
158+
originalType: 'tuple[]',
159+
},
160+
originalType: 'tuple[][]',
161+
structName: 'Call',
162+
})
163+
})
164+
137165
it('parses constant size struct arrays', () => {
138166
const actual = parseEvmType(
139167
'tuple[2]',

0 commit comments

Comments
 (0)
Please sign in to comment.