Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContractLogicError from custom exception contains stringified bytes instead of hex str #253

Open
antazoey opened this issue Mar 14, 2023 · 0 comments

Comments

@antazoey
Copy link
Contributor

  • Version: 0.7.0b1
  • Python: 3.9.13
  • OS: macOS

What was wrong?

Currently, when you have a custom Solidity exeption type like:

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;

error Unauthorized();

contract HasError {
    address payable owner = payable(msg.sender);

    function withdraw() public {
        if (msg.sender != owner)
            revert Unauthorized();

        owner.transfer(address(this).balance);
    }
    // ...
}

and you purposely trigger the error, you get an exception with the following message:

TransactionFailed("execution reverted: b'\\x82\\xb4)\\x00'")

It is great! But when parsing into a python script, it can be awkward because it is a bytes string enclosed within an actual string.

How can it be fixed?

Before putting the reason in the exception message, convert it to a hex str such that the output is:

TransactionFailed("execution reverted: 0x82b42900")

Fill this section in if you know how this could or should be fixed.

@antazoey antazoey changed the title ContractLogicError from custom exception contains stringified bytes data ContractLogicError from custom exception contains stringified bytes instead of hex str Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant