Skip to content

Commit

Permalink
fix: issue with snake_case keys in `ape_ethereum.transactions.ShareBl…
Browse files Browse the repository at this point in the history
…obReceipt` (#2205)
  • Loading branch information
antazoey authored Aug 5, 2024
1 parent 011f776 commit af66f93
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
15 changes: 10 additions & 5 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,18 @@ def decode_receipt(self, data: dict) -> ReceiptAPI:
receipt_cls: type[Receipt]
if any(
x in data
for x in ("blobGasPrice", "blobGasUsed", "blobVersionedHashes", "maxFeePerBlobGas")
for x in (
"blobGasPrice",
"blobGasUsed",
"blobVersionedHashes",
"maxFeePerBlobGas",
"blob_gas_price",
"blob_gas_used",
)
):
receipt_cls = SharedBlobReceipt
receipt_kwargs["blob_gas_price"] = data.get("blob_gas_price", data.get("blobGasPrice"))
receipt_kwargs["blob_gas_used"] = (
data.get("blob_gas_used", data.get("blobGasUsed")) or 0
)
receipt_kwargs["blobGasPrice"] = data.get("blob_gas_price", data.get("blobGasPrice"))
receipt_kwargs["blobGasUsed"] = data.get("blob_gas_used", data.get("blobGasUsed")) or 0
else:
receipt_cls = Receipt

Expand Down
4 changes: 2 additions & 2 deletions src/ape_ethereum/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,12 @@ class SharedBlobReceipt(Receipt):
blob transaction.
"""

blob_gas_used: HexInt
blob_gas_used: Optional[HexInt] = Field(default=None, alias="blobGasUsed")
"""
The total amount of blob gas consumed by the transactions within the block.
"""

blob_gas_price: HexInt
blob_gas_price: HexInt = Field(alias="blobGasPrice")
"""
The blob-gas price, independent from regular gas price.
"""
14 changes: 11 additions & 3 deletions tests/functional/test_ecosystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,16 @@ def test_decode_receipt_from_etherscan(eth_tester_provider, ethereum):
assert receipt.gas_price == 1499999989


@pytest.mark.parametrize("blob_gas_used", ("0x20000", 131072, 0, None))
def test_decode_receipt_shared_blob(ethereum, blob_gas_used):
@pytest.mark.parametrize(
"blob_gas_used,blob_gas_key",
[
("0x20000", "blobGasUsed"),
(131072, "blob_gas_used"),
(0, "blobGasUsed"),
(None, "blobGasUsed"),
],
)
def test_decode_receipt_shared_blob(ethereum, blob_gas_used, blob_gas_key):
blob_gas_price = "0x4d137e31b"

data = {
Expand Down Expand Up @@ -582,7 +590,7 @@ def test_decode_receipt_shared_blob(ethereum, blob_gas_used):
"s": HexBytes("0x31c98ea044c97225d83b9a3f0fa719e2299b9fbc6436e4b3eb096ea528de03ff"),
"yParity": 0,
"blobGasPrice": blob_gas_price,
"blobGasUsed": blob_gas_used,
blob_gas_key: blob_gas_used,
"contractAddress": None,
"cumulativeGasUsed": 23085827,
"effectiveGasPrice": 1000000008,
Expand Down

0 comments on commit af66f93

Please sign in to comment.