-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix assertion error when calling the cdps getter of the Stabilization contract #45
Conversation
Fixes `AssertionError` from the assert isinstance(return_value, tuple) assertion when calling the `cdps` getter of the Stabilization contract. The reason for failing the assertion is that for this call the contract function wrapper returns a list instead of the expected tuple. To work around it, cast the return value to a tuple. Note that according to web3.py docs[1], the function wrapper's call() method "returns the return value of the executed function" i.e. there is no guarantee that the return value is either a list or a tuple, however I don't think we should worry about it until we run into similar errors. [1]: https://web3py.readthedocs.io/en/stable/web3.contract.html#web3.contract.ContractFunction.call Fixes #37.
The previous docstring was unhelpful in understanding what the function does.
Do we know why we are getting back a list instead of a tuple? I think it is worth investigating. Otherwise, we won't be able to detect if there is a problem since we don't know what the expected behaviour of Web3 should be. This is a good starting point: https://github.com/ethereum/web3.py/blob/e94e5e8cf79eed324534fdf77127a49545aba20a/web3/contract/utils.py#L66 |
I've done the investigation. The contract function call is performed by try:
output_data = w3.codec.decode(output_types, return_data)
except DecodingError as e:
...
_normalizers = itertools.chain(
BASE_RETURN_NORMALIZERS,
normalizers,
)
normalized_data = map_abi_data(_normalizers, output_types, output_data) It first calls However, Therefore, if the contract function has multiple outputs, the expected behaviour of Web3 is that the return type is a list. I could verify this by performing other contract calls; e.g. calling the
also results in assertion error. |
Anyway, it seems to me that the entire decoding logic in
I'd propose a refactoring that autcli should use the built-in ABI parser instead of our own implementation. |
Great investigation, thanks!
This sounds like a good proposal, let's discuss it soon. |
Fixes
AssertionError
from theassertion when calling the
cdps
getter of the Stabilization contract.The reason for failing the assertion is that for this call the contract
function wrapper returns a list instead of the expected tuple.
To work around it, cast the return value to a tuple.
Note that according to web3.py docs1, the function wrapper's call()
method "returns the return value of the executed function" i.e. there is
no guarantee that the return value is either a list or a tuple, however
I don't think we should worry about it until we run into similar errors.
Fixes #37.