3

I am following a brownie tutorial which wrote the following test

def test_only_owner_can_withdraw():    
    fund_me = deploy()
    bad_actor = accounts.add()
    with pytest.raises(exceptions.VirtualMachineError):
        fund_me.withdraw({"from": bad_actor})

and when I run it on development, it is supposed to pass after an exception from the withdraw transaction being reverted, but instead I get the following error:

>       fund_me.withdraw({"from": bad_actor})
E       TypeError: int() can't convert non-string with explicit base

and the stack from pdb where the error happens is as follows:

/home/gcodes/brownie_fundme/tests/test_fund_me.py(30)test_only_owner_can_withdraw()
-> fund_me.withdraw({"from": bad_actor})
  /home/gcodes/.local/pipx/venvs/eth-brownie/lib/python3.10/site-packages/brownie/network/contract.py(1864)__call__()
-> return self.transact(*args)
  /home/gcodes/.local/pipx/venvs/eth-brownie/lib/python3.10/site-packages/brownie/network/contract.py(1737)transact()
-> return tx["from"].transfer(
  /home/gcodes/.local/pipx/venvs/eth-brownie/lib/python3.10/site-packages/brownie/network/account.py(682)transfer()
-> receipt._raise_if_reverted(exc)
  /home/gcodes/.local/pipx/venvs/eth-brownie/lib/python3.10/site-packages/brownie/network/transaction.py(432)_raise_if_reverted()
-> self._expand_trace()
  /home/gcodes/.local/pipx/venvs/eth-brownie/lib/python3.10/site-packages/brownie/network/transaction.py(817)_expand_trace()
-> self._get_trace()
> /home/gcodes/.local/pipx/venvs/eth-brownie/lib/python3.10/site-packages/brownie/network/transaction.py(678)_get_trace()
-> step["pc"] = int(step["pc"], 16)

and step is as follows

{'depth': 1, 'error': '', 'gas': 11978936, 'gasCost': 3, 'memory': [], 'op': 'PUSH1', 'pc': 0, 'stack': [], 'storage': None}

What is the issue here? Thank you

Edit: Upon further investigation, I noticed that the executed code in transactions.py is

fix_gas = isinstance(trace[0]["gas"], str)

if fix_stack or fix_gas:
    for step in trace:
        if fix_stack:
            # for stack values, we need 32 bytes (64 chars) without the 0x prefix
            step["stack"] = [HexBytes(s).hex()[2:].zfill(64) for s in step["stack"]]
        if fix_gas:
            # handle traces where numeric values are returned as hex (Nethermind)
            step["gas"] = int(step["gas"], 16)
            step["gasCost"] = int.from_bytes(HexBytes(step["gasCost"]), "big", signed=True)
            step["pc"] = int(step["pc"], 16)

and before that trace[0] is

{'depth': 1, 'error': '', 'gas': '0xb6c8b8', 'gasCost': 3, 'memory': [], 'op': 'PUSH1', 'pc': 0, 'stack': [], 'storage': None}

so fix_gas is set to True, however pc is not in hex form so int(0, 16) throws an error. However, I don't think anything I do is causing this and I don't know how to fix this issue. What do I do?

gcodes
  • 33
  • 5

0 Answers0