From 6b584a26ff6217506e8b1fc03a29de9cabf2d51c Mon Sep 17 00:00:00 2001 From: antazoey Date: Sat, 26 Oct 2024 16:31:43 -0500 Subject: [PATCH] fix: mistaken blob receipt causing serialization problems (#2345) --- src/ape_ethereum/ecosystem.py | 16 ++++++++++++--- tests/functional/test_ecosystem.py | 33 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/ape_ethereum/ecosystem.py b/src/ape_ethereum/ecosystem.py index f08c7a980d..82636f65fa 100644 --- a/src/ape_ethereum/ecosystem.py +++ b/src/ape_ethereum/ecosystem.py @@ -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 diff --git a/tests/functional/test_ecosystem.py b/tests/functional/test_ecosystem.py index 08b3170c9a..981afecd80 100644 --- a/tests/functional/test_ecosystem.py +++ b/tests/functional/test_ecosystem.py @@ -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}}}