diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index 6062c9ccf2..561621b7ce 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -485,8 +485,8 @@ def test_eth_getBlockByHash(self, web3, empty_block): assert block['hash'] == empty_block['hash'] def test_eth_getBlockByHash_not_found(self, web3, empty_block): - block = web3.eth.getBlock(UNKNOWN_HASH) - assert block is None + with pytest.raises(ValueError): + web3.eth.getBlock(UNKNOWN_HASH) def test_eth_getBlockByNumber_with_integer(self, web3, empty_block): block = web3.eth.getBlock(empty_block['number']) @@ -498,8 +498,8 @@ def test_eth_getBlockByNumber_latest(self, web3, empty_block): assert block['number'] == current_block_number def test_eth_getBlockByNumber_not_found(self, web3, empty_block): - block = web3.eth.getBlock(12345) - assert block is None + with pytest.raises(ValueError): + web3.eth.getBlock(12345) def test_eth_getBlockByNumber_pending(self, web3, empty_block): current_block_number = web3.eth.blockNumber diff --git a/web3/eth.py b/web3/eth.py index dfd377eead..2ef0d4fc2c 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -142,10 +142,13 @@ def getBlock(self, block_identifier, full_transactions=False): if_number='eth_getBlockByNumber', ) - return self.web3.manager.request_blocking( + result = self.web3.manager.request_blocking( method, [block_identifier, full_transactions], ) + if result: + return result + raise ValueError(f"The call to {method} did not return a value.") def getBlockTransactionCount(self, block_identifier): """ @@ -196,10 +199,13 @@ def getUncleByBlock(self, block_identifier, uncle_index): ) def getTransaction(self, transaction_hash): - return self.web3.manager.request_blocking( + result = self.web3.manager.request_blocking( "eth_getTransactionByHash", [transaction_hash], ) + if result: + return result + raise ValueError("The call to eth_getTransactionByHash did not return a value.") @deprecated_for("w3.eth.getTransactionByBlock") def getTransactionFromBlock(self, block_identifier, transaction_index):