Skip to content

Commit

Permalink
Move eth_getTransactionCount to snake case
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifere authored and kclowes committed Feb 10, 2021
1 parent 158a6b9 commit 125c6ae
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ Methods

.. code-block:: python
>>> math_contract.functions.increment(5).buildTransaction({'nonce': web3.eth.getTransactionCount('0xF5...')})
>>> math_contract.functions.increment(5).buildTransaction({'nonce': web3.eth.get_transaction_count('0xF5...')})
Returns a transaction dictionary. This transaction dictionary can then be sent using
:meth:`~web3.eth.Eth.sendTransaction`.
Expand Down
2 changes: 1 addition & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ Just remember that you have to sign all transactions locally, as infura does not
transaction = contract.functions.function_Name(params).buildTransaction()
transaction.update({ 'gas' : appropriate_gas_amount })
transaction.update({ 'nonce' : w3.eth.getTransactionCount('Your_Wallet_Address') })
transaction.update({ 'nonce' : w3.eth.get_transaction_count('Your_Wallet_Address') })
signed_tx = w3.eth.account.signTransaction(transaction, private_key)
P.S : the two updates are done to the transaction dictionary, since a raw transaction might not contain gas & nonce amounts, so you have to add them manually.
Expand Down
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ API
- :meth:`web3.eth.get_storage_at() <web3.eth.Eth.get_storage_at>`
- :meth:`web3.eth.get_transaction() <web3.eth.Eth.get_transaction>`
- :meth:`web3.eth.get_transaction_by_block() <web3.eth.Eth.get_transaction_by_block>`
- :meth:`web3.eth.getTransactionCount() <web3.eth.Eth.getTransactionCount>`
- :meth:`web3.eth.get_transaction_count() <web3.eth.Eth.get_transaction_count>`
- :meth:`web3.eth.get_uncle_by_block() <web3.eth.Eth.get_uncle_by_block>`
- :meth:`web3.eth.get_uncle_count() <web3.eth.Eth.get_uncle_count>`

Expand Down
2 changes: 1 addition & 1 deletion docs/web3.eth.account.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ To sign a transaction locally that will invoke a smart contract:

>>> unicorns = w3.eth.contract(address="0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359", abi=EIP20_ABI)

>>> nonce = w3.eth.getTransactionCount('0x5ce9454909639D2D17A3F753ce7d93fa0b9aB12E') # doctest: +SKIP
>>> nonce = w3.eth.get_transaction_count('0x5ce9454909639D2D17A3F753ce7d93fa0b9aB12E') # doctest: +SKIP

# Build a transaction that invokes this contract's function, called transfer
>>> unicorn_txn = unicorns.functions.transfer(
Expand Down
12 changes: 9 additions & 3 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ The following methods are available on the ``web3.eth`` namespace.
})
.. py:method:: Eth.getTransactionCount(account, block_identifier=web3.eth.default_block)
.. py:method:: Eth.get_transaction_count(account, block_identifier=web3.eth.default_block)
* Delegates to ``eth_getTransactionCount`` RPC Method

Expand All @@ -687,10 +687,16 @@ The following methods are available on the ``web3.eth`` namespace.

.. code-block:: python
>>> web3.eth.getTransactionCount('0xd3CdA913deB6f67967B99D67aCDFa1712C293601')
>>> web3.eth.get_transaction_count('0xd3CdA913deB6f67967B99D67aCDFa1712C293601')
340
.. py:method:: Eth.getTransactionCount(account, block_identifier=web3.eth.default_block)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.eth.Eth.get_transaction_count()`


.. py:method:: Eth.sendTransaction(transaction)
* Delegates to ``eth_sendTransaction`` RPC Method
Expand Down Expand Up @@ -739,7 +745,7 @@ The following methods are available on the ``web3.eth`` namespace.
.. code-block:: python
>>> signed_txn = w3.eth.signTransaction(dict(
nonce=w3.eth.getTransactionCount(w3.eth.coinbase),
nonce=w3.eth.get_transaction_count(w3.eth.coinbase),
gasPrice=w3.eth.gas_price,
gas=100000,
to='0xd3CdA913deB6f67967B99D67aCDFa1712C293601',
Expand Down
1 change: 1 addition & 0 deletions newsfragments/1844.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ``get_transaction_count``, and deprecated ``getTransactionCount``
6 changes: 3 additions & 3 deletions tests/core/contracts/test_contract_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_contract_constructor_build_transaction_no_constructor(
{'from': address_conversion_func(web3.eth.accounts[0])}
)
txn = web3.eth.get_transaction(txn_hash)
nonce = web3.eth.getTransactionCount(web3.eth.coinbase)
nonce = web3.eth.get_transaction_count(web3.eth.coinbase)
unsent_txn = MathContract.constructor().buildTransaction({'nonce': nonce})
assert txn['data'] == unsent_txn['data']

Expand All @@ -203,7 +203,7 @@ def test_contract_constructor_build_transaction_with_constructor_without_argumen
{'from': address_conversion_func(web3.eth.accounts[0])}
)
txn = web3.eth.get_transaction(txn_hash)
nonce = web3.eth.getTransactionCount(web3.eth.coinbase)
nonce = web3.eth.get_transaction_count(web3.eth.coinbase)
unsent_txn = MathContract.constructor().buildTransaction({'nonce': nonce})
assert txn['data'] == unsent_txn['data']

Expand Down Expand Up @@ -233,7 +233,7 @@ def test_contract_constructor_build_transaction_with_constructor_with_argument(
{'from': address_conversion_func(web3.eth.accounts[0])}
)
txn = web3.eth.get_transaction(txn_hash)
nonce = web3.eth.getTransactionCount(web3.eth.coinbase)
nonce = web3.eth.get_transaction_count(web3.eth.coinbase)
unsent_txn = WithConstructorArgumentsContract.constructor(
*constructor_args, **constructor_kwargs).buildTransaction({'nonce': nonce})
assert txn['data'] == unsent_txn['data']
Expand Down
10 changes: 5 additions & 5 deletions tests/ens/test_setup_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_set_address_equivalence(ens, name, equivalent, TEST_ADDRESS):
@pytest.mark.parametrize(
'set_address',
[
# since the test uses getTransactionCount,
# since the test uses get_transaction_count,
# using a same address converted to bytes and hex will error with same count,
# use two different addresses of each type (hex, bytes)
"0x000000000000000000000000000000000000dEaD",
Expand All @@ -115,11 +115,11 @@ def test_set_address_noop(ens, set_address):
eth = ens.web3.eth
owner = ens.owner('tester.eth')
ens.setup_address('noop.tester.eth', set_address)
starting_transactions = eth.getTransactionCount(owner)
starting_transactions = eth.get_transaction_count(owner)

# do not issue transaction if address is already set
ens.setup_address('noop.tester.eth', set_address)
assert eth.getTransactionCount(owner) == starting_transactions
assert eth.get_transaction_count(owner) == starting_transactions


def test_set_address_unauthorized(ens, TEST_ADDRESS):
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_set_resolver_leave_default(ens, TEST_ADDRESS):
owner = ens.owner('tester.eth')
ens.setup_address('leave-default-resolver.tester.eth', TEST_ADDRESS)
eth = ens.web3.eth
num_transactions = eth.getTransactionCount(owner)
num_transactions = eth.get_transaction_count(owner)

ens.setup_address(
'leave-default-resolver.tester.eth',
Expand All @@ -162,4 +162,4 @@ def test_set_resolver_leave_default(ens, TEST_ADDRESS):

# should skip setting the owner and setting the default resolver, and only
# set the name in the default resolver to point to the new address
assert eth.getTransactionCount(owner) == num_transactions + 1
assert eth.get_transaction_count(owner) == num_transactions + 1
4 changes: 2 additions & 2 deletions tests/ens/test_setup_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ def test_setup_reverse_dict_unmodified(ens):
# setup
owner = ens.owner('tester.eth')
eth = ens.web3.eth
start_count = eth.getTransactionCount(owner)
start_count = eth.get_transaction_count(owner)

address = ens.web3.eth.accounts[3]
transact = {}
ens.setup_name('tester.eth', address, transact=transact)

# even though a transaction was issued, the dict argument was not modified
assert eth.getTransactionCount(owner) > start_count
assert eth.get_transaction_count(owner) > start_count
assert transact == {}

# teardown
Expand Down
22 changes: 15 additions & 7 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,25 +220,33 @@ def test_eth_get_storage_at_invalid_address(self, web3: "Web3") -> None:
with pytest.raises(InvalidAddress):
web3.eth.get_storage_at(ChecksumAddress(HexAddress(HexStr(coinbase.lower()))), 0)

def test_eth_getTransactionCount(
def test_eth_get_transaction_count(
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
) -> None:
transaction_count = web3.eth.getTransactionCount(unlocked_account_dual_type)
transaction_count = web3.eth.get_transaction_count(unlocked_account_dual_type)
assert is_integer(transaction_count)
assert transaction_count >= 0

def test_eth_getTransactionCount_ens_name(
def test_eth_getTransactionCount_deprecated(
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
) -> None:
with pytest.warns(DeprecationWarning):
transaction_count = web3.eth.getTransactionCount(unlocked_account_dual_type)
assert is_integer(transaction_count)
assert transaction_count >= 0

def test_eth_get_transaction_count_ens_name(
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
) -> None:
with ens_addresses(web3, {'unlocked-acct-dual-type.eth': unlocked_account_dual_type}):
transaction_count = web3.eth.getTransactionCount('unlocked-acct-dual-type.eth')
transaction_count = web3.eth.get_transaction_count('unlocked-acct-dual-type.eth')
assert is_integer(transaction_count)
assert transaction_count >= 0

def test_eth_getTransactionCount_invalid_address(self, web3: "Web3") -> None:
def test_eth_get_transaction_count_invalid_address(self, web3: "Web3") -> None:
coinbase = web3.eth.coinbase
with pytest.raises(InvalidAddress):
web3.eth.getTransactionCount(ChecksumAddress(HexAddress(HexStr(coinbase.lower()))))
web3.eth.get_transaction_count(ChecksumAddress(HexAddress(HexStr(coinbase.lower()))))

def test_eth_getBlockTransactionCountByHash_empty_block(
self, web3: "Web3", empty_block: BlockData
Expand Down Expand Up @@ -597,7 +605,7 @@ def test_eth_sendTransaction_with_nonce(
'gas': Wei(21000),
# Increased gas price to ensure transaction hash different from other tests
'gasPrice': Wei(web3.eth.gas_price * 3),
'nonce': web3.eth.getTransactionCount(unlocked_account),
'nonce': web3.eth.get_transaction_count(unlocked_account),
}
txn_hash = web3.eth.sendTransaction(txn_params)
txn = web3.eth.get_transaction(txn_hash)
Expand Down
2 changes: 1 addition & 1 deletion web3/_utils/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def fill_nonce(web3: "Web3", transaction: TxParams) -> TxParams:
return assoc(
transaction,
'nonce',
web3.eth.getTransactionCount(
web3.eth.get_transaction_count(
cast(ChecksumAddress, transaction['from']),
block_identifier='pending'))
else:
Expand Down
7 changes: 6 additions & 1 deletion web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ def waitForTransactionReceipt(
mungers=[default_root_munger]
)

getTransactionCount: Method[Callable[..., Nonce]] = Method(
get_transaction_count: Method[Callable[..., Nonce]] = Method(


RPC.eth_getTransactionCount,
mungers=[block_id_munger],
)
Expand Down Expand Up @@ -659,5 +661,8 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None:
getTransactionByBlock = DeprecatedMethod(get_transaction_by_block,
'getTransactionByBlock',
'get_transaction_by_block')
getTransactionCount = DeprecatedMethod(get_transaction_count,
'getTransactionCount',
'get_transaction_count')
getUncleByBlock = DeprecatedMethod(get_uncle_by_block, 'getUncleByBlock', 'get_uncle_by_block')
getUncleCount = DeprecatedMethod(get_uncle_count, 'getUncleCount', 'get_uncle_count')

0 comments on commit 125c6ae

Please sign in to comment.