Skip to content
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 @@ -173,7 +173,7 @@ API
- :meth:`web3.eth.send_transaction() <web3.eth.Eth.send_transaction>`
- :meth:`web3.eth.sign_transaction() <web3.eth.Eth.sign_transaction>`
- :meth:`web3.eth.send_raw_transaction() <web3.eth.Eth.send_raw_transaction>`
- :meth:`web3.eth.replaceTransaction() <web3.eth.Eth.replaceTransaction>`
- :meth:`web3.eth.replace_transaction() <web3.eth.Eth.replace_transaction>`
- :meth:`web3.eth.modifyTransaction() <web3.eth.Eth.modifyTransaction>`
- :meth:`web3.eth.waitForTransactionReceipt() <web3.eth.Eth.waitForTransactionReceipt>`
- :meth:`web3.eth.getTransactionReceipt() <web3.eth.Eth.getTransactionReceipt>`
Expand Down
20 changes: 12 additions & 8 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ The following methods are available on the ``web3.eth`` namespace.

.. py:method:: Eth.getUncleCount(block_identifier)

.. warning:: Deprecated: This property is deprecated in favor of
.. warning:: Deprecated: This method is deprecated in favor of
:attr:`~web3.eth.Eth.get_uncle_count()`

.. py:method:: Eth.get_transaction(transaction_hash)
Expand Down Expand Up @@ -556,7 +556,7 @@ The following methods are available on the ``web3.eth`` namespace.

.. py:method:: Eth.getTransaction(transaction_hash)

.. warning:: Deprecated: This property is deprecated in favor of
.. warning:: Deprecated: This method is deprecated in favor of
:attr:`~web3.eth.Eth.get_transaction`


Expand Down Expand Up @@ -736,7 +736,7 @@ The following methods are available on the ``web3.eth`` namespace.

.. py:method:: Eth.sendTransaction(transaction)

.. warning:: Deprecated: This property is deprecated in favor of
.. warning:: Deprecated: This method is deprecated in favor of
:attr:`~web3.eth.Eth.send_transaction()`

.. py:method:: Eth.sign_transaction(transaction)
Expand All @@ -762,7 +762,7 @@ The following methods are available on the ``web3.eth`` namespace.

.. py:method:: Eth.signTransaction(transaction)

.. warning:: Deprecated: This property is deprecated in favor of
.. warning:: Deprecated: This method is deprecated in favor of
:attr:`~web3.eth.Eth.sign_transaction()`

.. py:method:: Eth.send_raw_transaction(raw_transaction)
Expand All @@ -788,10 +788,10 @@ The following methods are available on the ``web3.eth`` namespace.

.. py:method:: Eth.sendRawTransaction(raw_transaction)

.. warning:: Deprecated: This property is deprecated in favor of
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.eth.Eth.send_raw_transaction()`

.. py:method:: Eth.replaceTransaction(transaction_hash, new_transaction)
.. py:method:: Eth.replace_transaction(transaction_hash, new_transaction)

* Delegates to ``eth_sendTransaction`` RPC Method

Expand Down Expand Up @@ -827,12 +827,16 @@ The following methods are available on the ``web3.eth`` namespace.
'value': 1000
})
'0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331'
>>> web3.eth.replaceTransaction('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', {
>>> web3.eth.replace_transaction('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', {
'to': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601',
'from': web3.eth.coinbase,
'value': 2000
})

.. py:method:: Eth.replaceTransaction(transaction_hash, new_transaction)

.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.eth.Eth.replace_transaction()`

.. py:method:: Eth.modifyTransaction(transaction_hash, **transaction_params)

Expand All @@ -845,7 +849,7 @@ The following methods are available on the ``web3.eth`` namespace.
will override the pending transaction's values to create the replacement transaction
to send.

The same validation and defaulting rules of :meth:`~web3.eth.Eth.replaceTransaction` apply.
The same validation and defaulting rules of :meth:`~web3.eth.Eth.replace_transaction` apply.

This method returns the transaction hash of the newly modified transaction.

Expand Down
1 change: 1 addition & 0 deletions newsfragments/1882.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``w3.eth.replace_transaction`` deprecate ``w3.eth.replaceTransaction``
4 changes: 2 additions & 2 deletions tests/integration/go_ethereum/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def test_eth_submitHashrate(self, web3):
raises=FuturesTimeoutError,
reason='Sometimes a TimeoutError is hit when waiting for the txn to be mined',
)
def test_eth_replaceTransaction_already_mined(self, web3, unlocked_account_dual_type):
def test_eth_replace_transaction_already_mined(self, web3, unlocked_account_dual_type):
web3.geth.miner.start()
super().test_eth_replaceTransaction_already_mined(web3, unlocked_account_dual_type)
super().test_eth_replace_transaction_already_mined(web3, unlocked_account_dual_type)
web3.geth.miner.stop()

@pytest.mark.xfail(reason='Block identifier has not been implemented in geth')
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/parity/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def test_eth_uninstallFilter(self, web3):
super().test_eth_uninstallFilter(web3)

@pytest.mark.xfail(reason='Parity is not setup to auto mine')
def test_eth_replaceTransaction_already_mined(self, web3, unlocked_account):
super().test_eth_replaceTransaction_already_mined(web3, unlocked_account)
def test_eth_replace_transaction_already_mined(self, web3, unlocked_account):
super().test_eth_replace_transaction_already_mined(web3, unlocked_account)

@flaky(max_runs=MAX_FLAKY_RUNS)
def test_eth_getTransactionReceipt_unmined(self, web3, unlocked_account):
Expand Down
46 changes: 25 additions & 21 deletions tests/integration/test_ethereum_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,39 +265,43 @@ def test_eth_getTransactionReceipt_unmined(self, eth_tester, web3, unlocked_acco
super().test_eth_getTransactionReceipt_unmined(web3, unlocked_account)

@disable_auto_mine
def test_eth_replaceTransaction(self, eth_tester, web3, unlocked_account):
super().test_eth_replaceTransaction(web3, unlocked_account)
def test_eth_replaceTransaction_deprecated(self, eth_tester, web3, unlocked_account):
super().test_eth_replaceTransaction_deprecated(web3, unlocked_account)

@disable_auto_mine
def test_eth_replaceTransaction_incorrect_nonce(self, eth_tester, web3, unlocked_account):
super().test_eth_replaceTransaction_incorrect_nonce(web3, unlocked_account)
def test_eth_replace_transaction(self, eth_tester, web3, unlocked_account):
super().test_eth_replace_transaction(web3, unlocked_account)

@disable_auto_mine
def test_eth_replaceTransaction_gas_price_too_low(self, eth_tester, web3, unlocked_account):
super().test_eth_replaceTransaction_gas_price_too_low(web3, unlocked_account)
def test_eth_replace_transaction_incorrect_nonce(self, eth_tester, web3, unlocked_account):
super().test_eth_replace_transaction_incorrect_nonce(web3, unlocked_account)

@disable_auto_mine
def test_eth_replaceTransaction_gas_price_defaulting_minimum(self,
eth_tester,
web3,
unlocked_account):
super().test_eth_replaceTransaction_gas_price_defaulting_minimum(web3, unlocked_account)
def test_eth_replace_transaction_gas_price_too_low(self, eth_tester, web3, unlocked_account):
super().test_eth_replace_transaction_gas_price_too_low(web3, unlocked_account)

@disable_auto_mine
def test_eth_replaceTransaction_gas_price_defaulting_strategy_higher(self,
eth_tester,
web3,
unlocked_account):
super().test_eth_replaceTransaction_gas_price_defaulting_strategy_higher(
def test_eth_replace_transaction_gas_price_defaulting_minimum(self,
eth_tester,
web3,
unlocked_account):
super().test_eth_replace_transaction_gas_price_defaulting_minimum(web3, unlocked_account)

@disable_auto_mine
def test_eth_replace_transaction_gas_price_defaulting_strategy_higher(self,
eth_tester,
web3,
unlocked_account):
super().test_eth_replace_transaction_gas_price_defaulting_strategy_higher(
web3, unlocked_account
)

@disable_auto_mine
def test_eth_replaceTransaction_gas_price_defaulting_strategy_lower(self,
eth_tester,
web3,
unlocked_account):
super().test_eth_replaceTransaction_gas_price_defaulting_strategy_lower(
def test_eth_replace_transaction_gas_price_defaulting_strategy_lower(self,
eth_tester,
web3,
unlocked_account):
super().test_eth_replace_transaction_gas_price_defaulting_strategy_lower(
web3, unlocked_account
)

Expand Down
60 changes: 43 additions & 17 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def test_eth_send_transaction_with_nonce(
assert txn['gasPrice'] == txn_params['gasPrice']
assert txn['nonce'] == txn_params['nonce']

def test_eth_replaceTransaction(
def test_eth_replace_transaction(
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
) -> None:
txn_params: TxParams = {
Expand All @@ -673,7 +673,7 @@ def test_eth_replaceTransaction(
txn_hash = web3.eth.send_transaction(txn_params)

txn_params['gasPrice'] = Wei(web3.eth.gas_price * 2)
replace_txn_hash = web3.eth.replaceTransaction(txn_hash, txn_params)
replace_txn_hash = web3.eth.replace_transaction(txn_hash, txn_params)
replace_txn = web3.eth.get_transaction(replace_txn_hash)

assert is_same_address(replace_txn['from'], cast(ChecksumAddress, txn_params['from']))
Expand All @@ -682,7 +682,33 @@ def test_eth_replaceTransaction(
assert replace_txn['gas'] == 21000
assert replace_txn['gasPrice'] == txn_params['gasPrice']

def test_eth_replaceTransaction_non_existing_transaction(
def test_eth_replaceTransaction_deprecated(
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
) -> None:
txn_params: TxParams = {
'from': unlocked_account_dual_type,
'to': unlocked_account_dual_type,
'value': Wei(1),
'gas': Wei(21000),
'gasPrice': web3.eth.gas_price,
}
txn_hash = web3.eth.send_transaction(txn_params)

txn_params['gasPrice'] = Wei(web3.eth.gas_price * 2)
with pytest.warns(
DeprecationWarning,
match="replaceTransaction is deprecated in favor of replace_transaction"
):
replace_txn_hash = web3.eth.replaceTransaction(txn_hash, txn_params)
replace_txn = web3.eth.get_transaction(replace_txn_hash)

assert is_same_address(replace_txn['from'], cast(ChecksumAddress, txn_params['from']))
assert is_same_address(replace_txn['to'], cast(ChecksumAddress, txn_params['to']))
assert replace_txn['value'] == 1
assert replace_txn['gas'] == 21000
assert replace_txn['gasPrice'] == txn_params['gasPrice']

def test_eth_replace_transaction_non_existing_transaction(
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
) -> None:
txn_params: TxParams = {
Expand All @@ -693,12 +719,12 @@ def test_eth_replaceTransaction_non_existing_transaction(
'gasPrice': web3.eth.gas_price,
}
with pytest.raises(TransactionNotFound):
web3.eth.replaceTransaction(
web3.eth.replace_transaction(
HexStr('0x98e8cc09b311583c5079fa600f6c2a3bea8611af168c52e4b60b5b243a441997'),
txn_params
)

def test_eth_replaceTransaction_already_mined(
def test_eth_replace_transaction_already_mined(
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
) -> None:
txn_params: TxParams = {
Expand All @@ -713,9 +739,9 @@ def test_eth_replaceTransaction_already_mined(

txn_params['gasPrice'] = Wei(web3.eth.gas_price * 2)
with pytest.raises(ValueError, match="Supplied transaction with hash"):
web3.eth.replaceTransaction(txn_hash, txn_params)
web3.eth.replace_transaction(txn_hash, txn_params)

def test_eth_replaceTransaction_incorrect_nonce(
def test_eth_replace_transaction_incorrect_nonce(
self, web3: "Web3", unlocked_account: ChecksumAddress
) -> None:
txn_params: TxParams = {
Expand All @@ -731,9 +757,9 @@ def test_eth_replaceTransaction_incorrect_nonce(
txn_params['gasPrice'] = Wei(web3.eth.gas_price * 2)
txn_params['nonce'] = Nonce(txn['nonce'] + 1)
with pytest.raises(ValueError):
web3.eth.replaceTransaction(txn_hash, txn_params)
web3.eth.replace_transaction(txn_hash, txn_params)

def test_eth_replaceTransaction_gas_price_too_low(
def test_eth_replace_transaction_gas_price_too_low(
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
) -> None:
txn_params: TxParams = {
Expand All @@ -747,9 +773,9 @@ def test_eth_replaceTransaction_gas_price_too_low(

txn_params['gasPrice'] = Wei(9)
with pytest.raises(ValueError):
web3.eth.replaceTransaction(txn_hash, txn_params)
web3.eth.replace_transaction(txn_hash, txn_params)

def test_eth_replaceTransaction_gas_price_defaulting_minimum(
def test_eth_replace_transaction_gas_price_defaulting_minimum(
self, web3: "Web3", unlocked_account: ChecksumAddress
) -> None:
txn_params: TxParams = {
Expand All @@ -762,12 +788,12 @@ def test_eth_replaceTransaction_gas_price_defaulting_minimum(
txn_hash = web3.eth.send_transaction(txn_params)

txn_params.pop('gasPrice')
replace_txn_hash = web3.eth.replaceTransaction(txn_hash, txn_params)
replace_txn_hash = web3.eth.replace_transaction(txn_hash, txn_params)
replace_txn = web3.eth.get_transaction(replace_txn_hash)

assert replace_txn['gasPrice'] == 12 # minimum gas price

def test_eth_replaceTransaction_gas_price_defaulting_strategy_higher(
def test_eth_replace_transaction_gas_price_defaulting_strategy_higher(
self, web3: "Web3", unlocked_account: ChecksumAddress
) -> None:
txn_params: TxParams = {
Expand All @@ -785,11 +811,11 @@ def higher_gas_price_strategy(web3: "Web3", txn: TxParams) -> Wei:
web3.eth.setGasPriceStrategy(higher_gas_price_strategy)

txn_params.pop('gasPrice')
replace_txn_hash = web3.eth.replaceTransaction(txn_hash, txn_params)
replace_txn_hash = web3.eth.replace_transaction(txn_hash, txn_params)
replace_txn = web3.eth.get_transaction(replace_txn_hash)
assert replace_txn['gasPrice'] == 20 # Strategy provides higher gas price

def test_eth_replaceTransaction_gas_price_defaulting_strategy_lower(
def test_eth_replace_transaction_gas_price_defaulting_strategy_lower(
self, web3: "Web3", unlocked_account: ChecksumAddress
) -> None:
txn_params: TxParams = {
Expand All @@ -807,9 +833,9 @@ def lower_gas_price_strategy(web3: "Web3", txn: TxParams) -> Wei:
web3.eth.setGasPriceStrategy(lower_gas_price_strategy)

txn_params.pop('gasPrice')
replace_txn_hash = web3.eth.replaceTransaction(txn_hash, txn_params)
replace_txn_hash = web3.eth.replace_transaction(txn_hash, txn_params)
replace_txn = web3.eth.get_transaction(replace_txn_hash)
# Strategy provices lower gas price - minimum preferred
# Strategy provides lower gas price - minimum preferred
assert replace_txn['gasPrice'] == 12

def test_eth_modifyTransaction(
Expand Down
7 changes: 7 additions & 0 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
from web3._utils.blocks import (
select_method_for_block_identifier,
)
from web3._utils.decorators import (
deprecated_for,
)
from web3._utils.empty import (
Empty,
empty,
Expand Down Expand Up @@ -439,7 +442,11 @@ def waitForTransactionReceipt(
mungers=[block_id_munger],
)

@deprecated_for("replace_transaction")
def replaceTransaction(self, transaction_hash: _Hash32, new_transaction: TxParams) -> HexBytes:
return self.replace_transaction(transaction_hash, new_transaction)

def replace_transaction(self, transaction_hash: _Hash32, new_transaction: TxParams) -> HexBytes:
current_transaction = get_required_transaction(self.web3, transaction_hash)
return replace_transaction(self.web3, current_transaction, new_transaction)

Expand Down