Skip to content

Commit e4f46cf

Browse files
authored
Merge pull request #1270 from njgheorghita/refactor-jsonrpc-endpoints
Deprecate endpoints according to updated spec
2 parents 0cb2dc0 + 889c1cf commit e4f46cf

File tree

10 files changed

+35
-69
lines changed

10 files changed

+35
-69
lines changed

docs/web3.eth.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ The following methods are available on the ``web3.eth`` namespace.
332332
333333
.. py:method:: Eth.getTransactionFromBlock(block_identifier, transaction_index)
334334
335-
.. note:: This method is deprecated and replaced by
336-
``Eth.getTransactionByBlock``
335+
.. note:: This method is deprecated in EIP 1474.
337336

338337

339338
.. py:method:: Eth.getTransactionByBlock(block_identifier, transaction_index)

docs/web3.net.rst

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,8 @@ Properties
1515

1616
The following properties are available on the ``web3.net`` namespace.
1717

18-
.. py:method:: Net.chainId(self)
19-
20-
This method is trivially implemented.
21-
It will always return `None`, which is a valid chainId to specify in the transaction.
22-
23-
If you want the real chainId of your node, you must manually determine it for now.
24-
25-
Note that your transactions (may be) replayable on forks of the network you intend, if
26-
:ref:`eth-account` and using a chainId of `None`.
27-
28-
.. code-block:: python
29-
30-
>>> web3.net.chainId
31-
None
18+
.. py:method:: Net.chainId(self)
19+
This method is deprecated as of EIP 1474.
3220

3321
.. py:method:: Net.version(self)
3422

tests/core/contracts/test_contract_buildTransaction.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_build_transaction_not_paying_to_nonpayable_function(
5757
'data': '0xe4cb8f5c',
5858
'value': 0,
5959
'gasPrice': 1,
60-
'chainId': None,
60+
'chainId': 1,
6161
}
6262

6363

@@ -78,7 +78,7 @@ def test_build_transaction_with_contract_no_arguments(web3, math_contract, build
7878
'data': '0xd09de08a',
7979
'value': 0,
8080
'gasPrice': 1,
81-
'chainId': None,
81+
'chainId': 1,
8282
}
8383

8484

@@ -89,7 +89,7 @@ def test_build_transaction_with_contract_fallback_function(web3, fallback_functi
8989
'data': '0x',
9090
'value': 0,
9191
'gasPrice': 1,
92-
'chainId': None,
92+
'chainId': 1,
9393
}
9494

9595

@@ -108,7 +108,7 @@ def test_build_transaction_with_contract_class_method(
108108
'data': '0xd09de08a',
109109
'value': 0,
110110
'gasPrice': 1,
111-
'chainId': None,
111+
'chainId': 1,
112112
}
113113

114114

@@ -122,7 +122,7 @@ def test_build_transaction_with_contract_default_account_is_set(
122122
'data': '0xd09de08a',
123123
'value': 0,
124124
'gasPrice': 1,
125-
'chainId': None,
125+
'chainId': 1,
126126
}
127127

128128

@@ -136,7 +136,7 @@ def my_gas_price_strategy(web3, transaction_params):
136136
'data': '0xd09de08a',
137137
'value': 0,
138138
'gasPrice': 5,
139-
'chainId': None,
139+
'chainId': 1,
140140
}
141141

142142

@@ -164,31 +164,31 @@ def test_build_transaction_with_contract_to_address_supplied_errors(web3,
164164
(
165165
{}, (5,), {}, {
166166
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
167-
'value': 0, 'gasPrice': 1, 'chainId': None,
167+
'value': 0, 'gasPrice': 1, 'chainId': 1,
168168
}, False
169169
),
170170
(
171171
{'gas': 800000}, (5,), {}, {
172172
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
173-
'value': 0, 'gasPrice': 1, 'chainId': None,
173+
'value': 0, 'gasPrice': 1, 'chainId': 1,
174174
}, False
175175
),
176176
(
177177
{'gasPrice': 21000000000}, (5,), {}, {
178178
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
179-
'value': 0, 'gasPrice': 21000000000, 'chainId': None,
179+
'value': 0, 'gasPrice': 21000000000, 'chainId': 1,
180180
}, False
181181
),
182182
(
183183
{'nonce': 7}, (5,), {}, {
184184
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
185-
'value': 0, 'gasPrice': 1, 'nonce': 7, 'chainId': None,
185+
'value': 0, 'gasPrice': 1, 'nonce': 7, 'chainId': 1,
186186
}, True
187187
),
188188
(
189189
{'value': 20000}, (5,), {}, {
190190
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501
191-
'value': 20000, 'gasPrice': 1, 'chainId': None,
191+
'value': 20000, 'gasPrice': 1, 'chainId': 1,
192192
}, False
193193
),
194194
),

tests/core/eth-module/test_transactions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
'make_chain_id, expect_success',
1717
(
1818
(
19-
lambda web3: web3.net.chainId,
19+
lambda web3: web3.net.version,
2020
True,
2121
),
2222
pytest.param(
2323
lambda web3: 999999999999,
2424
False,
25-
marks=pytest.mark.xfail,
2625
),
2726
),
2827
)

web3/_utils/module_testing/eth_module.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -531,16 +531,6 @@ def test_eth_getTransactionByHash_contract_creation(self,
531531
assert is_dict(transaction)
532532
assert transaction['to'] is None, "to field is %r" % transaction['to']
533533

534-
def test_eth_getTransactionFromBlockHashAndIndex(self, web3, block_with_txn, mined_txn_hash):
535-
transaction = web3.eth.getTransactionFromBlock(block_with_txn['hash'], 0)
536-
assert is_dict(transaction)
537-
assert transaction['hash'] == HexBytes(mined_txn_hash)
538-
539-
def test_eth_getTransactionFromBlockNumberAndIndex(self, web3, block_with_txn, mined_txn_hash):
540-
transaction = web3.eth.getTransactionFromBlock(block_with_txn['number'], 0)
541-
assert is_dict(transaction)
542-
assert transaction['hash'] == HexBytes(mined_txn_hash)
543-
544534
def test_eth_getTransactionByBlockHashAndIndex(self, web3, block_with_txn, mined_txn_hash):
545535
transaction = web3.eth.getTransactionByBlock(block_with_txn['hash'], 0)
546536
assert is_dict(transaction)
@@ -600,22 +590,6 @@ def test_eth_getUncleByBlockNumberAndIndex(self, web3):
600590
# TODO: how do we make uncles....
601591
pass
602592

603-
def test_eth_getCompilers(self, web3):
604-
# TODO: do we want to test this?
605-
pass
606-
607-
def test_eth_compileSolidity(self, web3):
608-
# TODO: do we want to test this?
609-
pass
610-
611-
def test_eth_compileLLL(self, web3):
612-
# TODO: do we want to test this?
613-
pass
614-
615-
def test_eth_compileSerpent(self, web3):
616-
# TODO: do we want to test this?
617-
pass
618-
619593
def test_eth_newFilter(self, web3):
620594
filter = web3.eth.filter({})
621595

@@ -828,3 +802,11 @@ def test_eth_uninstallFilter(self, web3):
828802

829803
failure = web3.eth.uninstallFilter(filter.filter_id)
830804
assert failure is False
805+
806+
def test_eth_getTransactionFromBlock_deprecation(self, web3, block_with_txn):
807+
with pytest.raises(DeprecationWarning):
808+
web3.eth.getTransactionFromBlock(block_with_txn['hash'], 0)
809+
810+
def test_eth_getCompilers_deprecation(self, web3):
811+
with pytest.raises(DeprecationWarning):
812+
web3.eth.getCompilers()

web3/_utils/module_testing/net_module.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
from eth_utils import (
24
is_boolean,
35
is_integer,
@@ -21,3 +23,7 @@ def test_net_peerCount(self, web3):
2123
peer_count = web3.net.peerCount
2224

2325
assert is_integer(peer_count)
26+
27+
def test_net_chainId_deprecation(self, web3):
28+
with pytest.raises(DeprecationWarning):
29+
web3.net.chainId

web3/_utils/transactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
'data': b'',
2929
'gas': lambda web3, tx: web3.eth.estimateGas(tx),
3030
'gasPrice': lambda web3, tx: web3.eth.generateGasPrice(tx) or web3.eth.gasPrice,
31-
'chainId': lambda web3, tx: web3.net.chainId,
31+
'chainId': lambda web3, tx: int(web3.net.version),
3232
}
3333

3434

web3/eth.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
from web3._utils.blocks import (
1414
select_method_for_block_identifier,
1515
)
16-
from web3._utils.decorators import (
17-
deprecated_for,
18-
)
1916
from web3._utils.empty import (
2017
empty,
2118
)
@@ -66,10 +63,6 @@ class Eth(Module):
6663
iban = Iban
6764
gasPriceStrategy = None
6865

69-
@deprecated_for("doing nothing at all")
70-
def enable_unaudited_features(self):
71-
pass
72-
7366
def namereg(self):
7467
raise NotImplementedError()
7568

@@ -220,13 +213,12 @@ def getTransaction(self, transaction_hash):
220213
raise TransactionNotFound(f"Transaction with hash: {transaction_hash} not found.")
221214
return result
222215

223-
@deprecated_for("w3.eth.getTransactionByBlock")
224216
def getTransactionFromBlock(self, block_identifier, transaction_index):
225217
"""
226218
Alias for the method getTransactionByBlock
227219
Depreceated to maintain naming consistency with the json-rpc API
228220
"""
229-
return self.getTransactionByBlock(block_identifier, transaction_index)
221+
raise DeprecationWarning("This method has been deprecated as of EIP 1474.")
230222

231223
def getTransactionByBlock(self, block_identifier, transaction_index):
232224
"""
@@ -419,7 +411,7 @@ def setContractFactory(self, contractFactory):
419411
self.defaultContractFactory = contractFactory
420412

421413
def getCompilers(self):
422-
return self.web3.manager.request_blocking("eth_getCompilers", [])
414+
raise DeprecationWarning("This method has been deprecated as of EIP 1474.")
423415

424416
def getWork(self):
425417
return self.web3.manager.request_blocking("eth_getWork", [])

web3/middleware/validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
@curry
3131
def validate_chain_id(web3, chain_id):
32-
if chain_id == web3.net.chainId:
32+
if chain_id == web3.net.version:
3333
return chain_id
3434
else:
3535
raise ValidationError(
@@ -66,7 +66,7 @@ def transaction_param_validator(web3):
6666
transactions_params_validators = {
6767
'chainId': apply_formatter_if(
6868
# Bypass `validate_chain_id` if chainId can't be determined
69-
lambda _: is_not_null(web3.net.chainId),
69+
lambda _: is_not_null(web3.net.version),
7070
validate_chain_id(web3)
7171
),
7272
}

web3/net.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def peerCount(self):
1414

1515
@property
1616
def chainId(self):
17-
return None
17+
raise DeprecationWarning("This method has been deprecated in EIP 1474.")
1818

1919
@property
2020
def version(self):

0 commit comments

Comments
 (0)