We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove all beta dependencies (except eth-account)
* Version: 4

### What was wrong?

In order to mark v4 stable, it needs to not depend on any beta packages. `eth-account` is the exception, awaiting security audit. In order to signal that to users, we will probably make them jump through a hoop to acknowledge the lack of audit.

### How can it be fixed?

Stabilize and release versions of all unstable dependencies, starting with the leaves in the dependency graph.

Dependencies:

- [x] eth-hash - v0.1.0
  - [x] eth-utils - v1.0.1
    - [x] eth-abi - v1.0.0
    - [x] hexbytes - v0.1.0
- [x] eth-rlp v0.1.0
  - [x] ~eth-keys~ _(awaiting audit)_
    - [ ] ~eth-account~ _(awaiting audit)_ -- Still need to make some kind of *in-your-face* warnings about the pending audit -- tracked in #678 
- [x] ~eth-tester~ _(only needed for testing, not prod use; depends too heavily on py-evm, which isn't leaving alpha any time soon)_



Dependent nodes are listed in hierarchy. Because eth-abi depends on eth-utils, it is indented beneath it. eth-utils should be worked on before eth-abi. eth-hash before eth-utils, etc.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 from setuptools import (
4     setup,
5     find_packages,
6 )
7 
8 
9 setup(
10     name='web3',
11     # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility.
12     version='4.0.0-beta.11',
13     description="""Web3.py""",
14     long_description_markdown_filename='README.md',
15     author='Piper Merriam',
16     author_email='pipermerriam@gmail.com',
17     url='https://github.com/ethereum/web3.py',
18     include_package_data=True,
19     install_requires=[
20         "cytoolz>=0.9.0,<1.0.0",
21         "eth-abi>=1.0.0-beta.1,<2",
22         "eth-account>=0.1.0a2,<1.0.0",
23         "eth-utils>=1.0.0b1,<2.0.0",
24         "hexbytes>=0.1.0b1,<1.0.0",
25         "lru-dict>=1.1.6,<2.0.0",
26         "eth-hash[pycryptodome]",
27         "requests>=2.16.0,<3.0.0",
28     ],
29     setup_requires=['setuptools-markdown'],
30     extras_require={
31         'tester': [
32             "eth-tester[py-evm]==0.1.0b19",
33             "py-geth>=2.0.1,<3.0.0",
34         ],
35         'testrpc': ["eth-testrpc>=1.3.3,<2.0.0"],
36         'linter': [
37             "flake8==3.4.1",
38             "isort>=4.2.15,<5",
39         ],
40         'platform_system=="Windows"': [
41             'pypiwin32'  # TODO: specify a version number, move under install_requires
42         ],
43     },
44     py_modules=['web3', 'ens'],
45     license="MIT",
46     zip_safe=False,
47     keywords='ethereum',
48     packages=find_packages(exclude=["tests", "tests.*"]),
49     classifiers=[
50         'Development Status :: 4 - Beta',
51         'Intended Audience :: Developers',
52         'License :: OSI Approved :: MIT License',
53         'Natural Language :: English',
54         'Programming Language :: Python :: 3',
55         'Programming Language :: Python :: 3.5',
56         'Programming Language :: Python :: 3.6',
57     ],
58 )
59
```

Path: `web3/providers/eth_tester/middleware.py`
Content:
```
1 import operator
2 
3 from cytoolz import (
4     assoc,
5     complement,
6     compose,
7     curry,
8     identity,
9     partial,
10     pipe,
11 )
12 from eth_utils import (
13     is_dict,
14     is_string,
15 )
16 
17 from web3.middleware import (
18     construct_fixture_middleware,
19     construct_formatting_middleware,
20 )
21 from web3.utils.formatters import (
22     apply_formatter_if,
23     apply_formatter_to_array,
24     apply_formatters_to_args,
25     apply_formatters_to_dict,
26     apply_key_map,
27     hex_to_integer,
28     integer_to_hex,
29     is_array_of_dicts,
30     static_return,
31 )
32 
33 
34 def is_named_block(value):
35     return value in {"latest", "earliest", "pending"}
36 
37 
38 to_integer_if_hex = apply_formatter_if(is_string, hex_to_integer)
39 
40 
41 is_not_named_block = complement(is_named_block)
42 
43 
44 TRANSACTION_KEY_MAPPINGS = {
45     'block_hash': 'blockHash',
46     'block_number': 'blockNumber',
47     'gas_price': 'gasPrice',
48     'transaction_hash': 'transactionHash',
49     'transaction_index': 'transactionIndex',
50 }
51 
52 transaction_key_remapper = apply_key_map(TRANSACTION_KEY_MAPPINGS)
53 
54 
55 LOG_KEY_MAPPINGS = {
56     'log_index': 'logIndex',
57     'transaction_index': 'transactionIndex',
58     'transaction_hash': 'transactionHash',
59     'block_hash': 'blockHash',
60     'block_number': 'blockNumber',
61 }
62 
63 
64 log_key_remapper = apply_key_map(LOG_KEY_MAPPINGS)
65 
66 
67 RECEIPT_KEY_MAPPINGS = {
68     'block_hash': 'blockHash',
69     'block_number': 'blockNumber',
70     'contract_address': 'contractAddress',
71     'gas_used': 'gasUsed',
72     'cumulative_gas_used': 'cumulativeGasUsed',
73     'transaction_hash': 'transactionHash',
74     'transaction_index': 'transactionIndex',
75 }
76 
77 
78 receipt_key_remapper = apply_key_map(RECEIPT_KEY_MAPPINGS)
79 
80 
81 BLOCK_KEY_MAPPINGS = {
82     'gas_limit': 'gasLimit',
83     'sha3_uncles': 'sha3Uncles',
84     'transactions_root': 'transactionsRoot',
85     'parent_hash': 'parentHash',
86     'bloom': 'logsBloom',
87     'state_root': 'stateRoot',
88     'receipt_root': 'receiptsRoot',
89     'total_difficulty': 'totalDifficulty',
90     'extra_data': 'extraData',
91     'gas_used': 'gasUsed',
92 }
93 
94 
95 block_key_remapper = apply_key_map(BLOCK_KEY_MAPPINGS)
96 
97 
98 TRANSACTION_PARAMS_MAPPING = {
99     'gasPrice': 'gas_price',
100 }
101 
102 
103 transaction_params_remapper = apply_key_map(TRANSACTION_PARAMS_MAPPING)
104 
105 
106 TRANSACTION_PARAMS_FORMATTERS = {
107     'gas': to_integer_if_hex,
108     'gasPrice': to_integer_if_hex,
109     'value': to_integer_if_hex,
110     'nonce': to_integer_if_hex,
111 }
112 
113 
114 transaction_params_formatter = apply_formatters_to_dict(TRANSACTION_PARAMS_FORMATTERS)
115 
116 
117 FILTER_PARAMS_MAPPINGS = {
118     'fromBlock': 'from_block',
119     'toBlock': 'to_block',
120 }
121 
122 filter_params_remapper = apply_key_map(FILTER_PARAMS_MAPPINGS)
123 
124 FILTER_PARAMS_FORMATTERS = {
125     'fromBlock': to_integer_if_hex,
126     'toBlock': to_integer_if_hex,
127 }
128 
129 filter_params_formatter = apply_formatters_to_dict(FILTER_PARAMS_FORMATTERS)
130 
131 filter_params_transformer = compose(filter_params_remapper, filter_params_formatter)
132 
133 
134 TRANSACTION_FORMATTERS = {
135     'to': apply_formatter_if(partial(operator.eq, b''), static_return(None)),
136 }
137 
138 
139 transaction_formatter = apply_formatters_to_dict(TRANSACTION_FORMATTERS)
140 
141 
142 RECEIPT_FORMATTERS = {
143     'logs': apply_formatter_to_array(log_key_remapper),
144 }
145 
146 
147 receipt_formatter = apply_formatters_to_dict(RECEIPT_FORMATTERS)
148 
149 transaction_params_transformer = compose(transaction_params_remapper, transaction_params_formatter)
150 
151 ethereum_tester_middleware = construct_formatting_middleware(
152     request_formatters={
153         # Eth
154         'eth_getBlockByNumber': apply_formatters_to_args(
155             apply_formatter_if(is_not_named_block, to_integer_if_hex),
156         ),
157         'eth_getFilterChanges': apply_formatters_to_args(hex_to_integer),
158         'eth_getFilterLogs': apply_formatters_to_args(hex_to_integer),
159         'eth_getBlockTransactionCountByNumber': apply_formatters_to_args(
160             apply_formatter_if(is_not_named_block, to_integer_if_hex),
161         ),
162         'eth_getUncleCountByBlockNumber': apply_formatters_to_args(
163             apply_formatter_if(is_not_named_block, to_integer_if_hex),
164         ),
165         'eth_getTransactionByBlockHashAndIndex': apply_formatters_to_args(
166             identity,
167             to_integer_if_hex,
168         ),
169         'eth_getTransactionByBlockNumberAndIndex': apply_formatters_to_args(
170             apply_formatter_if(is_not_named_block, to_integer_if_hex),
171             to_integer_if_hex,
172         ),
173         'eth_getUncleByBlockNumberAndIndex': apply_formatters_to_args(
174             apply_formatter_if(is_not_named_block, to_integer_if_hex),
175             to_integer_if_hex,
176         ),
177         'eth_newFilter': apply_formatters_to_args(
178             filter_params_transformer,
179         ),
180         'eth_getLogs': apply_formatters_to_args(
181             filter_params_transformer,
182         ),
183         'eth_sendTransaction': apply_formatters_to_args(
184             transaction_params_transformer,
185         ),
186         'eth_estimateGas': apply_formatters_to_args(
187             transaction_params_transformer,
188         ),
189         'eth_call': apply_formatters_to_args(
190             transaction_params_transformer,
191         ),
192         'eth_uninstallFilter': apply_formatters_to_args(hex_to_integer),
193         # EVM
194         'evm_revert': apply_formatters_to_args(hex_to_integer),
195         # Personal
196         'personal_sendTransaction': apply_formatters_to_args(
197             transaction_params_transformer,
198             identity,
199         ),
200     },
201     result_formatters={
202         'eth_getBlockByHash': apply_formatter_if(
203             is_dict,
204             block_key_remapper,
205         ),
206         'eth_getBlockByNumber': apply_formatter_if(
207             is_dict,
208             block_key_remapper,
209         ),
210         'eth_getBlockTransactionCountByHash': apply_formatter_if(
211             is_dict,
212             transaction_key_remapper,
213         ),
214         'eth_getBlockTransactionCountByNumber': apply_formatter_if(
215             is_dict,
216             transaction_key_remapper,
217         ),
218         'eth_getTransactionByHash': apply_formatter_if(
219             is_dict,
220             compose(transaction_key_remapper, transaction_formatter),
221         ),
222         'eth_getTransactionReceipt': apply_formatter_if(
223             is_dict,
224             compose(receipt_key_remapper, receipt_formatter),
225         ),
226         'eth_newFilter': integer_to_hex,
227         'eth_newBlockFilter': integer_to_hex,
228         'eth_newPendingTransactionFilter': integer_to_hex,
229         'eth_getLogs': apply_formatter_if(
230             is_array_of_dicts,
231             apply_formatter_to_array(log_key_remapper),
232         ),
233         'eth_getFilterChanges': apply_formatter_if(
234             is_array_of_dicts,
235             apply_formatter_to_array(log_key_remapper),
236         ),
237         'eth_getFilterLogs': apply_formatter_if(
238             is_array_of_dicts,
239             apply_formatter_to_array(log_key_remapper),
240         ),
241         # EVM
242         'evm_snapshot': integer_to_hex,
243     },
244 )
245 
246 
247 ethereum_tester_fixture_middleware = construct_fixture_middleware({
248     # Eth
249     'eth_protocolVersion': '63',
250     'eth_hashrate': 0,
251     'eth_gasPrice': 1,
252     'eth_syncing': False,
253     'eth_mining': False,
254     # Net
255     'net_version': '1',
256     'net_listening': False,
257     'net_peerCount': 0,
258 })
259 
260 
261 def guess_from(web3, transaction):
262     coinbase = web3.eth.coinbase
263     if coinbase is not None:
264         return coinbase
265 
266     try:
267         return web3.eth.accounts[0]
268     except KeyError as e:
269         # no accounts available to pre-fill, carry on
270         pass
271 
272     return None
273 
274 
275 def guess_gas(web3, transaction):
276     return web3.eth.estimateGas(transaction) * 2
277 
278 
279 @curry
280 def fill_default(field, guess_func, web3, transaction):
281     if field in transaction and transaction[field] is not None:
282         return transaction
283     else:
284         guess_val = guess_func(web3, transaction)
285         return assoc(transaction, field, guess_val)
286 
287 
288 def default_transaction_fields_middleware(make_request, web3):
289     fill_default_from = fill_default('from', guess_from, web3)
290     fill_default_gas = fill_default('gas', guess_gas, web3)
291 
292     def middleware(method, params):
293         # TODO send call to eth-tester without gas, and remove guess_gas entirely
294         if method == 'eth_call':
295             filled_transaction = pipe(
296                 params[0],
297                 fill_default_from,
298                 fill_default_gas,
299             )
300             return make_request(method, [filled_transaction] + params[1:])
301         elif method in (
302             'eth_estimateGas',
303             'eth_sendTransaction',
304         ):
305             filled_transaction = pipe(
306                 params[0],
307                 fill_default_from,
308             )
309             return make_request(method, [filled_transaction] + params[1:])
310         else:
311             return make_request(method, params)
312     return middleware
313
```
--- 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()

```

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -18,10 +18,10 @@
     include_package_data=True,
     install_requires=[
         "cytoolz>=0.9.0,<1.0.0",
-        "eth-abi>=1.0.0-beta.1,<2",
-        "eth-account>=0.1.0a2,<1.0.0",
-        "eth-utils>=1.0.0b1,<2.0.0",
-        "hexbytes>=0.1.0b1,<1.0.0",
+        "eth-abi>=1.0.0,<2",
+        "eth-account>=0.1.0-alpha.2,<1.0.0",
+        "eth-utils>=1.0.1,<2.0.0",
+        "hexbytes>=0.1.0,<1.0.0",
         "lru-dict>=1.1.6,<2.0.0",
         "eth-hash[pycryptodome]",
         "requests>=2.16.0,<3.0.0",
@@ -29,7 +29,7 @@
     setup_requires=['setuptools-markdown'],
     extras_require={
         'tester': [
-            "eth-tester[py-evm]==0.1.0b19",
+            "eth-tester[py-evm]==0.1.0-beta.21",
             "py-geth>=2.0.1,<3.0.0",
         ],
         'testrpc': ["eth-testrpc>=1.3.3,<2.0.0"],
diff --git a/web3/providers/eth_tester/middleware.py b/web3/providers/eth_tester/middleware.py
--- a/web3/providers/eth_tester/middleware.py
+++ b/web3/providers/eth_tester/middleware.py
@@ -132,7 +132,7 @@
 
 
 TRANSACTION_FORMATTERS = {
-    'to': apply_formatter_if(partial(operator.eq, b''), static_return(None)),
+    'to': apply_formatter_if(partial(operator.eq, ''), static_return(None)),
 }

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -18,10 +18,10 @@\n     include_package_data=True,\n     install_requires=[\n         \"cytoolz>=0.9.0,<1.0.0\",\n-        \"eth-abi>=1.0.0-beta.1,<2\",\n-        \"eth-account>=0.1.0a2,<1.0.0\",\n-        \"eth-utils>=1.0.0b1,<2.0.0\",\n-        \"hexbytes>=0.1.0b1,<1.0.0\",\n+        \"eth-abi>=1.0.0,<2\",\n+        \"eth-account>=0.1.0-alpha.2,<1.0.0\",\n+        \"eth-utils>=1.0.1,<2.0.0\",\n+        \"hexbytes>=0.1.0,<1.0.0\",\n         \"lru-dict>=1.1.6,<2.0.0\",\n         \"eth-hash[pycryptodome]\",\n         \"requests>=2.16.0,<3.0.0\",\n@@ -29,7 +29,7 @@\n     setup_requires=['setuptools-markdown'],\n     extras_require={\n         'tester': [\n-            \"eth-tester[py-evm]==0.1.0b19\",\n+            \"eth-tester[py-evm]==0.1.0-beta.21\",\n             \"py-geth>=2.0.1,<3.0.0\",\n         ],\n         'testrpc': [\"eth-testrpc>=1.3.3,<2.0.0\"],\ndiff --git a/web3/providers/eth_tester/middleware.py b/web3/providers/eth_tester/middleware.py\n--- a/web3/providers/eth_tester/middleware.py\n+++ b/web3/providers/eth_tester/middleware.py\n@@ -132,7 +132,7 @@\n \n \n TRANSACTION_FORMATTERS = {\n-    'to': apply_formatter_if(partial(operator.eq, b''), static_return(None)),\n+    'to': apply_formatter_if(partial(operator.eq, ''), static_return(None)),\n }\n", "issue": "Remove all beta dependencies (except eth-account)\n* Version: 4\r\n\r\n### What was wrong?\r\n\r\nIn order to mark v4 stable, it needs to not depend on any beta packages. `eth-account` is the exception, awaiting security audit. In order to signal that to users, we will probably make them jump through a hoop to acknowledge the lack of audit.\r\n\r\n### How can it be fixed?\r\n\r\nStabilize and release versions of all unstable dependencies, starting with the leaves in the dependency graph.\r\n\r\nDependencies:\r\n\r\n- [x] eth-hash - v0.1.0\r\n  - [x] eth-utils - v1.0.1\r\n    - [x] eth-abi - v1.0.0\r\n    - [x] hexbytes - v0.1.0\r\n- [x] eth-rlp v0.1.0\r\n  - [x] ~eth-keys~ _(awaiting audit)_\r\n    - [ ] ~eth-account~ _(awaiting audit)_ -- Still need to make some kind of *in-your-face* warnings about the pending audit -- tracked in #678 \r\n- [x] ~eth-tester~ _(only needed for testing, not prod use; depends too heavily on py-evm, which isn't leaving alpha any time soon)_\r\n\r\n\r\n\r\nDependent nodes are listed in hierarchy. Because eth-abi depends on eth-utils, it is indented beneath it. eth-utils should be worked on before eth-abi. eth-hash before eth-utils, etc.\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nfrom setuptools import (\n    setup,\n    find_packages,\n)\n\n\nsetup(\n    name='web3',\n    # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility.\n    version='4.0.0-beta.11',\n    description=\"\"\"Web3.py\"\"\",\n    long_description_markdown_filename='README.md',\n    author='Piper Merriam',\n    author_email='pipermerriam@gmail.com',\n    url='https://github.com/ethereum/web3.py',\n    include_package_data=True,\n    install_requires=[\n        \"cytoolz>=0.9.0,<1.0.0\",\n        \"eth-abi>=1.0.0-beta.1,<2\",\n        \"eth-account>=0.1.0a2,<1.0.0\",\n        \"eth-utils>=1.0.0b1,<2.0.0\",\n        \"hexbytes>=0.1.0b1,<1.0.0\",\n        \"lru-dict>=1.1.6,<2.0.0\",\n        \"eth-hash[pycryptodome]\",\n        \"requests>=2.16.0,<3.0.0\",\n    ],\n    setup_requires=['setuptools-markdown'],\n    extras_require={\n        'tester': [\n            \"eth-tester[py-evm]==0.1.0b19\",\n            \"py-geth>=2.0.1,<3.0.0\",\n        ],\n        'testrpc': [\"eth-testrpc>=1.3.3,<2.0.0\"],\n        'linter': [\n            \"flake8==3.4.1\",\n            \"isort>=4.2.15,<5\",\n        ],\n        'platform_system==\"Windows\"': [\n            'pypiwin32'  # TODO: specify a version number, move under install_requires\n        ],\n    },\n    py_modules=['web3', 'ens'],\n    license=\"MIT\",\n    zip_safe=False,\n    keywords='ethereum',\n    packages=find_packages(exclude=[\"tests\", \"tests.*\"]),\n    classifiers=[\n        'Development Status :: 4 - Beta',\n        'Intended Audience :: Developers',\n        'License :: OSI Approved :: MIT License',\n        'Natural Language :: English',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.5',\n        'Programming Language :: Python :: 3.6',\n    ],\n)\n", "path": "setup.py"}, {"content": "import operator\n\nfrom cytoolz import (\n    assoc,\n    complement,\n    compose,\n    curry,\n    identity,\n    partial,\n    pipe,\n)\nfrom eth_utils import (\n    is_dict,\n    is_string,\n)\n\nfrom web3.middleware import (\n    construct_fixture_middleware,\n    construct_formatting_middleware,\n)\nfrom web3.utils.formatters import (\n    apply_formatter_if,\n    apply_formatter_to_array,\n    apply_formatters_to_args,\n    apply_formatters_to_dict,\n    apply_key_map,\n    hex_to_integer,\n    integer_to_hex,\n    is_array_of_dicts,\n    static_return,\n)\n\n\ndef is_named_block(value):\n    return value in {\"latest\", \"earliest\", \"pending\"}\n\n\nto_integer_if_hex = apply_formatter_if(is_string, hex_to_integer)\n\n\nis_not_named_block = complement(is_named_block)\n\n\nTRANSACTION_KEY_MAPPINGS = {\n    'block_hash': 'blockHash',\n    'block_number': 'blockNumber',\n    'gas_price': 'gasPrice',\n    'transaction_hash': 'transactionHash',\n    'transaction_index': 'transactionIndex',\n}\n\ntransaction_key_remapper = apply_key_map(TRANSACTION_KEY_MAPPINGS)\n\n\nLOG_KEY_MAPPINGS = {\n    'log_index': 'logIndex',\n    'transaction_index': 'transactionIndex',\n    'transaction_hash': 'transactionHash',\n    'block_hash': 'blockHash',\n    'block_number': 'blockNumber',\n}\n\n\nlog_key_remapper = apply_key_map(LOG_KEY_MAPPINGS)\n\n\nRECEIPT_KEY_MAPPINGS = {\n    'block_hash': 'blockHash',\n    'block_number': 'blockNumber',\n    'contract_address': 'contractAddress',\n    'gas_used': 'gasUsed',\n    'cumulative_gas_used': 'cumulativeGasUsed',\n    'transaction_hash': 'transactionHash',\n    'transaction_index': 'transactionIndex',\n}\n\n\nreceipt_key_remapper = apply_key_map(RECEIPT_KEY_MAPPINGS)\n\n\nBLOCK_KEY_MAPPINGS = {\n    'gas_limit': 'gasLimit',\n    'sha3_uncles': 'sha3Uncles',\n    'transactions_root': 'transactionsRoot',\n    'parent_hash': 'parentHash',\n    'bloom': 'logsBloom',\n    'state_root': 'stateRoot',\n    'receipt_root': 'receiptsRoot',\n    'total_difficulty': 'totalDifficulty',\n    'extra_data': 'extraData',\n    'gas_used': 'gasUsed',\n}\n\n\nblock_key_remapper = apply_key_map(BLOCK_KEY_MAPPINGS)\n\n\nTRANSACTION_PARAMS_MAPPING = {\n    'gasPrice': 'gas_price',\n}\n\n\ntransaction_params_remapper = apply_key_map(TRANSACTION_PARAMS_MAPPING)\n\n\nTRANSACTION_PARAMS_FORMATTERS = {\n    'gas': to_integer_if_hex,\n    'gasPrice': to_integer_if_hex,\n    'value': to_integer_if_hex,\n    'nonce': to_integer_if_hex,\n}\n\n\ntransaction_params_formatter = apply_formatters_to_dict(TRANSACTION_PARAMS_FORMATTERS)\n\n\nFILTER_PARAMS_MAPPINGS = {\n    'fromBlock': 'from_block',\n    'toBlock': 'to_block',\n}\n\nfilter_params_remapper = apply_key_map(FILTER_PARAMS_MAPPINGS)\n\nFILTER_PARAMS_FORMATTERS = {\n    'fromBlock': to_integer_if_hex,\n    'toBlock': to_integer_if_hex,\n}\n\nfilter_params_formatter = apply_formatters_to_dict(FILTER_PARAMS_FORMATTERS)\n\nfilter_params_transformer = compose(filter_params_remapper, filter_params_formatter)\n\n\nTRANSACTION_FORMATTERS = {\n    'to': apply_formatter_if(partial(operator.eq, b''), static_return(None)),\n}\n\n\ntransaction_formatter = apply_formatters_to_dict(TRANSACTION_FORMATTERS)\n\n\nRECEIPT_FORMATTERS = {\n    'logs': apply_formatter_to_array(log_key_remapper),\n}\n\n\nreceipt_formatter = apply_formatters_to_dict(RECEIPT_FORMATTERS)\n\ntransaction_params_transformer = compose(transaction_params_remapper, transaction_params_formatter)\n\nethereum_tester_middleware = construct_formatting_middleware(\n    request_formatters={\n        # Eth\n        'eth_getBlockByNumber': apply_formatters_to_args(\n            apply_formatter_if(is_not_named_block, to_integer_if_hex),\n        ),\n        'eth_getFilterChanges': apply_formatters_to_args(hex_to_integer),\n        'eth_getFilterLogs': apply_formatters_to_args(hex_to_integer),\n        'eth_getBlockTransactionCountByNumber': apply_formatters_to_args(\n            apply_formatter_if(is_not_named_block, to_integer_if_hex),\n        ),\n        'eth_getUncleCountByBlockNumber': apply_formatters_to_args(\n            apply_formatter_if(is_not_named_block, to_integer_if_hex),\n        ),\n        'eth_getTransactionByBlockHashAndIndex': apply_formatters_to_args(\n            identity,\n            to_integer_if_hex,\n        ),\n        'eth_getTransactionByBlockNumberAndIndex': apply_formatters_to_args(\n            apply_formatter_if(is_not_named_block, to_integer_if_hex),\n            to_integer_if_hex,\n        ),\n        'eth_getUncleByBlockNumberAndIndex': apply_formatters_to_args(\n            apply_formatter_if(is_not_named_block, to_integer_if_hex),\n            to_integer_if_hex,\n        ),\n        'eth_newFilter': apply_formatters_to_args(\n            filter_params_transformer,\n        ),\n        'eth_getLogs': apply_formatters_to_args(\n            filter_params_transformer,\n        ),\n        'eth_sendTransaction': apply_formatters_to_args(\n            transaction_params_transformer,\n        ),\n        'eth_estimateGas': apply_formatters_to_args(\n            transaction_params_transformer,\n        ),\n        'eth_call': apply_formatters_to_args(\n            transaction_params_transformer,\n        ),\n        'eth_uninstallFilter': apply_formatters_to_args(hex_to_integer),\n        # EVM\n        'evm_revert': apply_formatters_to_args(hex_to_integer),\n        # Personal\n        'personal_sendTransaction': apply_formatters_to_args(\n            transaction_params_transformer,\n            identity,\n        ),\n    },\n    result_formatters={\n        'eth_getBlockByHash': apply_formatter_if(\n            is_dict,\n            block_key_remapper,\n        ),\n        'eth_getBlockByNumber': apply_formatter_if(\n            is_dict,\n            block_key_remapper,\n        ),\n        'eth_getBlockTransactionCountByHash': apply_formatter_if(\n            is_dict,\n            transaction_key_remapper,\n        ),\n        'eth_getBlockTransactionCountByNumber': apply_formatter_if(\n            is_dict,\n            transaction_key_remapper,\n        ),\n        'eth_getTransactionByHash': apply_formatter_if(\n            is_dict,\n            compose(transaction_key_remapper, transaction_formatter),\n        ),\n        'eth_getTransactionReceipt': apply_formatter_if(\n            is_dict,\n            compose(receipt_key_remapper, receipt_formatter),\n        ),\n        'eth_newFilter': integer_to_hex,\n        'eth_newBlockFilter': integer_to_hex,\n        'eth_newPendingTransactionFilter': integer_to_hex,\n        'eth_getLogs': apply_formatter_if(\n            is_array_of_dicts,\n            apply_formatter_to_array(log_key_remapper),\n        ),\n        'eth_getFilterChanges': apply_formatter_if(\n            is_array_of_dicts,\n            apply_formatter_to_array(log_key_remapper),\n        ),\n        'eth_getFilterLogs': apply_formatter_if(\n            is_array_of_dicts,\n            apply_formatter_to_array(log_key_remapper),\n        ),\n        # EVM\n        'evm_snapshot': integer_to_hex,\n    },\n)\n\n\nethereum_tester_fixture_middleware = construct_fixture_middleware({\n    # Eth\n    'eth_protocolVersion': '63',\n    'eth_hashrate': 0,\n    'eth_gasPrice': 1,\n    'eth_syncing': False,\n    'eth_mining': False,\n    # Net\n    'net_version': '1',\n    'net_listening': False,\n    'net_peerCount': 0,\n})\n\n\ndef guess_from(web3, transaction):\n    coinbase = web3.eth.coinbase\n    if coinbase is not None:\n        return coinbase\n\n    try:\n        return web3.eth.accounts[0]\n    except KeyError as e:\n        # no accounts available to pre-fill, carry on\n        pass\n\n    return None\n\n\ndef guess_gas(web3, transaction):\n    return web3.eth.estimateGas(transaction) * 2\n\n\n@curry\ndef fill_default(field, guess_func, web3, transaction):\n    if field in transaction and transaction[field] is not None:\n        return transaction\n    else:\n        guess_val = guess_func(web3, transaction)\n        return assoc(transaction, field, guess_val)\n\n\ndef default_transaction_fields_middleware(make_request, web3):\n    fill_default_from = fill_default('from', guess_from, web3)\n    fill_default_gas = fill_default('gas', guess_gas, web3)\n\n    def middleware(method, params):\n        # TODO send call to eth-tester without gas, and remove guess_gas entirely\n        if method == 'eth_call':\n            filled_transaction = pipe(\n                params[0],\n                fill_default_from,\n                fill_default_gas,\n            )\n            return make_request(method, [filled_transaction] + params[1:])\n        elif method in (\n            'eth_estimateGas',\n            'eth_sendTransaction',\n        ):\n            filled_transaction = pipe(\n                params[0],\n                fill_default_from,\n            )\n            return make_request(method, [filled_transaction] + params[1:])\n        else:\n            return make_request(method, params)\n    return middleware\n", "path": "web3/providers/eth_tester/middleware.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nfrom setuptools import (\n    setup,\n    find_packages,\n)\n\n\nsetup(\n    name='web3',\n    # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility.\n    version='4.0.0-beta.11',\n    description=\"\"\"Web3.py\"\"\",\n    long_description_markdown_filename='README.md',\n    author='Piper Merriam',\n    author_email='pipermerriam@gmail.com',\n    url='https://github.com/ethereum/web3.py',\n    include_package_data=True,\n    install_requires=[\n        \"cytoolz>=0.9.0,<1.0.0\",\n        \"eth-abi>=1.0.0,<2\",\n        \"eth-account>=0.1.0-alpha.2,<1.0.0\",\n        \"eth-utils>=1.0.1,<2.0.0\",\n        \"hexbytes>=0.1.0,<1.0.0\",\n        \"lru-dict>=1.1.6,<2.0.0\",\n        \"eth-hash[pycryptodome]\",\n        \"requests>=2.16.0,<3.0.0\",\n    ],\n    setup_requires=['setuptools-markdown'],\n    extras_require={\n        'tester': [\n            \"eth-tester[py-evm]==0.1.0-beta.21\",\n            \"py-geth>=2.0.1,<3.0.0\",\n        ],\n        'testrpc': [\"eth-testrpc>=1.3.3,<2.0.0\"],\n        'linter': [\n            \"flake8==3.4.1\",\n            \"isort>=4.2.15,<5\",\n        ],\n        'platform_system==\"Windows\"': [\n            'pypiwin32'  # TODO: specify a version number, move under install_requires\n        ],\n    },\n    py_modules=['web3', 'ens'],\n    license=\"MIT\",\n    zip_safe=False,\n    keywords='ethereum',\n    packages=find_packages(exclude=[\"tests\", \"tests.*\"]),\n    classifiers=[\n        'Development Status :: 4 - Beta',\n        'Intended Audience :: Developers',\n        'License :: OSI Approved :: MIT License',\n        'Natural Language :: English',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.5',\n        'Programming Language :: Python :: 3.6',\n    ],\n)\n", "path": "setup.py"}, {"content": "import operator\n\nfrom cytoolz import (\n    assoc,\n    complement,\n    compose,\n    curry,\n    identity,\n    partial,\n    pipe,\n)\nfrom eth_utils import (\n    is_dict,\n    is_string,\n)\n\nfrom web3.middleware import (\n    construct_fixture_middleware,\n    construct_formatting_middleware,\n)\nfrom web3.utils.formatters import (\n    apply_formatter_if,\n    apply_formatter_to_array,\n    apply_formatters_to_args,\n    apply_formatters_to_dict,\n    apply_key_map,\n    hex_to_integer,\n    integer_to_hex,\n    is_array_of_dicts,\n    static_return,\n)\n\n\ndef is_named_block(value):\n    return value in {\"latest\", \"earliest\", \"pending\"}\n\n\nto_integer_if_hex = apply_formatter_if(is_string, hex_to_integer)\n\n\nis_not_named_block = complement(is_named_block)\n\n\nTRANSACTION_KEY_MAPPINGS = {\n    'block_hash': 'blockHash',\n    'block_number': 'blockNumber',\n    'gas_price': 'gasPrice',\n    'transaction_hash': 'transactionHash',\n    'transaction_index': 'transactionIndex',\n}\n\ntransaction_key_remapper = apply_key_map(TRANSACTION_KEY_MAPPINGS)\n\n\nLOG_KEY_MAPPINGS = {\n    'log_index': 'logIndex',\n    'transaction_index': 'transactionIndex',\n    'transaction_hash': 'transactionHash',\n    'block_hash': 'blockHash',\n    'block_number': 'blockNumber',\n}\n\n\nlog_key_remapper = apply_key_map(LOG_KEY_MAPPINGS)\n\n\nRECEIPT_KEY_MAPPINGS = {\n    'block_hash': 'blockHash',\n    'block_number': 'blockNumber',\n    'contract_address': 'contractAddress',\n    'gas_used': 'gasUsed',\n    'cumulative_gas_used': 'cumulativeGasUsed',\n    'transaction_hash': 'transactionHash',\n    'transaction_index': 'transactionIndex',\n}\n\n\nreceipt_key_remapper = apply_key_map(RECEIPT_KEY_MAPPINGS)\n\n\nBLOCK_KEY_MAPPINGS = {\n    'gas_limit': 'gasLimit',\n    'sha3_uncles': 'sha3Uncles',\n    'transactions_root': 'transactionsRoot',\n    'parent_hash': 'parentHash',\n    'bloom': 'logsBloom',\n    'state_root': 'stateRoot',\n    'receipt_root': 'receiptsRoot',\n    'total_difficulty': 'totalDifficulty',\n    'extra_data': 'extraData',\n    'gas_used': 'gasUsed',\n}\n\n\nblock_key_remapper = apply_key_map(BLOCK_KEY_MAPPINGS)\n\n\nTRANSACTION_PARAMS_MAPPING = {\n    'gasPrice': 'gas_price',\n}\n\n\ntransaction_params_remapper = apply_key_map(TRANSACTION_PARAMS_MAPPING)\n\n\nTRANSACTION_PARAMS_FORMATTERS = {\n    'gas': to_integer_if_hex,\n    'gasPrice': to_integer_if_hex,\n    'value': to_integer_if_hex,\n    'nonce': to_integer_if_hex,\n}\n\n\ntransaction_params_formatter = apply_formatters_to_dict(TRANSACTION_PARAMS_FORMATTERS)\n\n\nFILTER_PARAMS_MAPPINGS = {\n    'fromBlock': 'from_block',\n    'toBlock': 'to_block',\n}\n\nfilter_params_remapper = apply_key_map(FILTER_PARAMS_MAPPINGS)\n\nFILTER_PARAMS_FORMATTERS = {\n    'fromBlock': to_integer_if_hex,\n    'toBlock': to_integer_if_hex,\n}\n\nfilter_params_formatter = apply_formatters_to_dict(FILTER_PARAMS_FORMATTERS)\n\nfilter_params_transformer = compose(filter_params_remapper, filter_params_formatter)\n\n\nTRANSACTION_FORMATTERS = {\n    'to': apply_formatter_if(partial(operator.eq, ''), static_return(None)),\n}\n\n\ntransaction_formatter = apply_formatters_to_dict(TRANSACTION_FORMATTERS)\n\n\nRECEIPT_FORMATTERS = {\n    'logs': apply_formatter_to_array(log_key_remapper),\n}\n\n\nreceipt_formatter = apply_formatters_to_dict(RECEIPT_FORMATTERS)\n\ntransaction_params_transformer = compose(transaction_params_remapper, transaction_params_formatter)\n\nethereum_tester_middleware = construct_formatting_middleware(\n    request_formatters={\n        # Eth\n        'eth_getBlockByNumber': apply_formatters_to_args(\n            apply_formatter_if(is_not_named_block, to_integer_if_hex),\n        ),\n        'eth_getFilterChanges': apply_formatters_to_args(hex_to_integer),\n        'eth_getFilterLogs': apply_formatters_to_args(hex_to_integer),\n        'eth_getBlockTransactionCountByNumber': apply_formatters_to_args(\n            apply_formatter_if(is_not_named_block, to_integer_if_hex),\n        ),\n        'eth_getUncleCountByBlockNumber': apply_formatters_to_args(\n            apply_formatter_if(is_not_named_block, to_integer_if_hex),\n        ),\n        'eth_getTransactionByBlockHashAndIndex': apply_formatters_to_args(\n            identity,\n            to_integer_if_hex,\n        ),\n        'eth_getTransactionByBlockNumberAndIndex': apply_formatters_to_args(\n            apply_formatter_if(is_not_named_block, to_integer_if_hex),\n            to_integer_if_hex,\n        ),\n        'eth_getUncleByBlockNumberAndIndex': apply_formatters_to_args(\n            apply_formatter_if(is_not_named_block, to_integer_if_hex),\n            to_integer_if_hex,\n        ),\n        'eth_newFilter': apply_formatters_to_args(\n            filter_params_transformer,\n        ),\n        'eth_getLogs': apply_formatters_to_args(\n            filter_params_transformer,\n        ),\n        'eth_sendTransaction': apply_formatters_to_args(\n            transaction_params_transformer,\n        ),\n        'eth_estimateGas': apply_formatters_to_args(\n            transaction_params_transformer,\n        ),\n        'eth_call': apply_formatters_to_args(\n            transaction_params_transformer,\n        ),\n        'eth_uninstallFilter': apply_formatters_to_args(hex_to_integer),\n        # EVM\n        'evm_revert': apply_formatters_to_args(hex_to_integer),\n        # Personal\n        'personal_sendTransaction': apply_formatters_to_args(\n            transaction_params_transformer,\n            identity,\n        ),\n    },\n    result_formatters={\n        'eth_getBlockByHash': apply_formatter_if(\n            is_dict,\n            block_key_remapper,\n        ),\n        'eth_getBlockByNumber': apply_formatter_if(\n            is_dict,\n            block_key_remapper,\n        ),\n        'eth_getBlockTransactionCountByHash': apply_formatter_if(\n            is_dict,\n            transaction_key_remapper,\n        ),\n        'eth_getBlockTransactionCountByNumber': apply_formatter_if(\n            is_dict,\n            transaction_key_remapper,\n        ),\n        'eth_getTransactionByHash': apply_formatter_if(\n            is_dict,\n            compose(transaction_key_remapper, transaction_formatter),\n        ),\n        'eth_getTransactionReceipt': apply_formatter_if(\n            is_dict,\n            compose(receipt_key_remapper, receipt_formatter),\n        ),\n        'eth_newFilter': integer_to_hex,\n        'eth_newBlockFilter': integer_to_hex,\n        'eth_newPendingTransactionFilter': integer_to_hex,\n        'eth_getLogs': apply_formatter_if(\n            is_array_of_dicts,\n            apply_formatter_to_array(log_key_remapper),\n        ),\n        'eth_getFilterChanges': apply_formatter_if(\n            is_array_of_dicts,\n            apply_formatter_to_array(log_key_remapper),\n        ),\n        'eth_getFilterLogs': apply_formatter_if(\n            is_array_of_dicts,\n            apply_formatter_to_array(log_key_remapper),\n        ),\n        # EVM\n        'evm_snapshot': integer_to_hex,\n    },\n)\n\n\nethereum_tester_fixture_middleware = construct_fixture_middleware({\n    # Eth\n    'eth_protocolVersion': '63',\n    'eth_hashrate': 0,\n    'eth_gasPrice': 1,\n    'eth_syncing': False,\n    'eth_mining': False,\n    # Net\n    'net_version': '1',\n    'net_listening': False,\n    'net_peerCount': 0,\n})\n\n\ndef guess_from(web3, transaction):\n    coinbase = web3.eth.coinbase\n    if coinbase is not None:\n        return coinbase\n\n    try:\n        return web3.eth.accounts[0]\n    except KeyError as e:\n        # no accounts available to pre-fill, carry on\n        pass\n\n    return None\n\n\ndef guess_gas(web3, transaction):\n    return web3.eth.estimateGas(transaction) * 2\n\n\n@curry\ndef fill_default(field, guess_func, web3, transaction):\n    if field in transaction and transaction[field] is not None:\n        return transaction\n    else:\n        guess_val = guess_func(web3, transaction)\n        return assoc(transaction, field, guess_val)\n\n\ndef default_transaction_fields_middleware(make_request, web3):\n    fill_default_from = fill_default('from', guess_from, web3)\n    fill_default_gas = fill_default('gas', guess_gas, web3)\n\n    def middleware(method, params):\n        # TODO send call to eth-tester without gas, and remove guess_gas entirely\n        if method == 'eth_call':\n            filled_transaction = pipe(\n                params[0],\n                fill_default_from,\n                fill_default_gas,\n            )\n            return make_request(method, [filled_transaction] + params[1:])\n        elif method in (\n            'eth_estimateGas',\n            'eth_sendTransaction',\n        ):\n            filled_transaction = pipe(\n                params[0],\n                fill_default_from,\n            )\n            return make_request(method, [filled_transaction] + params[1:])\n        else:\n            return make_request(method, params)\n    return middleware\n", "path": "web3/providers/eth_tester/middleware.py"}]}