Closed antazoey closed 1 year ago
When using solidity error definitions, the revert message (the inputs to the custom error) are not decoded (they are just bytes).
solidity
e.g.
ape.exceptions.ContractLogicError: b'\x9b\x0f\x01\xda\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00;\x9a\xca\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
Let's do what we do best and dynamically generate a custom Exception class with the inputs as the properties!
Solidity projects that use custom errors.
https://github.com/ApeWorX/ethpm-types/pull/29#pullrequestreview-961074682
Like structs, events, etc, let's create custom ContractLogicError classes that have the inputs as the properties on the class
ContractLogicError
So in your solidity, if you do:
error InsufficientFund(uint256 given, uint256 required); function fund() public payable isOn { if (msg.value > 0) { revert InsufficientFund(msg.value, 1); } }
, you can access the custom error classes on the ContractInstance and they will be the exceptions raised for reverts in that case.
ContractInstance
So you can do this in your tests:
with ape.reverts(contract.InsufficientFund) as err: ... assert err.value.foo == 5 assert err.value.bar == 6
pytest.raises()
NOTE: The original still has to work to as not be breaking:
with ape.reverts(message="revert reason"):
Do not signoff unless:
(Please leave a comment to sign off)
Everything looks good, approved
Perhaps can use single dispatch to allow both message and exception class to be used in ape.reverts
ape.reverts
Elevator pitch:
When using
solidity
error definitions, the revert message (the inputs to the custom error) are not decoded (they are just bytes).e.g.
Let's do what we do best and dynamically generate a custom Exception class with the inputs as the properties!
Value:
Solidity projects that use custom errors.
Dependencies:
https://github.com/ApeWorX/ethpm-types/pull/29#pullrequestreview-961074682
Design approach:
Like structs, events, etc, let's create custom
ContractLogicError
classes that have the inputs as the properties on the classSo in your solidity, if you do:
, you can access the custom error classes on the
ContractInstance
and they will be the exceptions raised for reverts in that case.So you can do this in your tests:
pytest.raises()
works.NOTE: The original still has to work to as not be breaking:
Task list:
Estimated completion date:
Design review:
Do not signoff unless:
(Please leave a comment to sign off)