-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parse abi item fallback parsing (#261)
* fix: parse abi item fallback parsing * ci: apply automated fixes * refactor: extract parse signature functions, and test them * chore: tweaks * chore: tweaks * Update .changeset/red-turtles-refuse.md --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Tom Meagher <[email protected]>
- Loading branch information
1 parent
eed89ed
commit 889e85d
Showing
10 changed files
with
307 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"abitype": patch | ||
--- | ||
|
||
Fixed `parseAbiItem` fallback signature parsing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { expect, test } from 'vitest' | ||
import { formatAbiItem } from './formatAbiItem.js' | ||
import { parseAbiItem } from './parseAbiItem.js' | ||
|
||
test.each([ | ||
{ | ||
type: 'fallback', | ||
stateMutability: 'payable', | ||
} as const, | ||
{ | ||
type: 'fallback', | ||
stateMutability: 'nonpayable', | ||
} as const, | ||
{ | ||
type: 'receive', | ||
stateMutability: 'payable', | ||
} as const, | ||
{ | ||
type: 'function', | ||
name: 'foo', | ||
inputs: [{ type: 'string' }], | ||
outputs: [], | ||
stateMutability: 'nonpayable', | ||
} as const, | ||
{ | ||
type: 'event', | ||
name: 'Foo', | ||
inputs: [ | ||
{ type: 'address', name: 'from', indexed: true }, | ||
{ type: 'address', name: 'to', indexed: true }, | ||
{ type: 'uint256', name: 'amount' }, | ||
], | ||
} as const, | ||
{ | ||
type: 'constructor', | ||
stateMutability: 'nonpayable', | ||
inputs: [{ type: 'string' }], | ||
} as const, | ||
{ | ||
type: 'constructor', | ||
stateMutability: 'payable', | ||
inputs: [{ type: 'string' }], | ||
} as const, | ||
{ | ||
type: 'function', | ||
name: 'initWormhole', | ||
inputs: [ | ||
{ | ||
type: 'tuple[]', | ||
name: 'configs', | ||
components: [ | ||
{ | ||
type: 'uint256', | ||
name: 'chainId', | ||
}, | ||
{ | ||
type: 'uint16', | ||
name: 'wormholeChainId', | ||
}, | ||
], | ||
}, | ||
], | ||
outputs: [], | ||
stateMutability: 'nonpayable', | ||
} as const, | ||
])('use of parseAbiItem - formatAbiItem should be reversible', (abiItem) => { | ||
expect(parseAbiItem(formatAbiItem(abiItem))).toEqual(abiItem) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,11 @@ import { | |
isSolidityType, | ||
isValidDataLocation, | ||
parseAbiParameter, | ||
parseConstructorSignature, | ||
parseErrorSignature, | ||
parseEventSignature, | ||
parseFallbackSignature, | ||
parseFunctionSignature, | ||
parseSignature, | ||
splitParameters, | ||
} from './utils.js' | ||
|
@@ -93,6 +98,20 @@ test.each([ | |
stateMutability: 'payable', | ||
}, | ||
}, | ||
{ | ||
signature: 'fallback() external payable', | ||
expected: { | ||
type: 'fallback', | ||
stateMutability: 'payable', | ||
}, | ||
}, | ||
{ | ||
signature: 'fallback() external', | ||
expected: { | ||
type: 'fallback', | ||
stateMutability: 'nonpayable', | ||
}, | ||
}, | ||
])('parseSignature($signature)', ({ signature, expected }) => { | ||
expect(parseSignature(signature)).toEqual(expected) | ||
}) | ||
|
@@ -154,12 +173,56 @@ test('invalid signature', () => { | |
) | ||
|
||
expect(() => | ||
parseSignature('method foo_(string)'), | ||
parseFunctionSignature('function foo() invalid'), | ||
).toThrowErrorMatchingInlineSnapshot( | ||
` | ||
[UnknownSignatureError: Unknown signature. | ||
[InvalidSignatureError: Invalid function signature. | ||
Details: function foo() invalid | ||
Version: [email protected]] | ||
`, | ||
) | ||
|
||
expect(() => | ||
parseEventSignature('event Foo(string memory foo) invalid'), | ||
).toThrowErrorMatchingInlineSnapshot( | ||
` | ||
[InvalidSignatureError: Invalid event signature. | ||
Details: event Foo(string memory foo) invalid | ||
Version: [email protected]] | ||
`, | ||
) | ||
|
||
expect(() => { | ||
parseErrorSignature('error Foo(string memory foo) invalid') | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
` | ||
[InvalidSignatureError: Invalid error signature. | ||
Details: error Foo(string memory foo) invalid | ||
Version: [email protected]] | ||
`, | ||
) | ||
|
||
expect(() => { | ||
parseConstructorSignature('constructor() invalid') | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
` | ||
[InvalidSignatureError: Invalid constructor signature. | ||
Details: constructor() invalid | ||
Version: [email protected]] | ||
`, | ||
) | ||
|
||
expect(() => { | ||
parseFallbackSignature('fallback() external invalid') | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
` | ||
[InvalidSignatureError: Invalid fallback signature. | ||
Details: method foo_(string) | ||
Details: fallback() external invalid | ||
Version: [email protected]] | ||
`, | ||
) | ||
|
Oops, something went wrong.