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.63k stars 550 forks source link

Method signatures are not parsed well in arguments #1015

Open forestswap opened 3 years ago

forestswap commented 3 years ago

Environment information

What was wrong?

I'm trying to execute a tx from a Timelock. Brownie seems to have problems with the signature :

from brownie import ForestToken, MasterChef, Timelock, ForestReferral, accounts, Contract
from web3 import Web3

def main():
    acct = accounts.load('dev')

    chef = MasterChef.at("0xbBE864d09902c6c55D8DB0D83ae9D81ffd77D9b8")
    time = Timelock.at('0xf82adCDac7b7189D5C168354110C763A228a8D68')

    txPID0 = time.executeTransaction(chef.address, 0, '0xd9638422', "0xd96384220000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000009eb1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        1616612400, {"from":acct})

This returns the following error:

  File "eth_brownie-1.14.2-py3.9.egg/brownie/_cli/run.py", line 49, in main
    return_value, frame = run(
  File "eth_brownie-1.14.2-py3.9.egg/brownie/project/scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/get_tx_sign.py", line 10, in main
    txPID01 = time.executeTransaction(chef.address, 0, '0xd9638422', "0xd96384220000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000009eb1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  File "eth_brownie-1.14.2-py3.9.egg/brownie/network/contract.py", line 1670, in __call__
    return self.transact(*args)
  File "eth_brownie-1.14.2-py3.9.egg/brownie/network/contract.py", line 1552, in transact
    data=self.encode_input(*args),
  File "eth_brownie-1.14.2-py3.9.egg/brownie/network/contract.py", line 1587, in encode_input
    data = format_input(self.abi, args)
  File "eth_brownie-1.14.2-py3.9.egg/brownie/convert/normalize.py", line 20, in format_input
    raise type(e)(f"{abi['name']} {e}") from None
ValueError: executeTransaction '0xd9638422' - 'utf-8' codec can't decode byte 0xd9 in position 0: invalid continuation byte
Terminating local RPC client...

Any idea how I could solve this ? I tried to add .encode() but it doesn't seem to work.

iamdefinitelyahuman commented 3 years ago

It's happening because the input arg type where you supply 0xd9638422 is a string, and there seems to be a bug interpreting the hex data that way. You could try removing the leading 0x or passing it as b"0xd9638422" instead - but I would test in fork mode first, I'm not sure how these values will get ABI encoded or how Solidity will handle it when converting to bytes.

My own personal feeling is that hex data should be typed as bytes, so this isn't an area of Brownie that's been adequately tested / thought out. Sorry.