Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move getBlockTransactionCount to get_block_transaction_count #1841

Merged
merged 1 commit into from
Jan 20, 2021
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
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ API

- :meth:`web3.eth.get_balance() <web3.eth.Eth.get_balance>`
- :meth:`web3.eth.get_block() <web3.eth.Eth.get_block>`
- :meth:`web3.eth.getBlockTransactionCount() <web3.eth.Eth.getBlockTransactionCount>`
- :meth:`web3.eth.get_block_transaction_count() <web3.eth.Eth.get_block_transaction_count>`
- :meth:`web3.eth.getCode() <web3.eth.Eth.getCode>`
- :meth:`web3.eth.getProof() <web3.eth.Eth.getProof>`
- :meth:`web3.eth.get_storage_at() <web3.eth.Eth.get_storage_at>`
Expand Down
13 changes: 10 additions & 3 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions newsfragments/1841.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ``get_block_transaction_count``, and deprecated ``getBlockTransactionCount``
34 changes: 29 additions & 5 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -217,31 +217,55 @@ 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

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

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

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
Expand Down
5 changes: 4 additions & 1 deletion web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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')