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: mistaken blob receipt causing serialization problems #2345

Merged
merged 4 commits into from
Oct 26, 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
16 changes: 13 additions & 3 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,19 @@ def decode_receipt(self, data: dict) -> ReceiptAPI:
"blob_gas_used",
)
):
receipt_cls = SharedBlobReceipt
receipt_kwargs["blobGasPrice"] = data.get("blob_gas_price", data.get("blobGasPrice"))
receipt_kwargs["blobGasUsed"] = data.get("blob_gas_used", data.get("blobGasUsed")) or 0
blob_gas_price = data.get("blob_gas_price", data.get("blobGasPrice"))
if blob_gas_price is None:
# Not actually a blob-receipt? Some providers may give you
# empty values here when meaning the other types of receipts.
receipt_cls = Receipt

else:
receipt_cls = SharedBlobReceipt
receipt_kwargs["blobGasPrice"] = blob_gas_price
receipt_kwargs["blobGasUsed"] = (
data.get("blob_gas_used", data.get("blobGasUsed")) or 0
)

else:
receipt_cls = Receipt

Expand Down
33 changes: 33 additions & 0 deletions tests/functional/test_ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,39 @@ def test_decode_receipt_shared_blob(ethereum, blob_gas_used, blob_gas_key):
assert actual.blob_gas_used == 0


def test_decode_receipt_misleading_blob_receipt(ethereum):
"""
Tests a strange situation (noticed on Tenderly nodes) where _some_
of the keys indicate blob-related fields, set to ``0``, and others
are missing, because it's not actually a blob receipt. In this case,
don't use the blob-receipt class.
"""
data = {
"type": 2,
"status": 1,
"cumulativeGasUsed": 10565720,
"logsBloom": HexBytes(
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" # noqa: E501
),
"logs": [],
"transactionHash": HexBytes(
"0x62fc9991bc7fb0c76bc83faaa8d1c17fc5efb050542e58ac358932f80aa7a087"
),
"from": "0x1f9090aaE28b8a3dCeaDf281B0F12828e676c326",
"to": "0xeBec795c9c8bBD61FFc14A6662944748F299cAcf",
"contractAddress": None,
"gasUsed": 21055,
"effectiveGasPrice": 7267406643,
"blockHash": HexBytes("0xa47fc133f829183b751488c1146f1085451bcccd247db42066dc6c89eaf5ebac"),
"blockNumber": 21051245,
"transactionIndex": 130,
"blobGasUsed": 0,
}
actual = ethereum.decode_receipt(data)
assert not isinstance(actual, SharedBlobReceipt)
assert isinstance(actual, Receipt)


def test_default_transaction_type_not_connected_used_default_network(project, ethereum, networks):
value = TransactionType.STATIC.value
config_dict = {"ethereum": {"mainnet_fork": {"default_transaction_type": value}}}
Expand Down
Loading