Skip to content

Commit

Permalink
Fixes regex for fallback signatures (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyscott18 authored Mar 2, 2024
1 parent 3798068 commit a9300dd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-garlics-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"abitype": patch
---

Fixed regex for fallback signatures.
6 changes: 6 additions & 0 deletions packages/abitype/src/human-readable/parseAbiItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ test.each([
],
},
},
{
signature: ['fallback() external'],
expected: {
type: 'fallback',
},
},
])('parseAbiItem($signature)', ({ signature, expected }) => {
expect(parseAbiItem(signature)).toEqual(expected)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ test('execConstructorSignature', () => {
})

test('isFallbackSignature', () => {
expect(isFallbackSignature('fallback()')).toMatchInlineSnapshot('true')
expect(isFallbackSignature('fallback() external')).toMatchInlineSnapshot(
'true',
)
expect(
isFallbackSignature('fallback() external payable'),
).toMatchInlineSnapshot('true')

expect(isFallbackSignature('function name(string)')).toMatchInlineSnapshot(
'false',
)
Expand Down
5 changes: 3 additions & 2 deletions packages/abitype/src/human-readable/runtime/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ export function execConstructorSignature(signature: string) {
}>(constructorSignatureRegex, signature)
}

// https://regexr.com/78u18
const fallbackSignatureRegex = /^fallback\(\)$/
// https://regexr.com/7srtn
const fallbackSignatureRegex =
/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/
export function isFallbackSignature(signature: string) {
return fallbackSignatureRegex.test(signature)
}
Expand Down

0 comments on commit a9300dd

Please sign in to comment.