diff --git a/docs/overview.rst b/docs/overview.rst index fab196ee3e..55246238b6 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -173,7 +173,7 @@ API - :meth:`web3.eth.send_transaction() ` - :meth:`web3.eth.sign_transaction() ` - :meth:`web3.eth.send_raw_transaction() ` -- :meth:`web3.eth.replaceTransaction() ` +- :meth:`web3.eth.replace_transaction() ` - :meth:`web3.eth.modifyTransaction() ` - :meth:`web3.eth.waitForTransactionReceipt() ` - :meth:`web3.eth.getTransactionReceipt() ` diff --git a/docs/web3.eth.rst b/docs/web3.eth.rst index fadfc4da02..ddb5db53f7 100644 --- a/docs/web3.eth.rst +++ b/docs/web3.eth.rst @@ -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) @@ -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` @@ -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) @@ -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) @@ -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 @@ -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) @@ -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. diff --git a/newsfragments/1882.feature.rst b/newsfragments/1882.feature.rst new file mode 100644 index 0000000000..2ea44f9064 --- /dev/null +++ b/newsfragments/1882.feature.rst @@ -0,0 +1 @@ +Add ``w3.eth.replace_transaction`` deprecate ``w3.eth.replaceTransaction`` diff --git a/tests/integration/go_ethereum/common.py b/tests/integration/go_ethereum/common.py index e5e19d922b..586e55d479 100644 --- a/tests/integration/go_ethereum/common.py +++ b/tests/integration/go_ethereum/common.py @@ -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') diff --git a/tests/integration/parity/common.py b/tests/integration/parity/common.py index 6940459318..3155569b19 100644 --- a/tests/integration/parity/common.py +++ b/tests/integration/parity/common.py @@ -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): diff --git a/tests/integration/test_ethereum_tester.py b/tests/integration/test_ethereum_tester.py index b872416b5e..ca0210eccb 100644 --- a/tests/integration/test_ethereum_tester.py +++ b/tests/integration/test_ethereum_tester.py @@ -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 ) diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index 5f396567bd..eb63a9b443 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -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 = { @@ -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'])) @@ -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 = { @@ -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 = { @@ -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 = { @@ -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 = { @@ -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 = { @@ -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 = { @@ -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 = { @@ -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( diff --git a/web3/eth.py b/web3/eth.py index 0d0fc11da1..e3a005cd3e 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -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, @@ -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)