From 1c2b3cae445c333d0bb663d515c3e019ed589a4c Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Fri, 8 Mar 2019 17:22:42 +0100 Subject: [PATCH] Remove error raising on all jsonrpc none responses --- ...est_latest_block_based_cache_middleware.py | 9 +- .../test_simple_cache_middleware.py | 6 +- .../test_time_based_cache_middleware.py | 6 +- .../test_testing_snapshot_and_revert.py | 6 +- .../testing-module/test_testing_timeTravel.py | 3 +- web3/_utils/module_testing/parity_module.py | 4 +- web3/eth.py | 84 +++++++++---------- web3/manager.py | 3 - 8 files changed, 54 insertions(+), 67 deletions(-) diff --git a/tests/core/middleware/test_latest_block_based_cache_middleware.py b/tests/core/middleware/test_latest_block_based_cache_middleware.py index f13a269d77..090682ccec 100644 --- a/tests/core/middleware/test_latest_block_based_cache_middleware.py +++ b/tests/core/middleware/test_latest_block_based_cache_middleware.py @@ -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. @@ -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 diff --git a/tests/core/middleware/test_simple_cache_middleware.py b/tests/core/middleware/test_simple_cache_middleware.py index ef17ab0238..2f09a10ff9 100644 --- a/tests/core/middleware/test_simple_cache_middleware.py +++ b/tests/core/middleware/test_simple_cache_middleware.py @@ -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 diff --git a/tests/core/middleware/test_time_based_cache_middleware.py b/tests/core/middleware/test_time_based_cache_middleware.py index 5095255068..968160171f 100644 --- a/tests/core/middleware/test_time_based_cache_middleware.py +++ b/tests/core/middleware/test_time_based_cache_middleware.py @@ -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 diff --git a/tests/core/testing-module/test_testing_snapshot_and_revert.py b/tests/core/testing-module/test_testing_snapshot_and_revert.py index 3ea745b935..b6ac639deb 100644 --- a/tests/core/testing-module/test_testing_snapshot_and_revert.py +++ b/tests/core/testing-module/test_testing_snapshot_and_revert.py @@ -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") @@ -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") diff --git a/tests/core/testing-module/test_testing_timeTravel.py b/tests/core/testing-module/test_testing_timeTravel.py index 95d1352246..8551643765 100644 --- a/tests/core/testing-module/test_testing_timeTravel.py +++ b/tests/core/testing-module/test_testing_timeTravel.py @@ -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 diff --git a/web3/_utils/module_testing/parity_module.py b/web3/_utils/module_testing/parity_module.py index f21ffc1ed2..75eeb5f4f5 100644 --- a/web3/_utils/module_testing/parity_module.py +++ b/web3/_utils/module_testing/parity_module.py @@ -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']) diff --git a/web3/eth.py b/web3/eth.py index 7f75a5baa7..c6d41d33e7 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -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): """ @@ -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): """ @@ -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): """ @@ -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): @@ -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: @@ -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: diff --git a/web3/manager.py b/web3/manager.py index f94b7bcb2e..bb0d186794 100644 --- a/web3/manager.py +++ b/web3/manager.py @@ -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):