eth-brownie / brownie

A Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine.
https://eth-brownie.readthedocs.io
MIT License
2.65k stars 551 forks source link

When contracts return a string type starting with '0x' like '0x9e' , brwonie may have an error #1692

Open kejaly opened 1 year ago

kejaly commented 1 year ago

Environment information

What was wrong?

When Brownie returns a string starting with "0x", it will go to unhex it , which leads to an error if you want to directly return a string starting with "0x", such as "0x9e".

The test code is as follows: the left is test0x.sol , and the right is test.py

image

and I found out that the reason is the _format_single function :

image

when the type is string ,it will call to_string(value) , and in the to_string function , it will try to unhex the value ,if it is start with a '0x':

image

How can it be fixed

in my opinion, i think since it is already a string type, you can directly return str(value) instead of calling to_string(value)