Skip to content

Commit bd899fc

Browse files
committed
Remove error raising on all jsonrpc none responses
1 parent 1fe239d commit bd899fc

File tree

8 files changed

+54
-73
lines changed

8 files changed

+54
-73
lines changed

tests/core/middleware/test_latest_block_based_cache_middleware.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ def test_latest_block_based_cache_middleware_busts_cache(w3, mocker):
182182
result = w3.manager.request_blocking('fake_endpoint', [])
183183

184184
assert w3.manager.request_blocking('fake_endpoint', []) == result
185-
with pytest.raises(ValueError):
186-
w3.testing.mine()
185+
w3.testing.mine()
187186

188187
# should still be cached for at least 1 second. This also verifies that
189188
# the middleware caches the latest block based on the block time.
@@ -212,10 +211,8 @@ def result_cb(method, params):
212211
}))
213212
w3.middleware_onion.add(latest_block_based_cache_middleware)
214213

215-
with pytest.raises(ValueError):
216-
w3.manager.request_blocking('fake_endpoint', [])
217-
with pytest.raises(ValueError):
218-
w3.manager.request_blocking('fake_endpoint', [])
214+
w3.manager.request_blocking('fake_endpoint', [])
215+
w3.manager.request_blocking('fake_endpoint', [])
219216

220217
assert next(counter) == 2
221218

tests/core/middleware/test_simple_cache_middleware.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ def result_cb(method, params):
7878
rpc_whitelist={'fake_endpoint'},
7979
))
8080

81-
with pytest.raises(ValueError):
82-
w3.manager.request_blocking('fake_endpoint', [])
83-
with pytest.raises(ValueError):
84-
w3.manager.request_blocking('fake_endpoint', [])
81+
w3.manager.request_blocking('fake_endpoint', [])
82+
w3.manager.request_blocking('fake_endpoint', [])
8583

8684
assert next(counter) == 2
8785

tests/core/middleware/test_time_based_cache_middleware.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,8 @@ def mk_result(method, params):
117117
w3.middleware_onion.add(construct_result_generator_middleware({'fake_endpoint': mk_result}))
118118
w3.middleware_onion.add(time_cache_middleware)
119119

120-
with pytest.raises(ValueError):
121-
w3.manager.request_blocking('fake_endpoint', [])
122-
with pytest.raises(ValueError):
123-
w3.manager.request_blocking('fake_endpoint', [])
120+
w3.manager.request_blocking('fake_endpoint', [])
121+
w3.manager.request_blocking('fake_endpoint', [])
124122

125123
assert next(counter) == 2
126124

tests/core/testing-module/test_testing_snapshot_and_revert.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import pytest
2-
3-
41
def test_snapshot_revert_to_latest_snapshot(web3):
52
web3.testing.mine(5)
63

@@ -14,8 +11,7 @@ def test_snapshot_revert_to_latest_snapshot(web3):
1411

1512
block_after_mining = web3.eth.getBlock("latest")
1613

17-
with pytest.raises(ValueError):
18-
web3.testing.revert()
14+
web3.testing.revert()
1915

2016
block_after_revert = web3.eth.getBlock("latest")
2117

@@ -42,8 +38,7 @@ def test_snapshot_revert_to_specific(web3):
4238

4339
block_after_mining = web3.eth.getBlock("latest")
4440

45-
with pytest.raises(ValueError):
46-
web3.testing.revert(snapshot_idx)
41+
web3.testing.revert(snapshot_idx)
4742

4843
block_after_revert = web3.eth.getBlock("latest")
4944

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import pytest
2-
3-
41
def test_time_traveling(web3):
52
current_block_time = web3.eth.getBlock("pending")['timestamp']
63

74
time_travel_to = current_block_time + 12345
85

9-
with pytest.raises(ValueError):
10-
web3.testing.timeTravel(time_travel_to)
6+
web3.testing.timeTravel(time_travel_to)
117

128
latest_block_time = web3.eth.getBlock("pending")['timestamp']
139
assert latest_block_time >= time_travel_to

web3/_utils/module_testing/parity_module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
class ParityModuleTest:
1313

1414
def test_list_storage_keys_no_support(self, web3, emitter_contract_address):
15-
with pytest.raises(ValueError):
16-
web3.parity.listStorageKeys(emitter_contract_address, 10, None)
15+
keys = web3.parity.listStorageKeys(emitter_contract_address, 10, None)
16+
assert keys is None
1717

1818
def test_trace_replay_transaction(self, web3, parity_fixture_data):
1919
trace = web3.parity.traceReplayTransaction(parity_fixture_data['mined_txn_hash'])

web3/eth.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ def getBlock(self, block_identifier, full_transactions=False):
144144
if_number='eth_getBlockByNumber',
145145
)
146146

147-
try:
148-
return self.web3.manager.request_blocking(
149-
method,
150-
[block_identifier, full_transactions],
151-
)
152-
except ValueError:
147+
result = self.web3.manager.request_blocking(
148+
method,
149+
[block_identifier, full_transactions],
150+
)
151+
if result is None:
153152
raise BlockNotFound(f"Block with id: {block_identifier} not found.")
153+
return result
154154

155155
def getBlockTransactionCount(self, block_identifier):
156156
"""
@@ -163,13 +163,13 @@ def getBlockTransactionCount(self, block_identifier):
163163
if_hash='eth_getBlockTransactionCountByHash',
164164
if_number='eth_getBlockTransactionCountByNumber',
165165
)
166-
try:
167-
return self.web3.manager.request_blocking(
168-
method,
169-
[block_identifier],
170-
)
171-
except ValueError:
166+
result = self.web3.manager.request_blocking(
167+
method,
168+
[block_identifier],
169+
)
170+
if result is None:
172171
raise BlockNotFound(f"Block with id: {block_identifier} not found.")
172+
return result
173173

174174
def getUncleCount(self, block_identifier):
175175
"""
@@ -182,13 +182,13 @@ def getUncleCount(self, block_identifier):
182182
if_hash='eth_getUncleCountByBlockHash',
183183
if_number='eth_getUncleCountByBlockNumber',
184184
)
185-
try:
186-
return self.web3.manager.request_blocking(
187-
method,
188-
[block_identifier],
189-
)
190-
except ValueError:
185+
result = self.web3.manager.request_blocking(
186+
method,
187+
[block_identifier],
188+
)
189+
if result is None:
191190
raise BlockNotFound(f"Block with id: {block_identifier} not found.")
191+
return result
192192

193193
def getUncleByBlock(self, block_identifier, uncle_index):
194194
"""
@@ -201,24 +201,24 @@ def getUncleByBlock(self, block_identifier, uncle_index):
201201
if_hash='eth_getUncleByBlockHashAndIndex',
202202
if_number='eth_getUncleByBlockNumberAndIndex',
203203
)
204-
try:
205-
return self.web3.manager.request_blocking(
206-
method,
207-
[block_identifier, uncle_index],
208-
)
209-
except ValueError:
204+
result = self.web3.manager.request_blocking(
205+
method,
206+
[block_identifier, uncle_index],
207+
)
208+
if result is None:
210209
raise BlockNotFound(
211210
f"Uncle at index: {uncle_index} of block with id: {block_identifier} not found."
212211
)
212+
return result
213213

214214
def getTransaction(self, transaction_hash):
215-
try:
216-
return self.web3.manager.request_blocking(
217-
"eth_getTransactionByHash",
218-
[transaction_hash],
219-
)
220-
except ValueError:
215+
result = self.web3.manager.request_blocking(
216+
"eth_getTransactionByHash",
217+
[transaction_hash],
218+
)
219+
if result is None:
221220
raise TransactionNotFound(f"Transaction with hash: {transaction_hash} not found.")
221+
return result
222222

223223
@deprecated_for("w3.eth.getTransactionByBlock")
224224
def getTransactionFromBlock(self, block_identifier, transaction_index):
@@ -239,16 +239,16 @@ def getTransactionByBlock(self, block_identifier, transaction_index):
239239
if_hash='eth_getTransactionByBlockHashAndIndex',
240240
if_number='eth_getTransactionByBlockNumberAndIndex',
241241
)
242-
try:
243-
return self.web3.manager.request_blocking(
244-
method,
245-
[block_identifier, transaction_index],
246-
)
247-
except ValueError:
242+
result = self.web3.manager.request_blocking(
243+
method,
244+
[block_identifier, transaction_index],
245+
)
246+
if result is None:
248247
raise TransactionNotFound(
249248
f"Transaction index: {transaction_index} "
250249
f"on block id: {block_identifier} not found."
251250
)
251+
return result
252252

253253
def waitForTransactionReceipt(self, transaction_hash, timeout=120):
254254
try:
@@ -262,13 +262,13 @@ def waitForTransactionReceipt(self, transaction_hash, timeout=120):
262262
)
263263

264264
def getTransactionReceipt(self, transaction_hash):
265-
try:
266-
return self.web3.manager.request_blocking(
267-
"eth_getTransactionReceipt",
268-
[transaction_hash],
269-
)
270-
except ValueError:
265+
result = self.web3.manager.request_blocking(
266+
"eth_getTransactionReceipt",
267+
[transaction_hash],
268+
)
269+
if result is None:
271270
raise TransactionNotFound(f"Transaction with hash: {transaction_hash} not found.")
271+
return result
272272

273273
def getTransactionCount(self, account, block_identifier=None):
274274
if block_identifier is None:

web3/manager.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ def request_blocking(self, method, params):
9696
if "error" in response:
9797
raise ValueError(response["error"])
9898

99-
if response['result'] is None:
100-
raise ValueError(f"The call to {method} did not return a value.")
101-
10299
return response['result']
103100

104101
async def coro_request(self, method, params):

0 commit comments

Comments
 (0)