Skip to content

Commit

Permalink
Move getBlockTransactionCount to get_block_transaction_count
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Jan 20, 2021
1 parent 03416d5 commit 9b667ce
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
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
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')

0 comments on commit 9b667ce

Please sign in to comment.