From a9300ddc8fa11561e4e5a48328170f7780663d0a Mon Sep 17 00:00:00 2001 From: kyscott18 <43524469+kyscott18@users.noreply.github.com> Date: Sat, 2 Mar 2024 17:49:08 -0500 Subject: [PATCH] Fixes regex for fallback signatures (#229) --- .changeset/poor-garlics-invite.md | 5 +++++ packages/abitype/src/human-readable/parseAbiItem.test.ts | 6 ++++++ .../abitype/src/human-readable/runtime/signatures.test.ts | 8 +++++++- packages/abitype/src/human-readable/runtime/signatures.ts | 5 +++-- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 .changeset/poor-garlics-invite.md diff --git a/.changeset/poor-garlics-invite.md b/.changeset/poor-garlics-invite.md new file mode 100644 index 00000000..2167f120 --- /dev/null +++ b/.changeset/poor-garlics-invite.md @@ -0,0 +1,5 @@ +--- +"abitype": patch +--- + +Fixed regex for fallback signatures. diff --git a/packages/abitype/src/human-readable/parseAbiItem.test.ts b/packages/abitype/src/human-readable/parseAbiItem.test.ts index 2d548bd9..61ca81d8 100644 --- a/packages/abitype/src/human-readable/parseAbiItem.test.ts +++ b/packages/abitype/src/human-readable/parseAbiItem.test.ts @@ -61,6 +61,12 @@ test.each([ ], }, }, + { + signature: ['fallback() external'], + expected: { + type: 'fallback', + }, + }, ])('parseAbiItem($signature)', ({ signature, expected }) => { expect(parseAbiItem(signature)).toEqual(expected) }) diff --git a/packages/abitype/src/human-readable/runtime/signatures.test.ts b/packages/abitype/src/human-readable/runtime/signatures.test.ts index f19d921b..324b5f09 100644 --- a/packages/abitype/src/human-readable/runtime/signatures.test.ts +++ b/packages/abitype/src/human-readable/runtime/signatures.test.ts @@ -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', ) diff --git a/packages/abitype/src/human-readable/runtime/signatures.ts b/packages/abitype/src/human-readable/runtime/signatures.ts index 4136cbb3..3f8fc462 100644 --- a/packages/abitype/src/human-readable/runtime/signatures.ts +++ b/packages/abitype/src/human-readable/runtime/signatures.ts @@ -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(?payable{1}))?$/ export function isFallbackSignature(signature: string) { return fallbackSignatureRegex.test(signature) }