Skip to content

Commit 494ecc5

Browse files
committed
codegen: Add test for functions with tuple array results
1 parent 37877a3 commit 494ecc5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/codegen/abi.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ describe('ABI code generation', () => {
9999
stateMutability: 'view',
100100
type: 'function',
101101
},
102+
{
103+
type: 'function',
104+
stateMutability: 'view',
105+
payable: 'false',
106+
name: 'getProposals',
107+
outputs: [
108+
{
109+
type: 'uint256',
110+
name: 'size',
111+
},
112+
{
113+
type: 'tuple[]',
114+
components: [
115+
{ name: 'first', type: 'uint256' },
116+
{ name: 'second', type: 'string' },
117+
],
118+
},
119+
],
120+
},
102121
{
103122
type: 'function',
104123
stateMutability: 'view',
@@ -165,6 +184,8 @@ describe('ABI code generation', () => {
165184
'Contract__getProposalResultValue0Struct',
166185
'Contract__getProposalInputParam1Struct',
167186
'Contract__getProposalInputParam1BarStruct',
187+
'Contract__getProposalsResultValue1Struct',
188+
'Contract__getProposalsResult',
168189
'Contract',
169190
])
170191
})
@@ -212,6 +233,8 @@ describe('ABI code generation', () => {
212233
ts.param('param1', 'Contract__getProposalInputParam1Struct'),
213234
]),
214235
],
236+
['getProposals', immutable.List()],
237+
['try_getProposals', immutable.List()],
215238
['overloaded', immutable.List([ts.param('param0', 'string')])],
216239
['try_overloaded', immutable.List([ts.param('param0', 'string')])],
217240
['overloaded1', immutable.List([ts.param('param0', 'BigInt')])],
@@ -232,6 +255,8 @@ describe('ABI code generation', () => {
232255
'try_getProposal',
233256
'ethereum.CallResult<Contract__getProposalResultValue0Struct>',
234257
],
258+
['getProposals', ts.namedType('Contract__getProposalsResult')],
259+
['try_getProposals', 'ethereum.CallResult<Contract__getProposalsResult>'],
235260
['overloaded', ts.namedType('string')],
236261
['try_overloaded', 'ethereum.CallResult<string>'],
237262
['overloaded1', ts.namedType('string')],
@@ -295,5 +320,15 @@ describe('ABI code generation', () => {
295320
['get noCount', 'BigInt'],
296321
])
297322
})
323+
324+
test('Function bodies are generated correctly for tuple arrays', () => {
325+
let contract = generatedTypes.find(type => type.name === 'Contract')
326+
let getter = contract.methods.find(method => method.name === 'getProposals')
327+
328+
expect(getter.body).not.toContain('toTupleArray<undefined>')
329+
expect(getter.body).toContain(
330+
'result[1].toTupleArray<Contract__getProposalsResultValue1Struct>()',
331+
)
332+
})
298333
})
299334
})

0 commit comments

Comments
 (0)