Skip to content
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
1 change: 1 addition & 0 deletions newsfragments/3223.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add formatters for new ``Cancun`` network upgrade block header fields: ``blobGasUsed``, ``excessBlobGas``, and ``parentBeaconBlockRoot``.
13 changes: 13 additions & 0 deletions tests/core/eth-module/test_block_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def test_get_block_formatters_with_null_values(w3, request_mocker):
"transactions": [],
"withdrawalsRoot": None,
"withdrawals": [],
"blobGasUsed": None,
"excessBlobGas": None,
"parentBeaconBlockRoot": None,
}
with request_mocker(w3, mock_results={"eth_getBlockByNumber": null_values_block}):
received_block = w3.eth.get_block("pending")
Expand Down Expand Up @@ -101,6 +104,11 @@ def test_get_block_formatters_with_pre_formatted_values(w3, request_mocker):
"amount": "0x3f695",
},
],
"blobGasUsed": "0x7ffff",
"excessBlobGas": "0x12c00000",
"parentBeaconBlockRoot": (
"0x6470e77f1b8a55a49a57b3f74c2a10a76185636d65122053752ea5e4bb4dac59"
),
}

with request_mocker(
Expand Down Expand Up @@ -157,4 +165,9 @@ def test_get_block_formatters_with_pre_formatted_values(w3, request_mocker):
"amount": int(unformatted_values_block["withdrawals"][1]["amount"], 16),
},
],
"blobGasUsed": int(unformatted_values_block["blobGasUsed"], 16),
"excessBlobGas": int(unformatted_values_block["excessBlobGas"], 16),
"parentBeaconBlockRoot": HexBytes(
unformatted_values_block["parentBeaconBlockRoot"]
),
}
3 changes: 3 additions & 0 deletions web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]:
is_not_null, apply_list_to_array_formatter(withdrawal_result_formatter)
),
"withdrawalsRoot": apply_formatter_if(is_not_null, to_hexbytes(32)),
"blobGasUsed": to_integer_if_hex,
"excessBlobGas": to_integer_if_hex,
"parentBeaconBlockRoot": apply_formatter_if(is_not_null, to_hexbytes(32)),
}


Expand Down