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

fix: transaction was missing signature / couldn't get hash when came from receipt #2446

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,10 @@ def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI:
else self.network.required_confirmations
)
txn_data = txn_data or txn.model_dump(by_alias=True, mode="json")

# Signature is excluded from the model fields, so we have to include it manually.
txn_data["signature"] = txn.signature

if vm_err:
receipt = self._create_receipt(
block_number=-1, # Not in a block.
Expand Down Expand Up @@ -1076,6 +1080,9 @@ def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI:
# `nonce`, it's not needed anyway.
txn_data.pop("nonce", None)

# Signature causes issues when making call (instead of tx)
txn_data.pop("signature", None)

# NOTE: Using JSON mode since used as request data.
txn_params = cast(TxParams, txn_data)

Expand Down
2 changes: 2 additions & 0 deletions src/ape_ethereum/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def serialize_transaction(self) -> bytes:

return signed_txn

# TODO: In 0.9, either use hex-str or hex-bytes between both this
# and ReceiptAPI (make consistent).
@property
def txn_hash(self) -> HexBytes:
txn_bytes = self.serialize_transaction()
Expand Down
2 changes: 1 addition & 1 deletion src/ape_test/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def send_transaction(self, txn: "TransactionAPI") -> "ReceiptAPI":
else:
txn_dict = txn_dict or txn.model_dump(mode="json")

# Signature is typically excluded from the model fields,
# Signature is excluded from the model fields,
# so we have to include it manually.
txn_dict["signature"] = txn.signature

Expand Down
9 changes: 9 additions & 0 deletions tests/functional/geth/test_receipt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from eth_utils import to_hex

from ape.api import TraceAPI
from ape.utils import ManagerAccessMixin
from tests.conftest import geth_process_test
Expand Down Expand Up @@ -73,3 +75,10 @@ def test_await_confirmations_zero_confirmations(mocker, geth_account, geth_contr
tx.await_confirmations()
assert tx.confirmed
assert spy.call_count == 1


def test_transaction(geth_account, geth_contract):
receipt = geth_contract.setNumber(1998, sender=geth_account)
actual = receipt.transaction
assert actual.sender == geth_account.address
assert to_hex(actual.txn_hash) == receipt.txn_hash
8 changes: 8 additions & 0 deletions tests/functional/test_receipt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import TYPE_CHECKING

import pytest
from eth_utils import to_hex
from rich.table import Table
from rich.tree import Tree

Expand Down Expand Up @@ -270,6 +271,13 @@ def test_access_from_tx(deploy_receipt):
assert actual == deploy_receipt


def test_transaction(owner, vyper_contract_instance):
receipt = vyper_contract_instance.setNumber(1999, sender=owner)
actual = receipt.transaction
assert actual.sender == owner.address
assert to_hex(actual.txn_hash) == receipt.txn_hash


def test_transaction_validated_from_dict(ethereum, owner, deploy_receipt):
tx = ethereum.create_transaction(sender=owner.address, value=123, data=b"hello")
tx_data = tx.model_dump()
Expand Down
Loading