Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: alias tx.gas for tx.gas_limit and tx.hash for tx.txn_hash #2431

Merged
merged 6 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/ape/api/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,19 @@ def validate_gas_limit(cls, value):

return value

@property
def gas(self) -> Optional[int]:
"""
Alias for ``.gas_limit``.
"""
return self.gas_limit

@property
def raise_on_revert(self) -> bool:
"""
``True`` means VM-reverts should raise exceptions.
``False`` allows getting failed receipts.
"""
return self._raise_on_revert

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

# TODO: In 0.9, simply rename txn_hash to hash.
@property
def hash(self) -> HexBytes:
"""
Alias for ``self.txn_hash``.
"""
return self.txn_hash

@property
def receipt(self) -> Optional["ReceiptAPI"]:
"""
Expand Down
11 changes: 11 additions & 0 deletions tests/functional/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ def test_txn_hash_and_receipt(owner, eth_tester_provider, ethereum, kwargs):
txn = owner.prepare_transaction(txn)
txn = owner.sign_transaction(txn)
assert txn

# Show the .hash alias works.
assert txn.hash == txn.txn_hash

actual = to_hex(txn.txn_hash)
receipt = eth_tester_provider.send_transaction(txn)

Expand Down Expand Up @@ -406,3 +410,10 @@ def serialize_transaction(self) -> bytes:
my_tx = MyTransaction.model_validate({"chain_id": chain_id, "type": tx_type})
assert my_tx.chain_id == chain_id
assert my_tx.type == tx_type


def test_gas(ethereum):
tx = ethereum.create_transaction(gas_limit=123)
assert tx.gas_limit == 123
# Show the `gas` alias works.
assert tx.gas == 123
Loading