Skip to content

Commit

Permalink
Fix eth_getBalance integration and middleware tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Sep 15, 2020
1 parent dd5acc6 commit f0708ee
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 49 deletions.
26 changes: 12 additions & 14 deletions tests/core/gas-strategies/test_time_based_gas_price_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def _get_block_by_something(method, params):
block_identifier = params[0]
if (
block_identifier == 'latest' or
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000005' or
block_identifier == 5
block_identifier == '0x5'
):
return {
'hash': '0x0000000000000000000000000000000000000000000000000000000000000005',
Expand All @@ -35,12 +34,12 @@ def _get_block_by_something(method, params):
{'gasPrice': 5},
{'gasPrice': 50},
],
'miner': '0xA',
'miner': '0x' + 'AA' * 20,
'timestamp': 120,
}
elif (
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000004' or
block_identifier == 4
block_identifier == '0x4'
):
return {
'hash': '0x0000000000000000000000000000000000000000000000000000000000000004',
Expand All @@ -51,12 +50,12 @@ def _get_block_by_something(method, params):
{'gasPrice': 80},
{'gasPrice': 60},
],
'miner': '0xB',
'miner': '0x' + 'BB' * 20,
'timestamp': 90,
}
elif (
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000003' or
block_identifier == 3
block_identifier == '0x3'
):
return {
'hash': '0x0000000000000000000000000000000000000000000000000000000000000003',
Expand All @@ -65,25 +64,25 @@ def _get_block_by_something(method, params):
'transactions': [
{'gasPrice': 100},
],
'miner': '0xC',
'miner': '0x' + 'Cc' * 20,
'timestamp': 60,
}
elif (
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000002' or
block_identifier == 2
block_identifier == '0x2'
):
return {
'hash': '0x0000000000000000000000000000000000000000000000000000000000000002',
'number': 2,
'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000001',
'transactions': [
],
'miner': '0xB',
'miner': '0x' + 'Bb' * 20,
'timestamp': 30,
}
elif (
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000001' or
block_identifier == 1
block_identifier == '0x1'
):
return {
'hash': '0x0000000000000000000000000000000000000000000000000000000000000001',
Expand All @@ -94,12 +93,11 @@ def _get_block_by_something(method, params):
{'gasPrice': 35},
{'gasPrice': 65},
],
'miner': '0xA',
'miner': '0x' + 'Aa' * 20,
'timestamp': 15,
}
elif (
block_identifier == '0x0000000000000000000000000000000000000000000000000000000000000000' or
block_identifier == 0
block_identifier == '0x0'
):
return {
'hash': '0x0000000000000000000000000000000000000000000000000000000000000000',
Expand All @@ -119,7 +117,7 @@ def _get_block_by_something(method, params):
{'gasPrice': 54},
{'gasPrice': 10000000000000000000000},
],
'miner': '0xA',
'miner': '0x' + 'Aa' * 20,
'timestamp': 0,
}
else:
Expand Down
1 change: 1 addition & 0 deletions tests/core/middleware/test_filter_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def make_request(self, method, params):
BLOCK_HASH = '0xfe88c94d860f01a17f961bf4bdfb6e0c6cd10d3fda5cc861e805ca1240c58553'
FILTER_LOG = [AttributeDict({'address': '0xDc3A9Db694BCdd55EBaE4A89B22aC6D12b3F0c24', 'blockHash': HexBytes('0xb72256286ca528e09022ffd408856a73ef90e7216ac560187c6e43b4c4efd2f0'), 'blockNumber': 2217196, 'data': '0x0000000000000000000000000000000000000000000000000000000000000001', 'logIndex': 0, 'topics': [HexBytes('0xe65b00b698ba37c614af350761c735c5f4a82b4ab365a1f1022d49d9dfc8e930'), HexBytes('0x000000000000000000000000754c50465885f1ed1fa1a55b95ee8ecf3f1f4324'), HexBytes('0x296c7fb6ccafa3e689950b947c2895b07357c95b066d5cdccd58c301f41359a3')], 'transactionHash': HexBytes('0xfe1289fd3915794b99702202f65eea2e424b2f083a12749d29b4dd51f6dce40d'), 'transactionIndex': 1})] # noqa: E501


@pytest.fixture(scope='function')
def iter_block_number(start=0):
def iterator():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ def _get_block_by_number(method, params, block_info=_block_info):
return blocks[head_block_number + 1]
elif block_id == 'earliest':
return blocks[0]
elif is_integer(block_id) or is_hex(block_id):
if is_hex(block_id):
block_id = hex_to_integer(block_id)
elif is_integer(block_id):
if block_id <= head_block_number:
return blocks[block_id]
else:
return None
elif is_hex(block_id):
block_id = hex_to_integer(block_id)
if block_id <= head_block_number:
return blocks[block_id]
else:
Expand Down
2 changes: 1 addition & 1 deletion web3/_utils/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
remove_0x_prefix,
)
from eth_utils.toolz import (
curry
curry,
)

from web3.types import (
Expand Down
13 changes: 6 additions & 7 deletions web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Collection,
Dict,
Iterable,
NoReturn,
Tuple,
Union,
)
Expand Down Expand Up @@ -71,10 +72,9 @@
)
from web3.exceptions import (
BlockNotFound,
# TimeExhausted,
# TransactionNotFound,
)
from web3.types import (
BlockIdentifier,
RPCEndpoint,
TReturn,
)
Expand Down Expand Up @@ -500,7 +500,7 @@ def get_request_formatters(
return compose(*formatters)


def raise_block_not_found(params):
def raise_block_not_found(params: Tuple[BlockIdentifier, bool]) -> NoReturn:
block_identifier = params[0]
raise BlockNotFound(f"Block with id: {block_identifier} not found.")

Expand All @@ -514,14 +514,13 @@ def raise_block_not_found(params):
def get_result_formatters(
method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]]
) -> Dict[str, Callable[..., Any]]:
formatters = combine_formatters((
PYTHONIC_RESULT_FORMATTERS,
),
formatters = combine_formatters(
(PYTHONIC_RESULT_FORMATTERS,),
method_name
)
attrdict_formatter = apply_formatter_if(is_dict and not_attrdict, AttributeDict.recursive)

return compose(*formatters, attrdict_formatter)
return compose(attrdict_formatter, *formatters)


def get_error_formatters(
Expand Down
22 changes: 0 additions & 22 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,28 +251,6 @@ def address_resolver_munger(
mungers=[address_resolver_munger]
)

# def getBlock(
# self, block_identifier: BlockIdentifier, full_transactions: bool = False
# ) -> BlockData:
# """
# `eth_getBlockByHash`
# `eth_getBlockByNumber`
# """
# method = select_method_for_block_identifier(
# block_identifier,
# if_predefined=RPC.eth_getBlockByNumber,
# if_hash=RPC.eth_getBlockByHash,
# if_number=RPC.eth_getBlockByNumber,
# )

# 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 get_block_munger(
self, block_identifier: BlockIdentifier, full_transactions: bool=False
) -> Tuple[BlockIdentifier, bool]:
Expand Down
2 changes: 1 addition & 1 deletion web3/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def apply_error_formatters(
if 'error' in response and error_formatters:
formatted_response = pipe(response, error_formatters)
return formatted_response
elif response['result'] is None and error_formatters:
elif 'result' in response.keys() and response['result'] is None and error_formatters:
formatted_response = pipe(params, error_formatters)
return formatted_response
else:
Expand Down
2 changes: 1 addition & 1 deletion web3/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __init__(
request_formatters: Optional[Callable[..., TReturn]] = None,
result_formatters: Optional[Callable[..., TReturn]] = None,
error_formatters: Optional[Callable[..., TReturn]] = None,
method_choice_depends_on_args: Optional[Callable[..., str]] = None,
method_choice_depends_on_args: Optional[Callable[..., RPCEndpoint]] = None,
web3: Optional["Web3"] = None):

self.json_rpc_method = json_rpc_method
Expand Down

0 comments on commit f0708ee

Please sign in to comment.