Skip to content

Commit

Permalink
test: temp fix for test
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Jun 19, 2023
1 parent ffb3667 commit a85d5d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
25 changes: 8 additions & 17 deletions ape_solidity/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,26 +670,17 @@ def _get_best_version(self, path: Path, source_by_pragma_spec: Dict) -> Version:

def enrich_error(self, err: ContractLogicError) -> ContractLogicError:
if not is_0x_prefixed(err.revert_message):
# Nothing to do.
return err

if panic_cls := _get_sol_panic(err.revert_message):
# Is from a Solidity panic code, like a builtin Solidity revert.

if self._ape_version <= Version("0.6.10"):
return panic_cls(
contract_address=err.contract_address,
trace=err.trace,
txn=err.txn,
)
else:
# TODO: Bump to next ape version and remove conditional.
return panic_cls(
base_err=err.base_err,
contract_address=err.contract_address,
source_traceback=err.source_traceback,
trace=err.trace,
txn=err.txn,
)
return panic_cls(
base_err=err.base_err,
contract_address=err.contract_address,
source_traceback=err.source_traceback,
trace=err.trace,
txn=err.txn,
)

# Check for ErrorABI.
bytes_message = HexBytes(err.revert_message)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"packaging", # Use the version ape requires
"requests",
"typing-extensions==4.5.0", # Can be removed onced pinned in Core.
"web3[tester]>=0.6.5,<0.7.0", # Can remove any version after eth-ape 0.6.11
],
python_requires=">=3.8,<4",
extras_require=extras_require,
Expand Down
18 changes: 14 additions & 4 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ape.exceptions import CompilerError
from ethpm_types.ast import ASTClassification
from semantic_version import Version # type: ignore
from web3.exceptions import ContractPanicError

from ape_solidity import Extension
from ape_solidity._utils import OUTPUT_SELECTION
Expand Down Expand Up @@ -398,10 +399,19 @@ def test_enrich_error_when_custom(compiler, project, owner, not_owner, connectio


def test_enrich_error_when_builtin(project, owner, connection):
contract = project.BuiltinErrorChecker.deploy(sender=owner)

with pytest.raises(IndexOutOfBoundsError):
contract.checkIndexOutOfBounds(sender=owner)
# TODO: Any version after eth-ape 0.6.11, you can uncomment this and delete the rest.
# contract = project.BuiltinErrorChecker.deploy(sender=owner)
# with pytest.raises(IndexOutOfBoundsError):
# contract.checkIndexOutOfBounds(sender=owner)

compiler = project.compiler_manager.solidity
base_err = ContractPanicError(
message="Panic error 0x32: Array index is out of bounds.",
data="0x4e487b710000000000000000000000000000000000000000000000000000000000000032",
)
actual = compiler.enrich_error(base_err)
assert isinstance(actual, IndexOutOfBoundsError)
assert actual.base_err == base_err


def test_ast(project, compiler):
Expand Down

0 comments on commit a85d5d5

Please sign in to comment.