diff --git a/tests/core/gas-strategies/test_time_based_gas_price_strategy.py b/tests/core/gas-strategies/test_time_based_gas_price_strategy.py index 403a119ce3..e4b2b66b22 100644 --- a/tests/core/gas-strategies/test_time_based_gas_price_strategy.py +++ b/tests/core/gas-strategies/test_time_based_gas_price_strategy.py @@ -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', @@ -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', @@ -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', @@ -65,12 +64,12 @@ 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', @@ -78,12 +77,12 @@ def _get_block_by_something(method, params): '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', @@ -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', @@ -119,7 +117,7 @@ def _get_block_by_something(method, params): {'gasPrice': 54}, {'gasPrice': 10000000000000000000000}, ], - 'miner': '0xA', + 'miner': '0x' + 'Aa' * 20, 'timestamp': 0, } else: diff --git a/tests/core/middleware/test_filter_middleware.py b/tests/core/middleware/test_filter_middleware.py index 3cc4a5ef71..4a9b525c77 100644 --- a/tests/core/middleware/test_filter_middleware.py +++ b/tests/core/middleware/test_filter_middleware.py @@ -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(): 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 695173b7a6..b71ef455d3 100644 --- a/tests/core/middleware/test_latest_block_based_cache_middleware.py +++ b/tests/core/middleware/test_latest_block_based_cache_middleware.py @@ -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: diff --git a/web3/_utils/blocks.py b/web3/_utils/blocks.py index 3e39c7e852..ac875f3c03 100644 --- a/web3/_utils/blocks.py +++ b/web3/_utils/blocks.py @@ -11,7 +11,7 @@ remove_0x_prefix, ) from eth_utils.toolz import ( - curry + curry, ) from web3.types import ( diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index bda7125926..83aeeebd87 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -6,6 +6,7 @@ Collection, Dict, Iterable, + NoReturn, Tuple, Union, ) @@ -71,10 +72,9 @@ ) from web3.exceptions import ( BlockNotFound, - # TimeExhausted, - # TransactionNotFound, ) from web3.types import ( + BlockIdentifier, RPCEndpoint, TReturn, ) @@ -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.") @@ -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( diff --git a/web3/eth.py b/web3/eth.py index 762c9a29b7..12e29e0fa3 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -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]: diff --git a/web3/manager.py b/web3/manager.py index f293adb9f2..cf5c678094 100644 --- a/web3/manager.py +++ b/web3/manager.py @@ -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: diff --git a/web3/method.py b/web3/method.py index 7ca3902869..002419644b 100644 --- a/web3/method.py +++ b/web3/method.py @@ -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