Skip to content

Commit

Permalink
Raise exceptions in getBlock/getTransaction if result from rpc call i…
Browse files Browse the repository at this point in the history
…s none
  • Loading branch information
njgheorghita committed Jan 18, 2019
1 parent b1c0930 commit 0cb275b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0cb275b

Please sign in to comment.