Skip to content

Commit

Permalink
feat: allow setting txn on OutOfGasError (#1259)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jan 27, 2023
1 parent eb78b20 commit fc25a45
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,16 @@ venv.bak/
.dmypy.json
dmypy.json

**/.DS_Store

# setuptools-scm
version.py

# Ape stuff
.build/

**/.DS_Store
*.swp
*.swo

# From testing
tests/integration/cli/projects/with-dependencies/renamed_contracts_folder/ape-config.yaml
tests/integration/cli/projects/with-dependencies/containing_sub_dependencies/sub_dependency/ape-config.yaml
Expand Down
4 changes: 2 additions & 2 deletions src/ape/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ class OutOfGasError(VirtualMachineError):
out of gas.
"""

def __init__(self, code: Optional[int] = None):
super().__init__("The transaction ran out of gas.", code=code)
def __init__(self, code: Optional[int] = None, txn: Optional["TransactionAPI"] = None):
super().__init__("The transaction ran out of gas.", code=code, txn=txn)


class NetworkError(ApeException):
Expand Down
3 changes: 2 additions & 1 deletion src/ape_ethereum/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ def method_called(self) -> Optional[MethodABI]:

def raise_for_status(self):
if self.gas_limit is not None and self.ran_out_of_gas:
raise OutOfGasError()
raise OutOfGasError(txn=self.transaction)

elif self.status != TransactionStatusEnum.NO_ERROR:
txn_hash = HexBytes(self.txn_hash).hex()
raise TransactionError(f"Transaction '{txn_hash}' failed.")
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/test_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ def test_receipt_raise_for_status_out_of_gas_error(mocker, ethereum):
block_number=0,
transaction=txn,
)
with pytest.raises(OutOfGasError):
with pytest.raises(OutOfGasError) as err:
receipt.raise_for_status()

assert err.value.txn == receipt.transaction


def test_receipt_chain_id(invoke_receipt, eth_tester_provider):
assert invoke_receipt.chain_id == eth_tester_provider.chain_id
5 changes: 5 additions & 0 deletions tests/integration/cli/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ def test_compile_individual_contract_excludes_other_contract(ape_cli, runner, pr

@skip_projects_except("with-dependencies")
def test_compile_non_ape_project_deletes_ape_config_file(ape_cli, runner, project):
ape_config = project.path / "default" / "ape-config.yaml"
if ape_config.is_file():
# Corrupted from a previous test.
ape_config.unlink()

result = runner.invoke(ape_cli, ["compile", "Project", "--force"], catch_exceptions=False)
assert result.exit_code == 0, result.output
assert "ape-config.yaml" not in [f.name for f in (project.path / "default").iterdir()]
Expand Down

0 comments on commit fc25a45

Please sign in to comment.