prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Upgrade Parity version in test infrastructure
  ### What was wrong?
  
  Our Parity tests run on version 2.3.5. According to a recent OpenEthereum [blog post](https://medium.com/openethereum/vision-for-openethereum-ex-parity-client-eb7b11f6eef8), latest stable recommendation is 2.5.13.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `web3/middleware/validation.py`
  Content:
  ```
  1 from typing import (
  2     TYPE_CHECKING,
  3     Any,
  4     Callable,
  5 )
  6 
  7 from eth_utils.curried import (
  8     apply_formatter_at_index,
  9     apply_formatter_if,
  10     apply_formatters_to_dict,
  11     is_null,
  12 )
  13 from eth_utils.toolz import (
  14     complement,
  15     compose,
  16     curry,
  17     dissoc,
  18 )
  19 from hexbytes import (
  20     HexBytes,
  21 )
  22 
  23 from web3._utils.rpc_abi import (
  24     RPC,
  25 )
  26 from web3.exceptions import (
  27     ExtraDataLengthError,
  28     ValidationError,
  29 )
  30 from web3.middleware.formatting import (
  31     construct_web3_formatting_middleware,
  32 )
  33 from web3.types import (
  34     FormattersDict,
  35     TxParams,
  36 )
  37 
  38 if TYPE_CHECKING:
  39     from web3 import Web3  # noqa: F401
  40 
  41 MAX_EXTRADATA_LENGTH = 32
  42 
  43 is_not_null = complement(is_null)
  44 
  45 
  46 @curry
  47 def validate_chain_id(web3: "Web3", chain_id: int) -> int:
  48     if int(chain_id) == web3.eth.chainId:
  49         return chain_id
  50     else:
  51         raise ValidationError(
  52             "The transaction declared chain ID %r, "
  53             "but the connected node is on %r" % (
  54                 chain_id,
  55                 web3.eth.chainId,
  56             )
  57         )
  58 
  59 
  60 def check_extradata_length(val: Any) -> Any:
  61     if not isinstance(val, (str, int, bytes)):
  62         return val
  63     result = HexBytes(val)
  64     if len(result) > MAX_EXTRADATA_LENGTH:
  65         raise ExtraDataLengthError(
  66             "The field extraData is %d bytes, but should be %d. "
  67             "It is quite likely that you are connected to a POA chain. "
  68             "Refer to "
  69             "http://web3py.readthedocs.io/en/stable/middleware.html#geth-style-proof-of-authority "
  70             "for more details. The full extraData is: %r" % (
  71                 len(result), MAX_EXTRADATA_LENGTH, result
  72             )
  73         )
  74     return val
  75 
  76 
  77 def transaction_normalizer(transaction: TxParams) -> TxParams:
  78     return dissoc(transaction, 'chainId')
  79 
  80 
  81 def transaction_param_validator(web3: "Web3") -> Callable[..., Any]:
  82     transactions_params_validators = {
  83         "chainId": apply_formatter_if(
  84             # Bypass `validate_chain_id` if chainId can't be determined
  85             lambda _: is_not_null(web3.eth.chainId),
  86             validate_chain_id(web3),
  87         ),
  88     }
  89     return apply_formatter_at_index(
  90         apply_formatters_to_dict(transactions_params_validators),
  91         0
  92     )
  93 
  94 
  95 BLOCK_VALIDATORS = {
  96     'extraData': check_extradata_length,
  97 }
  98 
  99 
  100 block_validator = apply_formatter_if(
  101     is_not_null,
  102     apply_formatters_to_dict(BLOCK_VALIDATORS)
  103 )
  104 
  105 
  106 @curry
  107 def chain_id_validator(web3: "Web3") -> Callable[..., Any]:
  108     return compose(
  109         apply_formatter_at_index(transaction_normalizer, 0),
  110         transaction_param_validator(web3)
  111     )
  112 
  113 
  114 def build_validators_with_web3(w3: "Web3") -> FormattersDict:
  115     return dict(
  116         request_formatters={
  117             RPC.eth_sendTransaction: chain_id_validator(w3),
  118             RPC.eth_estimateGas: chain_id_validator(w3),
  119             RPC.eth_call: chain_id_validator(w3),
  120         },
  121         result_formatters={
  122             RPC.eth_getBlockByHash: block_validator,
  123             RPC.eth_getBlockByNumber: block_validator,
  124         },
  125     )
  126 
  127 
  128 validation_middleware = construct_web3_formatting_middleware(build_validators_with_web3)
  129
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/web3/middleware/validation.py b/web3/middleware/validation.py
  --- a/web3/middleware/validation.py
  +++ b/web3/middleware/validation.py
  @@ -9,6 +9,7 @@
       apply_formatter_if,
       apply_formatters_to_dict,
       is_null,
  +    is_string,
   )
   from eth_utils.toolz import (
       complement,
  @@ -20,6 +21,9 @@
       HexBytes,
   )
   
  +from web3._utils.formatters import (
  +    hex_to_integer,
  +)
   from web3._utils.rpc_abi import (
       RPC,
   )
  @@ -42,10 +46,12 @@
   
   is_not_null = complement(is_null)
   
  +to_integer_if_hex = apply_formatter_if(is_string, hex_to_integer)
  +
   
   @curry
   def validate_chain_id(web3: "Web3", chain_id: int) -> int:
  -    if int(chain_id) == web3.eth.chainId:
  +    if to_integer_if_hex(chain_id) == web3.eth.chainId:
           return chain_id
       else:
           raise ValidationError(
  
verification_info: {"golden_diff": "diff --git a/web3/middleware/validation.py b/web3/middleware/validation.py\n--- a/web3/middleware/validation.py\n+++ b/web3/middleware/validation.py\n@@ -9,6 +9,7 @@\n     apply_formatter_if,\n     apply_formatters_to_dict,\n     is_null,\n+    is_string,\n )\n from eth_utils.toolz import (\n     complement,\n@@ -20,6 +21,9 @@\n     HexBytes,\n )\n \n+from web3._utils.formatters import (\n+    hex_to_integer,\n+)\n from web3._utils.rpc_abi import (\n     RPC,\n )\n@@ -42,10 +46,12 @@\n \n is_not_null = complement(is_null)\n \n+to_integer_if_hex = apply_formatter_if(is_string, hex_to_integer)\n+\n \n @curry\n def validate_chain_id(web3: \"Web3\", chain_id: int) -> int:\n-    if int(chain_id) == web3.eth.chainId:\n+    if to_integer_if_hex(chain_id) == web3.eth.chainId:\n         return chain_id\n     else:\n         raise ValidationError(\n", "issue": "Upgrade Parity version in test infrastructure\n### What was wrong?\r\n\r\nOur Parity tests run on version 2.3.5. According to a recent OpenEthereum [blog post](https://medium.com/openethereum/vision-for-openethereum-ex-parity-client-eb7b11f6eef8), latest stable recommendation is 2.5.13.\n", "before_files": [{"content": "from typing import (\n    TYPE_CHECKING,\n    Any,\n    Callable,\n)\n\nfrom eth_utils.curried import (\n    apply_formatter_at_index,\n    apply_formatter_if,\n    apply_formatters_to_dict,\n    is_null,\n)\nfrom eth_utils.toolz import (\n    complement,\n    compose,\n    curry,\n    dissoc,\n)\nfrom hexbytes import (\n    HexBytes,\n)\n\nfrom web3._utils.rpc_abi import (\n    RPC,\n)\nfrom web3.exceptions import (\n    ExtraDataLengthError,\n    ValidationError,\n)\nfrom web3.middleware.formatting import (\n    construct_web3_formatting_middleware,\n)\nfrom web3.types import (\n    FormattersDict,\n    TxParams,\n)\n\nif TYPE_CHECKING:\n    from web3 import Web3  # noqa: F401\n\nMAX_EXTRADATA_LENGTH = 32\n\nis_not_null = complement(is_null)\n\n\n@curry\ndef validate_chain_id(web3: \"Web3\", chain_id: int) -> int:\n    if int(chain_id) == web3.eth.chainId:\n        return chain_id\n    else:\n        raise ValidationError(\n            \"The transaction declared chain ID %r, \"\n            \"but the connected node is on %r\" % (\n                chain_id,\n                web3.eth.chainId,\n            )\n        )\n\n\ndef check_extradata_length(val: Any) -> Any:\n    if not isinstance(val, (str, int, bytes)):\n        return val\n    result = HexBytes(val)\n    if len(result) > MAX_EXTRADATA_LENGTH:\n        raise ExtraDataLengthError(\n            \"The field extraData is %d bytes, but should be %d. \"\n            \"It is quite likely that you are connected to a POA chain. \"\n            \"Refer to \"\n            \"http://web3py.readthedocs.io/en/stable/middleware.html#geth-style-proof-of-authority \"\n            \"for more details. The full extraData is: %r\" % (\n                len(result), MAX_EXTRADATA_LENGTH, result\n            )\n        )\n    return val\n\n\ndef transaction_normalizer(transaction: TxParams) -> TxParams:\n    return dissoc(transaction, 'chainId')\n\n\ndef transaction_param_validator(web3: \"Web3\") -> Callable[..., Any]:\n    transactions_params_validators = {\n        \"chainId\": apply_formatter_if(\n            # Bypass `validate_chain_id` if chainId can't be determined\n            lambda _: is_not_null(web3.eth.chainId),\n            validate_chain_id(web3),\n        ),\n    }\n    return apply_formatter_at_index(\n        apply_formatters_to_dict(transactions_params_validators),\n        0\n    )\n\n\nBLOCK_VALIDATORS = {\n    'extraData': check_extradata_length,\n}\n\n\nblock_validator = apply_formatter_if(\n    is_not_null,\n    apply_formatters_to_dict(BLOCK_VALIDATORS)\n)\n\n\n@curry\ndef chain_id_validator(web3: \"Web3\") -> Callable[..., Any]:\n    return compose(\n        apply_formatter_at_index(transaction_normalizer, 0),\n        transaction_param_validator(web3)\n    )\n\n\ndef build_validators_with_web3(w3: \"Web3\") -> FormattersDict:\n    return dict(\n        request_formatters={\n            RPC.eth_sendTransaction: chain_id_validator(w3),\n            RPC.eth_estimateGas: chain_id_validator(w3),\n            RPC.eth_call: chain_id_validator(w3),\n        },\n        result_formatters={\n            RPC.eth_getBlockByHash: block_validator,\n            RPC.eth_getBlockByNumber: block_validator,\n        },\n    )\n\n\nvalidation_middleware = construct_web3_formatting_middleware(build_validators_with_web3)\n", "path": "web3/middleware/validation.py"}], "after_files": [{"content": "from typing import (\n    TYPE_CHECKING,\n    Any,\n    Callable,\n)\n\nfrom eth_utils.curried import (\n    apply_formatter_at_index,\n    apply_formatter_if,\n    apply_formatters_to_dict,\n    is_null,\n    is_string,\n)\nfrom eth_utils.toolz import (\n    complement,\n    compose,\n    curry,\n    dissoc,\n)\nfrom hexbytes import (\n    HexBytes,\n)\n\nfrom web3._utils.formatters import (\n    hex_to_integer,\n)\nfrom web3._utils.rpc_abi import (\n    RPC,\n)\nfrom web3.exceptions import (\n    ExtraDataLengthError,\n    ValidationError,\n)\nfrom web3.middleware.formatting import (\n    construct_web3_formatting_middleware,\n)\nfrom web3.types import (\n    FormattersDict,\n    TxParams,\n)\n\nif TYPE_CHECKING:\n    from web3 import Web3  # noqa: F401\n\nMAX_EXTRADATA_LENGTH = 32\n\nis_not_null = complement(is_null)\n\nto_integer_if_hex = apply_formatter_if(is_string, hex_to_integer)\n\n\n@curry\ndef validate_chain_id(web3: \"Web3\", chain_id: int) -> int:\n    if to_integer_if_hex(chain_id) == web3.eth.chainId:\n        return chain_id\n    else:\n        raise ValidationError(\n            \"The transaction declared chain ID %r, \"\n            \"but the connected node is on %r\" % (\n                chain_id,\n                web3.eth.chainId,\n            )\n        )\n\n\ndef check_extradata_length(val: Any) -> Any:\n    if not isinstance(val, (str, int, bytes)):\n        return val\n    result = HexBytes(val)\n    if len(result) > MAX_EXTRADATA_LENGTH:\n        raise ExtraDataLengthError(\n            \"The field extraData is %d bytes, but should be %d. \"\n            \"It is quite likely that you are connected to a POA chain. \"\n            \"Refer to \"\n            \"http://web3py.readthedocs.io/en/stable/middleware.html#geth-style-proof-of-authority \"\n            \"for more details. The full extraData is: %r\" % (\n                len(result), MAX_EXTRADATA_LENGTH, result\n            )\n        )\n    return val\n\n\ndef transaction_normalizer(transaction: TxParams) -> TxParams:\n    return dissoc(transaction, 'chainId')\n\n\ndef transaction_param_validator(web3: \"Web3\") -> Callable[..., Any]:\n    transactions_params_validators = {\n        \"chainId\": apply_formatter_if(\n            # Bypass `validate_chain_id` if chainId can't be determined\n            lambda _: is_not_null(web3.eth.chainId),\n            validate_chain_id(web3),\n        ),\n    }\n    return apply_formatter_at_index(\n        apply_formatters_to_dict(transactions_params_validators),\n        0\n    )\n\n\nBLOCK_VALIDATORS = {\n    'extraData': check_extradata_length,\n}\n\n\nblock_validator = apply_formatter_if(\n    is_not_null,\n    apply_formatters_to_dict(BLOCK_VALIDATORS)\n)\n\n\n@curry\ndef chain_id_validator(web3: \"Web3\") -> Callable[..., Any]:\n    return compose(\n        apply_formatter_at_index(transaction_normalizer, 0),\n        transaction_param_validator(web3)\n    )\n\n\ndef build_validators_with_web3(w3: \"Web3\") -> FormattersDict:\n    return dict(\n        request_formatters={\n            RPC.eth_sendTransaction: chain_id_validator(w3),\n            RPC.eth_estimateGas: chain_id_validator(w3),\n            RPC.eth_call: chain_id_validator(w3),\n        },\n        result_formatters={\n            RPC.eth_getBlockByHash: block_validator,\n            RPC.eth_getBlockByNumber: block_validator,\n        },\n    )\n\n\nvalidation_middleware = construct_web3_formatting_middleware(build_validators_with_web3)\n", "path": "web3/middleware/validation.py"}]}