Skip to content

Commit

Permalink
Fix formatAbiItem (#254)
Browse files Browse the repository at this point in the history
* fix: don't throw if  are undefined

* tests: test-case to demonstrate

* refactor: format

* chore: tweaks

---------

Co-authored-by: Tom Meagher <tom@meagher.co>
  • Loading branch information
catalyst17 and tmm authored Dec 3, 2024
1 parent f417a23 commit 473abee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/abitype/src/human-readable/formatAbiItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ test.each([
} as const,
expected: 'receive() external payable',
},
{
abiItem: {
type: 'function',
name: 'initWormhole',
inputs: [
{
type: 'tuple[]',
name: 'configs',
components: [
{
type: 'uint256',
name: 'chainId',
},
{
type: 'uint16',
name: 'wormholeChainId',
},
],
},
],
outputs: [],
stateMutability: 'nonpayable',
} as const,
expected:
'function initWormhole((uint256 chainId, uint16 wormholeChainId)[] configs)',
},
])('formatAbiItem($expected)', ({ abiItem, expected }) => {
expect(formatAbiItem(abiItem)).toEqual(expected)
})
2 changes: 1 addition & 1 deletion packages/abitype/src/human-readable/formatAbiItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function formatAbiItem<const abiItem extends Abi[number]>(
? ` ${abiItem.stateMutability}`
: ''
}${
abiItem.outputs.length
abiItem.outputs?.length
? ` returns (${formatAbiParameters(abiItem.outputs as Params)})`
: ''
}`
Expand Down

0 comments on commit 473abee

Please sign in to comment.