diff --git a/newsfragments/3224.feature.rst b/newsfragments/3224.feature.rst new file mode 100644 index 0000000000..2d7933d42a --- /dev/null +++ b/newsfragments/3224.feature.rst @@ -0,0 +1 @@ +Add formatters for new ``Cancun`` network upgrade block header fields: ``blobGasUsed``, ``excessBlobGas``, and ``parentBeaconBlockRoot``. diff --git a/tests/core/eth-module/test_block_api.py b/tests/core/eth-module/test_block_api.py index b9abae1329..c41813ac3b 100644 --- a/tests/core/eth-module/test_block_api.py +++ b/tests/core/eth-module/test_block_api.py @@ -50,6 +50,9 @@ def test_get_block_formatters_with_null_values(w3): "transactions": [], "withdrawalsRoot": None, "withdrawals": [], + "blobGasUsed": None, + "excessBlobGas": None, + "parentBeaconBlockRoot": None, } result_middleware = construct_result_generator_middleware( { @@ -115,6 +118,11 @@ def test_get_block_formatters_with_pre_formatted_values(w3): "amount": "0x3f695", }, ], + "blobGasUsed": "0x7ffff", + "excessBlobGas": "0x12c00000", + "parentBeaconBlockRoot": ( + "0x6470e77f1b8a55a49a57b3f74c2a10a76185636d65122053752ea5e4bb4dac59" + ), } result_middleware = construct_result_generator_middleware( { @@ -175,4 +183,9 @@ def test_get_block_formatters_with_pre_formatted_values(w3): "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"] + ), } diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index b157829e0f..ceff14090e 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -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)), }