Skip to content

Commit fc25a45

Browse files
authored
feat: allow setting txn on OutOfGasError (ApeWorX#1259)
1 parent eb78b20 commit fc25a45

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,16 @@ venv.bak/
114114
.dmypy.json
115115
dmypy.json
116116

117-
**/.DS_Store
118-
119117
# setuptools-scm
120118
version.py
121119

122120
# Ape stuff
123121
.build/
124122

123+
**/.DS_Store
124+
*.swp
125+
*.swo
126+
125127
# From testing
126128
tests/integration/cli/projects/with-dependencies/renamed_contracts_folder/ape-config.yaml
127129
tests/integration/cli/projects/with-dependencies/containing_sub_dependencies/sub_dependency/ape-config.yaml

src/ape/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ class OutOfGasError(VirtualMachineError):
142142
out of gas.
143143
"""
144144

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

148148

149149
class NetworkError(ApeException):

src/ape_ethereum/transactions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ def method_called(self) -> Optional[MethodABI]:
171171

172172
def raise_for_status(self):
173173
if self.gas_limit is not None and self.ran_out_of_gas:
174-
raise OutOfGasError()
174+
raise OutOfGasError(txn=self.transaction)
175+
175176
elif self.status != TransactionStatusEnum.NO_ERROR:
176177
txn_hash = HexBytes(self.txn_hash).hex()
177178
raise TransactionError(f"Transaction '{txn_hash}' failed.")

tests/functional/test_receipt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ def test_receipt_raise_for_status_out_of_gas_error(mocker, ethereum):
159159
block_number=0,
160160
transaction=txn,
161161
)
162-
with pytest.raises(OutOfGasError):
162+
with pytest.raises(OutOfGasError) as err:
163163
receipt.raise_for_status()
164164

165+
assert err.value.txn == receipt.transaction
166+
165167

166168
def test_receipt_chain_id(invoke_receipt, eth_tester_provider):
167169
assert invoke_receipt.chain_id == eth_tester_provider.chain_id

tests/integration/cli/test_compile.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ def test_compile_individual_contract_excludes_other_contract(ape_cli, runner, pr
225225

226226
@skip_projects_except("with-dependencies")
227227
def test_compile_non_ape_project_deletes_ape_config_file(ape_cli, runner, project):
228+
ape_config = project.path / "default" / "ape-config.yaml"
229+
if ape_config.is_file():
230+
# Corrupted from a previous test.
231+
ape_config.unlink()
232+
228233
result = runner.invoke(ape_cli, ["compile", "Project", "--force"], catch_exceptions=False)
229234
assert result.exit_code == 0, result.output
230235
assert "ape-config.yaml" not in [f.name for f in (project.path / "default").iterdir()]

0 commit comments

Comments
 (0)