refactor: abi err msg parse#388
Closed
wenyuanhust wants to merge 1 commit intosynapseweb3:mainfrom
Closed
Conversation
blckngm
reviewed
Dec 5, 2023
| } | ||
|
|
||
| pub fn convert_abi_err<T: ToString>(err: T) -> Error { | ||
| Error::other_error(parse_abi_err_data(&err.to_string())) |
Contributor
There was a problem hiding this comment.
The error may not be a call revert error
blckngm
reviewed
Dec 5, 2023
| let err = parse_abi_err_data(err_string); | ||
| assert_eq!( | ||
| err, | ||
| "parse_abi_err_data: unknown exception method 18c379a0!" |
Contributor
There was a problem hiding this comment.
Data should be retained when we cannot decode it.
blckngm
reviewed
Dec 5, 2023
| fn test_sol_invalid_data() { | ||
| let err_string = "Contract call reverted with data: 0x08c379a00000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000001c74657374206661696c656420746f2063726561746520636c69656e7400000000"; | ||
| let err = parse_abi_err_data(err_string); | ||
| assert_eq!(err, "parse_abi_err_data decode: InvalidData, data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1c, 74, 65, 73, 74, 20, 66, 61, 69, 6c, 65, 64, 20, 74, 6f, 20, 63, 72, 65, 61, 74, 65, 20, 63, 6c, 69, 65, 6e, 74, 0, 0, 0, 0]!"); |
Contributor
There was a problem hiding this comment.
Data should be retained (in hex) when we cannot decode it.
blckngm
reviewed
Dec 5, 2023
| let result = strings.join(";"); | ||
| if error_type == AbiErrorType::Panic { | ||
| let panic_error = parse_panic_error(&result); | ||
| handle_panic_error(panic_error) |
Contributor
There was a problem hiding this comment.
Shouldn't be necessary to convert the token to hex again.
Contributor
|
See #390 where I tried to address the aforementioned problems. |
blckngm
reviewed
Dec 5, 2023
| let start_index = "Contract call reverted with data: 0x".len(); | ||
| let method_signature_len = "08c379a0".len(); | ||
|
|
||
| let method_signature = &err[start_index..(start_index + method_signature_len)]; |
Contributor
There was a problem hiding this comment.
May panic if err is not long enough.
Collaborator
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #274
Description
At present, if the call of solidity contract failed, things like this printed
After this pr, following will be printed
which makes error message more human friendly.
I haven't found a rust crate to do it, so I parse 2 kinds of errors mannually.
PR author checklist:
unclog.docs/).Reviewer checklist:
Files changedin the GitHub PR explorer.