diff --git a/docs/overview.rst b/docs/overview.rst index 54cc63dc36..e5683d5ba7 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -142,7 +142,7 @@ API - :meth:`web3.eth.get_balance() ` - :meth:`web3.eth.get_block() ` -- :meth:`web3.eth.getBlockTransactionCount() ` +- :meth:`web3.eth.get_block_transaction_count() ` - :meth:`web3.eth.getCode() ` - :meth:`web3.eth.getProof() ` - :meth:`web3.eth.get_storage_at() ` diff --git a/docs/web3.eth.rst b/docs/web3.eth.rst index cf4bd9ea2d..6484041de3 100644 --- a/docs/web3.eth.rst +++ b/docs/web3.eth.rst @@ -376,7 +376,7 @@ The following methods are available on the ``web3.eth`` namespace. .. warning:: Deprecated: This method is deprecated in favor of :meth:`~web3.eth.Eth.get_block` -.. py:method:: Eth.getBlockTransactionCount(block_identifier) +.. py:method:: Eth.get_block_transaction_count(block_identifier) * Delegates to ``eth_getBlockTransactionCountByNumber`` or ``eth_getBlockTransactionCountByHash`` RPC Methods @@ -389,12 +389,19 @@ The following methods are available on the ``web3.eth`` namespace. .. code-block:: python - >>> web3.eth.getBlockTransactionCount(46147) + >>> web3.eth.get_block_transaction_count(46147) 1 - >>> web3.eth.getBlockTransactionCount('0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd') # block 46147 + >>> web3.eth.get_block_transaction_count('0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd') # block 46147 1 +.. py:method:: Eth.getBlockTransactionCount(block_identifier) + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.eth.Eth.get_block_transaction_count` + + + .. py:method:: Eth.getUncle(block_identifier) .. note:: Method to get an Uncle from its hash is not available through diff --git a/newsfragments/1841.feature.rst b/newsfragments/1841.feature.rst new file mode 100644 index 0000000000..f5ee4321d1 --- /dev/null +++ b/newsfragments/1841.feature.rst @@ -0,0 +1 @@ +Added ``get_block_transaction_count``, and deprecated ``getBlockTransactionCount`` diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index 51e307c2e0..9fc1d56d75 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -180,7 +180,7 @@ def test_eth_getStorageAt_deprecated( ) -> None: with pytest.warns(DeprecationWarning): storage = web3.eth.getStorageAt(emitter_contract_address, 0) - assert isinstance(storage, HexBytes) + assert isinstance(storage, HexBytes) def test_eth_get_storage_at_ens_name( self, web3: "Web3", emitter_contract_address: ChecksumAddress @@ -217,7 +217,7 @@ def test_eth_getTransactionCount_invalid_address(self, web3: "Web3") -> None: def test_eth_getBlockTransactionCountByHash_empty_block( self, web3: "Web3", empty_block: BlockData ) -> None: - transaction_count = web3.eth.getBlockTransactionCount(empty_block['hash']) + transaction_count = web3.eth.get_block_transaction_count(empty_block['hash']) assert is_integer(transaction_count) assert transaction_count == 0 @@ -225,7 +225,7 @@ def test_eth_getBlockTransactionCountByHash_empty_block( def test_eth_getBlockTransactionCountByNumber_empty_block( self, web3: "Web3", empty_block: BlockData ) -> None: - transaction_count = web3.eth.getBlockTransactionCount(empty_block['number']) + transaction_count = web3.eth.get_block_transaction_count(empty_block['number']) assert is_integer(transaction_count) assert transaction_count == 0 @@ -233,7 +233,7 @@ def test_eth_getBlockTransactionCountByNumber_empty_block( def test_eth_getBlockTransactionCountByHash_block_with_txn( self, web3: "Web3", block_with_txn: BlockData ) -> None: - transaction_count = web3.eth.getBlockTransactionCount(block_with_txn['hash']) + transaction_count = web3.eth.get_block_transaction_count(block_with_txn['hash']) assert is_integer(transaction_count) assert transaction_count >= 1 @@ -241,7 +241,31 @@ def test_eth_getBlockTransactionCountByHash_block_with_txn( def test_eth_getBlockTransactionCountByNumber_block_with_txn( self, web3: "Web3", block_with_txn: BlockData ) -> None: - transaction_count = web3.eth.getBlockTransactionCount(block_with_txn['number']) + transaction_count = web3.eth.get_block_transaction_count(block_with_txn['number']) + + assert is_integer(transaction_count) + assert transaction_count >= 1 + + def test_eth_getBlockTransactionCountByHash_block_with_txn_deprecated( + self, web3: "Web3", block_with_txn: BlockData + ) -> None: + with pytest.warns( + DeprecationWarning, + match="getBlockTransactionCount is deprecated in favor of get_block_transaction_count" + ): + transaction_count = web3.eth.getBlockTransactionCount(block_with_txn['hash']) + + assert is_integer(transaction_count) + assert transaction_count >= 1 + + def test_eth_getBlockTransactionCountByNumber_block_with_txn_deprecated( + self, web3: "Web3", block_with_txn: BlockData + ) -> None: + with pytest.warns( + DeprecationWarning, + match="getBlockTransactionCount is deprecated in favor of get_block_transaction_count" + ): + transaction_count = web3.eth.getBlockTransactionCount(block_with_txn['number']) assert is_integer(transaction_count) assert transaction_count >= 1 diff --git a/web3/eth.py b/web3/eth.py index 24158c3614..26f4cbb23c 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -273,7 +273,7 @@ def get_block_munger( `eth_getBlockTransactionCountByHash` `eth_getBlockTransactionCountByNumber` """ - getBlockTransactionCount: Method[Callable[[BlockIdentifier], int]] = Method( + get_block_transaction_count: Method[Callable[[BlockIdentifier], int]] = Method( method_choice_depends_on_args=select_method_for_block_identifier( if_predefined=RPC.eth_getBlockTransactionCountByNumber, if_hash=RPC.eth_getBlockTransactionCountByHash, @@ -567,3 +567,6 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None: getBalance = DeprecatedMethod(get_balance, 'getBalance', 'get_balance') getStorageAt = DeprecatedMethod(get_storage_at, 'getStorageAt', 'get_storage_at') getBlock = DeprecatedMethod(get_block, 'getBlock', 'get_block') + getBlockTransactionCount = DeprecatedMethod(get_block_transaction_count, + 'getBlockTransactionCount', + 'get_block_transaction_count')