Skip to content

Commit 7ccc2f2

Browse files
authored
feat: alias tx.gas for tx.gas_limit and tx.hash for tx.txn_hash (#2431)
1 parent d5e1a6f commit 7ccc2f2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/ape/api/transactions.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,19 @@ def validate_gas_limit(cls, value):
9595

9696
return value
9797

98+
@property
99+
def gas(self) -> Optional[int]:
100+
"""
101+
Alias for ``.gas_limit``.
102+
"""
103+
return self.gas_limit
104+
98105
@property
99106
def raise_on_revert(self) -> bool:
107+
"""
108+
``True`` means VM-reverts should raise exceptions.
109+
``False`` allows getting failed receipts.
110+
"""
100111
return self._raise_on_revert
101112

102113
@raise_on_revert.setter
@@ -122,6 +133,14 @@ def txn_hash(self) -> HexBytes:
122133
The calculated hash of the transaction.
123134
"""
124135

136+
# TODO: In 0.9, simply rename txn_hash to hash.
137+
@property
138+
def hash(self) -> HexBytes:
139+
"""
140+
Alias for ``self.txn_hash``.
141+
"""
142+
return self.txn_hash
143+
125144
@property
126145
def receipt(self) -> Optional["ReceiptAPI"]:
127146
"""

tests/functional/test_transaction.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ def test_txn_hash_and_receipt(owner, eth_tester_provider, ethereum, kwargs):
225225
txn = owner.prepare_transaction(txn)
226226
txn = owner.sign_transaction(txn)
227227
assert txn
228+
229+
# Show the .hash alias works.
230+
assert txn.hash == txn.txn_hash
231+
228232
actual = to_hex(txn.txn_hash)
229233
receipt = eth_tester_provider.send_transaction(txn)
230234

@@ -406,3 +410,10 @@ def serialize_transaction(self) -> bytes:
406410
my_tx = MyTransaction.model_validate({"chain_id": chain_id, "type": tx_type})
407411
assert my_tx.chain_id == chain_id
408412
assert my_tx.type == tx_type
413+
414+
415+
def test_gas(ethereum):
416+
tx = ethereum.create_transaction(gas_limit=123)
417+
assert tx.gas_limit == 123
418+
# Show the `gas` alias works.
419+
assert tx.gas == 123

0 commit comments

Comments
 (0)