fubuloubu / pytest-ethereum-old

py.test plugin for testing Ethereum smart contracts
MIT License
20 stars 1 forks source link

Need a mechanism for measuring/asserting gas use #3

Open fubuloubu opened 6 years ago

fubuloubu commented 6 years ago

Vyper has a built-in gas estimator. I would like to allow this in my plugin, for the simple fact that Vyper could leverage this plugin if it had this functionality. For reference, here it is: https://github.com/ethereum/vyper/blob/248c723288e84899908048efff4c3e0b12f0b3dc/tests/conftest.py#L178-L182

To enable this feature to be more broadly useful, I want a mechanism where you could assert a ceiling for gas usage via the ABI, leveraging a to-be-standardized feature of the ABI that includes max gas estimates for additional utility. It would basically be implemented like this:

# Function caller
...

# If gas estimate is available, check it
if 'gas' in func_abi:
    assert function.gasEstimate < func_abi.gas, "Function execution exceeds estimate!"

...