-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
feat: raise virtual machine errors #181
Conversation
c7c3bb1
to
6395b5c
Compare
src/ape/utils.py
Outdated
@@ -140,6 +142,41 @@ def compute_checksum(source: bytes, algorithm: str = "md5") -> str: | |||
return hasher(source).hexdigest() | |||
|
|||
|
|||
def get_tx_error_from_web3_value_error(web3_value_error: ValueError) -> Optional[TransactionError]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, this method only returns errors instead of raising them.
If it returns None
, we did not detect a transaction related error and the user of the method handle that however.
In our ape-http
example, if we don't get a transaction error from this, we raise the original error.
I have noticed an issue: If estimating gas (not specifying a gas limit), and calling a transaction that will revert, the transaction fails at that point with the revert message, so that is why brownie must raise the fixed |
src/ape_http/providers.py
Outdated
|
||
# If this is the cause of a would-be revert, | ||
# raise the VirtualMachineError so that we can confirm tx-reverts. | ||
if isinstance(txn, VirtualMachineError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We either have to do this, or any test that uses ape.reverts()
will have to specify a gas_limit
.
Edit:
Comment outdated, now says if isinstance(tx_error, VirtualMachineError):
449d9f4
to
28a1420
Compare
28a1420
to
bb164a4
Compare
What I did
How I did it
TransactionError
from web3.py'sValueError
(web3.py raisesValueError
for different Virtual-machine related errors). Also raise when a transaciton is reported as failing.How to verify it
when specifying a poor gas limit (too high, too low, etc), you should get
TransactionError
s.Like:
ERROR: {'code': -32000, 'message': 'Transaction requires at least 63744 gas but got 1000'}
when the gas is too low (
contract = test_account.deploy(contract_type, gas_limit=1000)
)and
ERROR: {'code': -32000, 'message': 'Transaction gas limit is 100000000 and exceeds block gas limit of 30000000'}
when the gas is too high (
contract = test_account.deploy(contract_type, gas_limit=100000000)
)Note: TransactionError ultimately will help us write the
ape.test.reverts()
fixture!Checklist