Skip to content

Commit

Permalink
Remove error raising on all jsonrpc none responses
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Mar 8, 2019
1 parent 1fe239d commit 1c2b3ca
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ def test_latest_block_based_cache_middleware_busts_cache(w3, mocker):
result = w3.manager.request_blocking('fake_endpoint', [])

assert w3.manager.request_blocking('fake_endpoint', []) == result
with pytest.raises(ValueError):
w3.testing.mine()
w3.testing.mine()

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

with pytest.raises(ValueError):
w3.manager.request_blocking('fake_endpoint', [])
with pytest.raises(ValueError):
w3.manager.request_blocking('fake_endpoint', [])
w3.manager.request_blocking('fake_endpoint', [])
w3.manager.request_blocking('fake_endpoint', [])

assert next(counter) == 2

Expand Down
6 changes: 2 additions & 4 deletions tests/core/middleware/test_simple_cache_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ def result_cb(method, params):
rpc_whitelist={'fake_endpoint'},
))

with pytest.raises(ValueError):
w3.manager.request_blocking('fake_endpoint', [])
with pytest.raises(ValueError):
w3.manager.request_blocking('fake_endpoint', [])
w3.manager.request_blocking('fake_endpoint', [])
w3.manager.request_blocking('fake_endpoint', [])

assert next(counter) == 2

Expand Down
6 changes: 2 additions & 4 deletions tests/core/middleware/test_time_based_cache_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ def mk_result(method, params):
w3.middleware_onion.add(construct_result_generator_middleware({'fake_endpoint': mk_result}))
w3.middleware_onion.add(time_cache_middleware)

with pytest.raises(ValueError):
w3.manager.request_blocking('fake_endpoint', [])
with pytest.raises(ValueError):
w3.manager.request_blocking('fake_endpoint', [])
w3.manager.request_blocking('fake_endpoint', [])
w3.manager.request_blocking('fake_endpoint', [])

assert next(counter) == 2

Expand Down
6 changes: 2 additions & 4 deletions tests/core/testing-module/test_testing_snapshot_and_revert.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def test_snapshot_revert_to_latest_snapshot(web3):

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

with pytest.raises(ValueError):
web3.testing.revert()
web3.testing.revert()

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

Expand All @@ -42,8 +41,7 @@ def test_snapshot_revert_to_specific(web3):

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

with pytest.raises(ValueError):
web3.testing.revert(snapshot_idx)
web3.testing.revert(snapshot_idx)

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

Expand Down
3 changes: 1 addition & 2 deletions tests/core/testing-module/test_testing_timeTravel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ def test_time_traveling(web3):

time_travel_to = current_block_time + 12345

with pytest.raises(ValueError):
web3.testing.timeTravel(time_travel_to)
web3.testing.timeTravel(time_travel_to)

latest_block_time = web3.eth.getBlock("pending")['timestamp']
assert latest_block_time >= time_travel_to
4 changes: 2 additions & 2 deletions web3/_utils/module_testing/parity_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
class ParityModuleTest:

def test_list_storage_keys_no_support(self, web3, emitter_contract_address):
with pytest.raises(ValueError):
web3.parity.listStorageKeys(emitter_contract_address, 10, None)
keys = web3.parity.listStorageKeys(emitter_contract_address, 10, None)
assert keys is None

def test_trace_replay_transaction(self, web3, parity_fixture_data):
trace = web3.parity.traceReplayTransaction(parity_fixture_data['mined_txn_hash'])
Expand Down
84 changes: 42 additions & 42 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ def getBlock(self, block_identifier, full_transactions=False):
if_number='eth_getBlockByNumber',
)

try:
return self.web3.manager.request_blocking(
method,
[block_identifier, full_transactions],
)
except ValueError:
result = self.web3.manager.request_blocking(
method,
[block_identifier, full_transactions],
)
if result is None:
raise BlockNotFound(f"Block with id: {block_identifier} not found.")
return result

def getBlockTransactionCount(self, block_identifier):
"""
Expand All @@ -163,13 +163,13 @@ def getBlockTransactionCount(self, block_identifier):
if_hash='eth_getBlockTransactionCountByHash',
if_number='eth_getBlockTransactionCountByNumber',
)
try:
return self.web3.manager.request_blocking(
method,
[block_identifier],
)
except ValueError:
result = self.web3.manager.request_blocking(
method,
[block_identifier],
)
if result is None:
raise BlockNotFound(f"Block with id: {block_identifier} not found.")
return result

def getUncleCount(self, block_identifier):
"""
Expand All @@ -182,13 +182,13 @@ def getUncleCount(self, block_identifier):
if_hash='eth_getUncleCountByBlockHash',
if_number='eth_getUncleCountByBlockNumber',
)
try:
return self.web3.manager.request_blocking(
method,
[block_identifier],
)
except ValueError:
result = self.web3.manager.request_blocking(
method,
[block_identifier],
)
if result is None:
raise BlockNotFound(f"Block with id: {block_identifier} not found.")
return result

def getUncleByBlock(self, block_identifier, uncle_index):
"""
Expand All @@ -201,24 +201,24 @@ def getUncleByBlock(self, block_identifier, uncle_index):
if_hash='eth_getUncleByBlockHashAndIndex',
if_number='eth_getUncleByBlockNumberAndIndex',
)
try:
return self.web3.manager.request_blocking(
method,
[block_identifier, uncle_index],
)
except ValueError:
result = self.web3.manager.request_blocking(
method,
[block_identifier, uncle_index],
)
if result is None:
raise BlockNotFound(
f"Uncle at index: {uncle_index} of block with id: {block_identifier} not found."
)
return result

def getTransaction(self, transaction_hash):
try:
return self.web3.manager.request_blocking(
"eth_getTransactionByHash",
[transaction_hash],
)
except ValueError:
result = self.web3.manager.request_blocking(
"eth_getTransactionByHash",
[transaction_hash],
)
if result is None:
raise TransactionNotFound(f"Transaction with hash: {transaction_hash} not found.")
return result

@deprecated_for("w3.eth.getTransactionByBlock")
def getTransactionFromBlock(self, block_identifier, transaction_index):
Expand All @@ -239,16 +239,16 @@ def getTransactionByBlock(self, block_identifier, transaction_index):
if_hash='eth_getTransactionByBlockHashAndIndex',
if_number='eth_getTransactionByBlockNumberAndIndex',
)
try:
return self.web3.manager.request_blocking(
method,
[block_identifier, transaction_index],
)
except ValueError:
result = self.web3.manager.request_blocking(
method,
[block_identifier, transaction_index],
)
if result is None:
raise TransactionNotFound(
f"Transaction index: {transaction_index} "
f"on block id: {block_identifier} not found."
)
return result

def waitForTransactionReceipt(self, transaction_hash, timeout=120):
try:
Expand All @@ -262,13 +262,13 @@ def waitForTransactionReceipt(self, transaction_hash, timeout=120):
)

def getTransactionReceipt(self, transaction_hash):
try:
return self.web3.manager.request_blocking(
"eth_getTransactionReceipt",
[transaction_hash],
)
except ValueError:
result = self.web3.manager.request_blocking(
"eth_getTransactionReceipt",
[transaction_hash],
)
if result is None:
raise TransactionNotFound(f"Transaction with hash: {transaction_hash} not found.")
return result

def getTransactionCount(self, account, block_identifier=None):
if block_identifier is None:
Expand Down
3 changes: 0 additions & 3 deletions web3/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ def request_blocking(self, method, params):
if "error" in response:
raise ValueError(response["error"])

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

return response['result']

async def coro_request(self, method, params):
Expand Down

0 comments on commit 1c2b3ca

Please sign in to comment.