web3 7.0.0b1__py3-none-any.whl → 7.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ens/__init__.py +13 -2
- ens/_normalization.py +4 -4
- ens/async_ens.py +31 -21
- ens/base_ens.py +3 -1
- ens/contract_data.py +2 -2
- ens/ens.py +14 -11
- ens/exceptions.py +16 -29
- ens/specs/nf.json +1 -1
- ens/specs/normalization_spec.json +1 -1
- ens/utils.py +33 -41
- web3/__init__.py +23 -12
- web3/_utils/abi.py +162 -274
- web3/_utils/async_transactions.py +34 -20
- web3/_utils/batching.py +217 -0
- web3/_utils/blocks.py +6 -2
- web3/_utils/caching/__init__.py +12 -0
- web3/_utils/caching/caching_utils.py +433 -0
- web3/_utils/caching/request_caching_validation.py +287 -0
- web3/_utils/compat/__init__.py +2 -3
- web3/_utils/contract_sources/compile_contracts.py +1 -1
- web3/_utils/contract_sources/contract_data/ambiguous_function_contract.py +42 -0
- web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
- web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/event_contracts.py +50 -5
- web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
- web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
- web3/_utils/contracts.py +172 -220
- web3/_utils/datatypes.py +5 -1
- web3/_utils/decorators.py +6 -1
- web3/_utils/empty.py +1 -1
- web3/_utils/encoding.py +16 -12
- web3/_utils/error_formatters_utils.py +5 -3
- web3/_utils/events.py +78 -72
- web3/_utils/fee_utils.py +1 -3
- web3/_utils/filters.py +24 -22
- web3/_utils/formatters.py +2 -2
- web3/_utils/http.py +8 -2
- web3/_utils/http_session_manager.py +314 -0
- web3/_utils/math.py +14 -15
- web3/_utils/method_formatters.py +161 -34
- web3/_utils/module.py +2 -1
- web3/_utils/module_testing/__init__.py +3 -2
- web3/_utils/module_testing/eth_module.py +736 -583
- web3/_utils/module_testing/go_ethereum_debug_module.py +128 -0
- web3/_utils/module_testing/module_testing_utils.py +81 -24
- web3/_utils/module_testing/persistent_connection_provider.py +702 -220
- web3/_utils/module_testing/utils.py +114 -33
- web3/_utils/module_testing/web3_module.py +438 -17
- web3/_utils/normalizers.py +13 -11
- web3/_utils/rpc_abi.py +10 -22
- web3/_utils/threads.py +8 -7
- web3/_utils/transactions.py +32 -25
- web3/_utils/type_conversion.py +5 -1
- web3/_utils/validation.py +20 -17
- web3/beacon/__init__.py +5 -0
- web3/beacon/api_endpoints.py +3 -0
- web3/beacon/async_beacon.py +29 -6
- web3/beacon/beacon.py +24 -6
- web3/contract/__init__.py +7 -0
- web3/contract/async_contract.py +285 -82
- web3/contract/base_contract.py +556 -258
- web3/contract/contract.py +295 -84
- web3/contract/utils.py +251 -55
- web3/datastructures.py +56 -41
- web3/eth/__init__.py +7 -0
- web3/eth/async_eth.py +89 -69
- web3/eth/base_eth.py +7 -3
- web3/eth/eth.py +43 -66
- web3/exceptions.py +158 -83
- web3/gas_strategies/time_based.py +8 -6
- web3/geth.py +53 -184
- web3/main.py +77 -43
- web3/manager.py +368 -101
- web3/method.py +43 -15
- web3/middleware/__init__.py +26 -8
- web3/middleware/attrdict.py +12 -22
- web3/middleware/base.py +55 -2
- web3/middleware/filter.py +45 -23
- web3/middleware/formatting.py +6 -3
- web3/middleware/names.py +4 -1
- web3/middleware/signing.py +15 -6
- web3/middleware/stalecheck.py +2 -1
- web3/module.py +62 -26
- web3/providers/__init__.py +21 -0
- web3/providers/async_base.py +93 -38
- web3/providers/base.py +85 -40
- web3/providers/eth_tester/__init__.py +5 -0
- web3/providers/eth_tester/defaults.py +2 -55
- web3/providers/eth_tester/main.py +57 -35
- web3/providers/eth_tester/middleware.py +16 -17
- web3/providers/ipc.py +42 -18
- web3/providers/legacy_websocket.py +27 -2
- web3/providers/persistent/__init__.py +7 -0
- web3/providers/persistent/async_ipc.py +61 -121
- web3/providers/persistent/persistent.py +324 -17
- web3/providers/persistent/persistent_connection.py +54 -5
- web3/providers/persistent/request_processor.py +136 -56
- web3/providers/persistent/subscription_container.py +56 -0
- web3/providers/persistent/subscription_manager.py +233 -0
- web3/providers/persistent/websocket.py +29 -92
- web3/providers/rpc/__init__.py +5 -0
- web3/providers/rpc/async_rpc.py +73 -18
- web3/providers/rpc/rpc.py +73 -30
- web3/providers/rpc/utils.py +1 -13
- web3/scripts/install_pre_releases.py +33 -0
- web3/scripts/parse_pygeth_version.py +16 -0
- web3/testing.py +4 -4
- web3/tracing.py +9 -5
- web3/types.py +141 -74
- web3/utils/__init__.py +64 -5
- web3/utils/abi.py +790 -10
- web3/utils/address.py +8 -0
- web3/utils/async_exception_handling.py +20 -11
- web3/utils/caching.py +34 -4
- web3/utils/exception_handling.py +9 -12
- web3/utils/subscriptions.py +285 -0
- {web3-7.0.0b1.dist-info → web3-7.7.0.dist-info}/LICENSE +1 -1
- web3-7.7.0.dist-info/METADATA +130 -0
- web3-7.7.0.dist-info/RECORD +171 -0
- {web3-7.0.0b1.dist-info → web3-7.7.0.dist-info}/WHEEL +1 -1
- {web3-7.0.0b1.dist-info → web3-7.7.0.dist-info}/top_level.txt +0 -1
- ethpm/__init__.py +0 -20
- ethpm/_utils/__init__.py +0 -0
- ethpm/_utils/backend.py +0 -93
- ethpm/_utils/cache.py +0 -44
- ethpm/_utils/chains.py +0 -119
- ethpm/_utils/contract.py +0 -35
- ethpm/_utils/deployments.py +0 -145
- ethpm/_utils/ipfs.py +0 -116
- ethpm/_utils/protobuf/__init__.py +0 -0
- ethpm/_utils/protobuf/ipfs_file_pb2.py +0 -33
- ethpm/_utils/registry.py +0 -29
- ethpm/assets/__init__.py +0 -0
- ethpm/assets/ens/v3.json +0 -1
- ethpm/assets/escrow/with_bytecode_v3.json +0 -1
- ethpm/assets/ipfs_file.proto +0 -32
- ethpm/assets/owned/output_v3.json +0 -1
- ethpm/assets/owned/with_contract_type_v3.json +0 -1
- ethpm/assets/registry/contracts/Authority.sol +0 -156
- ethpm/assets/registry/contracts/IndexedOrderedSetLib.sol +0 -106
- ethpm/assets/registry/contracts/PackageDB.sol +0 -225
- ethpm/assets/registry/contracts/PackageRegistry.sol +0 -361
- ethpm/assets/registry/contracts/PackageRegistryInterface.sol +0 -97
- ethpm/assets/registry/contracts/ReleaseDB.sol +0 -309
- ethpm/assets/registry/contracts/ReleaseValidator.sol +0 -152
- ethpm/assets/registry/solc_input.json +0 -1
- ethpm/assets/registry/solc_output.json +0 -1
- ethpm/assets/registry/v3.json +0 -1
- ethpm/assets/safe-math-lib/v3-strict-no-deployments.json +0 -1
- ethpm/assets/simple-registry/contracts/Ownable.sol +0 -63
- ethpm/assets/simple-registry/contracts/PackageRegistry.sol +0 -373
- ethpm/assets/simple-registry/contracts/PackageRegistryInterface.sol +0 -96
- ethpm/assets/simple-registry/solc_input.json +0 -33
- ethpm/assets/simple-registry/solc_output.json +0 -1
- ethpm/assets/simple-registry/v3.json +0 -1
- ethpm/assets/standard-token/output_v3.json +0 -1
- ethpm/assets/standard-token/with_bytecode_v3.json +0 -1
- ethpm/assets/vyper_registry/0.1.0.json +0 -1
- ethpm/assets/vyper_registry/registry.vy +0 -216
- ethpm/assets/vyper_registry/registry_with_delete.vy +0 -244
- ethpm/backends/__init__.py +0 -0
- ethpm/backends/base.py +0 -43
- ethpm/backends/http.py +0 -108
- ethpm/backends/ipfs.py +0 -219
- ethpm/backends/registry.py +0 -154
- ethpm/constants.py +0 -17
- ethpm/contract.py +0 -187
- ethpm/dependencies.py +0 -58
- ethpm/deployments.py +0 -80
- ethpm/ethpm-spec/examples/escrow/1.0.0-pretty.json +0 -146
- ethpm/ethpm-spec/examples/escrow/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/escrow/contracts/Escrow.sol +0 -32
- ethpm/ethpm-spec/examples/escrow/contracts/SafeSendLib.sol +0 -20
- ethpm/ethpm-spec/examples/escrow/v3-pretty.json +0 -171
- ethpm/ethpm-spec/examples/escrow/v3.json +0 -1
- ethpm/ethpm-spec/examples/owned/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/owned/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/owned/contracts/Owned.sol +0 -12
- ethpm/ethpm-spec/examples/owned/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/owned/v3.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/1.0.0-pretty.json +0 -31
- ethpm/ethpm-spec/examples/piper-coin/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/piper-coin/v3-pretty.json +0 -21
- ethpm/ethpm-spec/examples/piper-coin/v3.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0-pretty.json +0 -85
- ethpm/ethpm-spec/examples/safe-math-lib/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/safe-math-lib/contracts/SafeMathLib.sol +0 -24
- ethpm/ethpm-spec/examples/safe-math-lib/v3-pretty.json +0 -117
- ethpm/ethpm-spec/examples/safe-math-lib/v3.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/1.0.0-pretty.json +0 -55
- ethpm/ethpm-spec/examples/standard-token/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/standard-token/contracts/AbstractToken.sol +0 -20
- ethpm/ethpm-spec/examples/standard-token/contracts/StandardToken.sol +0 -84
- ethpm/ethpm-spec/examples/standard-token/v3-pretty.json +0 -460
- ethpm/ethpm-spec/examples/standard-token/v3.json +0 -1
- ethpm/ethpm-spec/examples/transferable/1.0.0-pretty.json +0 -21
- ethpm/ethpm-spec/examples/transferable/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/transferable/contracts/Transferable.sol +0 -14
- ethpm/ethpm-spec/examples/transferable/v3-pretty.json +0 -27
- ethpm/ethpm-spec/examples/transferable/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet/1.0.0-pretty.json +0 -120
- ethpm/ethpm-spec/examples/wallet/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet/contracts/Wallet.sol +0 -41
- ethpm/ethpm-spec/examples/wallet/v3-pretty.json +0 -181
- ethpm/ethpm-spec/examples/wallet/v3.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0-pretty.json +0 -135
- ethpm/ethpm-spec/examples/wallet-with-send/1.0.0.json +0 -1
- ethpm/ethpm-spec/examples/wallet-with-send/contracts/WalletWithSend.sol +0 -18
- ethpm/ethpm-spec/examples/wallet-with-send/v3-pretty.json +0 -207
- ethpm/ethpm-spec/examples/wallet-with-send/v3.json +0 -1
- ethpm/ethpm-spec/spec/package.spec.json +0 -379
- ethpm/ethpm-spec/spec/v3.spec.json +0 -483
- ethpm/exceptions.py +0 -68
- ethpm/package.py +0 -438
- ethpm/tools/__init__.py +0 -4
- ethpm/tools/builder.py +0 -930
- ethpm/tools/checker.py +0 -312
- ethpm/tools/get_manifest.py +0 -19
- ethpm/uri.py +0 -141
- ethpm/validation/__init__.py +0 -0
- ethpm/validation/manifest.py +0 -146
- ethpm/validation/misc.py +0 -39
- ethpm/validation/package.py +0 -80
- ethpm/validation/uri.py +0 -163
- web3/_utils/caching.py +0 -155
- web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
- web3/_utils/module_testing/go_ethereum_personal_module.py +0 -300
- web3/_utils/request.py +0 -265
- web3/pm.py +0 -602
- web3/tools/__init__.py +0 -4
- web3/tools/benchmark/__init__.py +0 -0
- web3/tools/benchmark/main.py +0 -185
- web3/tools/benchmark/node.py +0 -126
- web3/tools/benchmark/reporting.py +0 -39
- web3/tools/benchmark/utils.py +0 -69
- web3/tools/pytest_ethereum/__init__.py +0 -0
- web3/tools/pytest_ethereum/_utils.py +0 -145
- web3/tools/pytest_ethereum/deployer.py +0 -48
- web3/tools/pytest_ethereum/exceptions.py +0 -22
- web3/tools/pytest_ethereum/linker.py +0 -128
- web3/tools/pytest_ethereum/plugins.py +0 -33
- web3-7.0.0b1.dist-info/METADATA +0 -114
- web3-7.0.0b1.dist-info/RECORD +0 -280
- web3-7.0.0b1.dist-info/entry_points.txt +0 -2
- /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
web3/tools/benchmark/main.py
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import argparse
|
|
2
|
-
import asyncio
|
|
3
|
-
from collections import (
|
|
4
|
-
defaultdict,
|
|
5
|
-
)
|
|
6
|
-
import logging
|
|
7
|
-
import sys
|
|
8
|
-
import timeit
|
|
9
|
-
from typing import (
|
|
10
|
-
Any,
|
|
11
|
-
Callable,
|
|
12
|
-
Dict,
|
|
13
|
-
Union,
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
from web3 import (
|
|
17
|
-
AsyncHTTPProvider,
|
|
18
|
-
AsyncWeb3,
|
|
19
|
-
HTTPProvider,
|
|
20
|
-
Web3,
|
|
21
|
-
)
|
|
22
|
-
from web3.middleware import (
|
|
23
|
-
BufferedGasEstimateMiddleware,
|
|
24
|
-
GasPriceStrategyMiddleware,
|
|
25
|
-
)
|
|
26
|
-
from web3.tools.benchmark.node import (
|
|
27
|
-
GethBenchmarkFixture,
|
|
28
|
-
)
|
|
29
|
-
from web3.tools.benchmark.reporting import (
|
|
30
|
-
print_entry,
|
|
31
|
-
print_footer,
|
|
32
|
-
print_header,
|
|
33
|
-
)
|
|
34
|
-
from web3.tools.benchmark.utils import (
|
|
35
|
-
wait_for_aiohttp,
|
|
36
|
-
wait_for_http,
|
|
37
|
-
)
|
|
38
|
-
from web3.types import (
|
|
39
|
-
Wei,
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
KEYFILE_PW = "web3py-test"
|
|
43
|
-
|
|
44
|
-
parser = argparse.ArgumentParser()
|
|
45
|
-
parser.add_argument(
|
|
46
|
-
"--num-calls",
|
|
47
|
-
type=int,
|
|
48
|
-
default=10,
|
|
49
|
-
help="The number of RPC calls to make",
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
# TODO - layers to test:
|
|
53
|
-
# contract.functions.method(...).call()
|
|
54
|
-
# w3.eth.call(...)
|
|
55
|
-
# HTTPProvider.make_request(...)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def build_web3_http(endpoint_uri: str) -> Web3:
|
|
59
|
-
wait_for_http(endpoint_uri)
|
|
60
|
-
_w3 = Web3(
|
|
61
|
-
HTTPProvider(endpoint_uri),
|
|
62
|
-
middlewares=[GasPriceStrategyMiddleware, BufferedGasEstimateMiddleware],
|
|
63
|
-
)
|
|
64
|
-
return _w3
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
async def build_async_w3_http(endpoint_uri: str) -> AsyncWeb3:
|
|
68
|
-
await wait_for_aiohttp(endpoint_uri)
|
|
69
|
-
_w3 = AsyncWeb3(
|
|
70
|
-
AsyncHTTPProvider(endpoint_uri),
|
|
71
|
-
middlewares=[GasPriceStrategyMiddleware, BufferedGasEstimateMiddleware],
|
|
72
|
-
)
|
|
73
|
-
return _w3
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def sync_benchmark(func: Callable[..., Any], n: int) -> Union[float, str]:
|
|
77
|
-
try:
|
|
78
|
-
starttime = timeit.default_timer()
|
|
79
|
-
for _ in range(n):
|
|
80
|
-
func()
|
|
81
|
-
endtime = timeit.default_timer()
|
|
82
|
-
execution_time = endtime - starttime
|
|
83
|
-
return execution_time
|
|
84
|
-
except Exception:
|
|
85
|
-
return "N/A"
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
async def async_benchmark(func: Callable[..., Any], n: int) -> Union[float, str]:
|
|
89
|
-
try:
|
|
90
|
-
starttime = timeit.default_timer()
|
|
91
|
-
for result in asyncio.as_completed([func() for _ in range(n)]):
|
|
92
|
-
await result
|
|
93
|
-
execution_time = timeit.default_timer() - starttime
|
|
94
|
-
return execution_time
|
|
95
|
-
except Exception:
|
|
96
|
-
return "N/A"
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def main(logger: logging.Logger, num_calls: int) -> None:
|
|
100
|
-
fixture = GethBenchmarkFixture()
|
|
101
|
-
for built_fixture in fixture.build():
|
|
102
|
-
for _ in built_fixture:
|
|
103
|
-
w3_http = build_web3_http(fixture.endpoint_uri)
|
|
104
|
-
try:
|
|
105
|
-
loop = asyncio.get_running_loop()
|
|
106
|
-
except RuntimeError:
|
|
107
|
-
loop = asyncio.new_event_loop()
|
|
108
|
-
asyncio.set_event_loop(loop)
|
|
109
|
-
|
|
110
|
-
# -- sync -- #
|
|
111
|
-
coinbase = w3_http.eth.coinbase
|
|
112
|
-
|
|
113
|
-
# -- async -- #
|
|
114
|
-
async_w3_http = loop.run_until_complete(
|
|
115
|
-
build_async_w3_http(fixture.endpoint_uri)
|
|
116
|
-
)
|
|
117
|
-
async_coinbase = loop.run_until_complete(async_w3_http.eth.coinbase)
|
|
118
|
-
|
|
119
|
-
methods = [
|
|
120
|
-
{
|
|
121
|
-
"name": "eth_gasPrice",
|
|
122
|
-
"params": {},
|
|
123
|
-
"exec": lambda: w3_http.eth.gas_price,
|
|
124
|
-
"async_exec": lambda: async_w3_http.eth.gas_price,
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
"name": "eth_sendTransaction",
|
|
128
|
-
"params": {},
|
|
129
|
-
"exec": lambda: w3_http.eth.send_transaction(
|
|
130
|
-
{
|
|
131
|
-
"to": "0xd3CdA913deB6f67967B99D67aCDFa1712C293601",
|
|
132
|
-
"from": coinbase,
|
|
133
|
-
"value": Wei(1),
|
|
134
|
-
}
|
|
135
|
-
),
|
|
136
|
-
"async_exec": lambda: async_w3_http.eth.send_transaction(
|
|
137
|
-
{
|
|
138
|
-
"to": "0xd3CdA913deB6f67967B99D67aCDFa1712C293601",
|
|
139
|
-
"from": async_coinbase,
|
|
140
|
-
"value": Wei(1),
|
|
141
|
-
}
|
|
142
|
-
),
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
"name": "eth_blockNumber",
|
|
146
|
-
"params": {},
|
|
147
|
-
"exec": lambda: w3_http.eth.block_number,
|
|
148
|
-
"async_exec": lambda: async_w3_http.eth.block_number,
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
"name": "eth_getBlock",
|
|
152
|
-
"params": {},
|
|
153
|
-
"exec": lambda: w3_http.eth.get_block(1),
|
|
154
|
-
"async_exec": lambda: async_w3_http.eth.get_block(1),
|
|
155
|
-
},
|
|
156
|
-
]
|
|
157
|
-
|
|
158
|
-
def benchmark(method: Dict[str, Any]) -> None:
|
|
159
|
-
outcomes: Dict[str, Union[str, float]] = defaultdict(lambda: "N/A")
|
|
160
|
-
outcomes["name"] = method["name"]
|
|
161
|
-
outcomes["HTTPProvider"] = sync_benchmark(
|
|
162
|
-
method["exec"],
|
|
163
|
-
num_calls,
|
|
164
|
-
)
|
|
165
|
-
outcomes["AsyncHTTPProvider"] = loop.run_until_complete(
|
|
166
|
-
async_benchmark(method["async_exec"], num_calls)
|
|
167
|
-
)
|
|
168
|
-
print_entry(logger, outcomes)
|
|
169
|
-
|
|
170
|
-
print_header(logger, num_calls)
|
|
171
|
-
|
|
172
|
-
for method in methods:
|
|
173
|
-
benchmark(method)
|
|
174
|
-
|
|
175
|
-
print_footer(logger)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if __name__ == "__main__":
|
|
179
|
-
args = parser.parse_args()
|
|
180
|
-
|
|
181
|
-
logger = logging.getLogger()
|
|
182
|
-
logger.setLevel(logging.INFO)
|
|
183
|
-
logger.addHandler(logging.StreamHandler(sys.stdout))
|
|
184
|
-
|
|
185
|
-
main(logger, args.num_calls)
|
web3/tools/benchmark/node.py
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import socket
|
|
3
|
-
from subprocess import (
|
|
4
|
-
PIPE,
|
|
5
|
-
Popen,
|
|
6
|
-
check_output,
|
|
7
|
-
)
|
|
8
|
-
from tempfile import (
|
|
9
|
-
TemporaryDirectory,
|
|
10
|
-
)
|
|
11
|
-
from typing import (
|
|
12
|
-
Any,
|
|
13
|
-
Generator,
|
|
14
|
-
Sequence,
|
|
15
|
-
)
|
|
16
|
-
import zipfile
|
|
17
|
-
|
|
18
|
-
from geth.install import (
|
|
19
|
-
get_executable_path,
|
|
20
|
-
install_geth,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
from web3.tools.benchmark.utils import (
|
|
24
|
-
kill_proc_gracefully,
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
GETH_FIXTURE_ZIP = "geth-1.13.11-fixture.zip"
|
|
28
|
-
|
|
29
|
-
# use same coinbase value as in `web3.py/tests/integration/generate_fixtures/common.py`
|
|
30
|
-
COINBASE = "0xdc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class GethBenchmarkFixture:
|
|
34
|
-
def __init__(self) -> None:
|
|
35
|
-
self.rpc_port = self._rpc_port()
|
|
36
|
-
self.endpoint_uri = self._endpoint_uri()
|
|
37
|
-
self.geth_binary = self._geth_binary()
|
|
38
|
-
|
|
39
|
-
def build(self) -> Generator[Any, None, None]:
|
|
40
|
-
with TemporaryDirectory() as base_dir:
|
|
41
|
-
zipfile_path = os.path.abspath(
|
|
42
|
-
os.path.join(
|
|
43
|
-
os.path.dirname(__file__),
|
|
44
|
-
"../../../tests/integration/",
|
|
45
|
-
GETH_FIXTURE_ZIP,
|
|
46
|
-
)
|
|
47
|
-
)
|
|
48
|
-
tmp_datadir = os.path.join(str(base_dir), "datadir")
|
|
49
|
-
with zipfile.ZipFile(zipfile_path, "r") as zip_ref:
|
|
50
|
-
zip_ref.extractall(tmp_datadir)
|
|
51
|
-
self.datadir = tmp_datadir
|
|
52
|
-
|
|
53
|
-
genesis_file = os.path.join(self.datadir, "genesis.json")
|
|
54
|
-
|
|
55
|
-
yield self._geth_process(self.datadir, genesis_file, self.rpc_port)
|
|
56
|
-
|
|
57
|
-
def _rpc_port(self) -> str:
|
|
58
|
-
sock = socket.socket()
|
|
59
|
-
sock.bind(("127.0.0.1", 0))
|
|
60
|
-
port = sock.getsockname()[1]
|
|
61
|
-
sock.close()
|
|
62
|
-
return str(port)
|
|
63
|
-
|
|
64
|
-
def _endpoint_uri(self) -> str:
|
|
65
|
-
return f"http://localhost:{self.rpc_port}"
|
|
66
|
-
|
|
67
|
-
def _geth_binary(self) -> str:
|
|
68
|
-
if "GETH_BINARY" in os.environ:
|
|
69
|
-
return os.environ["GETH_BINARY"]
|
|
70
|
-
elif "GETH_VERSION" in os.environ:
|
|
71
|
-
geth_version = os.environ["GETH_VERSION"]
|
|
72
|
-
_geth_binary = get_executable_path(geth_version)
|
|
73
|
-
if not os.path.exists(_geth_binary):
|
|
74
|
-
install_geth(geth_version)
|
|
75
|
-
assert os.path.exists(_geth_binary)
|
|
76
|
-
return _geth_binary
|
|
77
|
-
else:
|
|
78
|
-
return "geth"
|
|
79
|
-
|
|
80
|
-
def _geth_command_arguments(self, datadir: str) -> Sequence[str]:
|
|
81
|
-
return (
|
|
82
|
-
self.geth_binary,
|
|
83
|
-
"--dev",
|
|
84
|
-
"--dev.period",
|
|
85
|
-
"100",
|
|
86
|
-
"--datadir",
|
|
87
|
-
str(datadir),
|
|
88
|
-
"--nodiscover",
|
|
89
|
-
"--http",
|
|
90
|
-
"--http.port",
|
|
91
|
-
self.rpc_port,
|
|
92
|
-
"--http.api",
|
|
93
|
-
"admin,eth,net,web3",
|
|
94
|
-
"--ipcdisable",
|
|
95
|
-
"--allow-insecure-unlock",
|
|
96
|
-
"--miner.etherbase",
|
|
97
|
-
COINBASE[2:],
|
|
98
|
-
"--password",
|
|
99
|
-
os.path.join(datadir, "keystore", "pw.txt"),
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
def _geth_process(
|
|
103
|
-
self, datadir: str, genesis_file: str, rpc_port: str
|
|
104
|
-
) -> Generator[Any, None, None]:
|
|
105
|
-
init_datadir_command = (
|
|
106
|
-
self.geth_binary,
|
|
107
|
-
"--datadir",
|
|
108
|
-
str(datadir),
|
|
109
|
-
"init",
|
|
110
|
-
str(genesis_file),
|
|
111
|
-
)
|
|
112
|
-
check_output(
|
|
113
|
-
init_datadir_command,
|
|
114
|
-
stdin=PIPE,
|
|
115
|
-
stderr=PIPE,
|
|
116
|
-
)
|
|
117
|
-
proc = Popen(
|
|
118
|
-
self._geth_command_arguments(datadir),
|
|
119
|
-
stdin=PIPE,
|
|
120
|
-
stdout=PIPE,
|
|
121
|
-
stderr=PIPE,
|
|
122
|
-
)
|
|
123
|
-
try:
|
|
124
|
-
yield proc
|
|
125
|
-
finally:
|
|
126
|
-
kill_proc_gracefully(proc)
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
from logging import (
|
|
2
|
-
Logger,
|
|
3
|
-
)
|
|
4
|
-
from typing import (
|
|
5
|
-
Any,
|
|
6
|
-
Dict,
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def print_header(logger: Logger, num_calls: int) -> None:
|
|
11
|
-
logger.info(
|
|
12
|
-
"|{:^26}|{:^20}|{:^20}|{:^20}|{:^20}|".format(
|
|
13
|
-
f"Method ({num_calls} calls)",
|
|
14
|
-
"HTTPProvider",
|
|
15
|
-
"AsyncHTTProvider",
|
|
16
|
-
"IPCProvider",
|
|
17
|
-
"WebSocketProvider",
|
|
18
|
-
)
|
|
19
|
-
)
|
|
20
|
-
logger.info("-" * 112)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def print_entry(
|
|
24
|
-
logger: Logger,
|
|
25
|
-
method_benchmarks: Dict[str, Any],
|
|
26
|
-
) -> None:
|
|
27
|
-
logger.info(
|
|
28
|
-
"|{:^26}|{:^20.10}|{:^20.10}|{:^20.10}|{:^20.10}|".format(
|
|
29
|
-
method_benchmarks["name"],
|
|
30
|
-
method_benchmarks["HTTPProvider"],
|
|
31
|
-
method_benchmarks["AsyncHTTPProvider"],
|
|
32
|
-
method_benchmarks["IPCProvider"],
|
|
33
|
-
method_benchmarks["WebSocketProvider"],
|
|
34
|
-
)
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def print_footer(logger: Logger) -> None:
|
|
39
|
-
logger.info("-" * 112)
|
web3/tools/benchmark/utils.py
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import signal
|
|
3
|
-
import socket
|
|
4
|
-
import time
|
|
5
|
-
from typing import (
|
|
6
|
-
Any,
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
import aiohttp
|
|
10
|
-
import requests
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def wait_for_socket(ipc_path: str, timeout: int = 30) -> None:
|
|
14
|
-
start = time.time()
|
|
15
|
-
while time.time() < start + timeout:
|
|
16
|
-
try:
|
|
17
|
-
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
18
|
-
sock.connect(ipc_path)
|
|
19
|
-
sock.settimeout(timeout)
|
|
20
|
-
except (FileNotFoundError, socket.error):
|
|
21
|
-
time.sleep(0.01)
|
|
22
|
-
else:
|
|
23
|
-
break
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def wait_for_http(endpoint_uri: str, timeout: int = 60) -> None:
|
|
27
|
-
start = time.time()
|
|
28
|
-
while time.time() < start + timeout:
|
|
29
|
-
try:
|
|
30
|
-
requests.get(endpoint_uri)
|
|
31
|
-
except requests.ConnectionError:
|
|
32
|
-
time.sleep(0.01)
|
|
33
|
-
else:
|
|
34
|
-
break
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
async def wait_for_aiohttp(endpoint_uri: str, timeout: int = 60) -> None:
|
|
38
|
-
start = time.time()
|
|
39
|
-
while time.time() < start + timeout:
|
|
40
|
-
try:
|
|
41
|
-
async with aiohttp.ClientSession() as session:
|
|
42
|
-
await session.get(endpoint_uri)
|
|
43
|
-
except aiohttp.client_exceptions.ClientConnectorError:
|
|
44
|
-
await asyncio.sleep(0.01)
|
|
45
|
-
else:
|
|
46
|
-
break
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def wait_for_popen(proc: Any, timeout: int) -> None:
|
|
50
|
-
start = time.time()
|
|
51
|
-
while time.time() < start + timeout:
|
|
52
|
-
if proc.poll() is None:
|
|
53
|
-
time.sleep(0.01)
|
|
54
|
-
else:
|
|
55
|
-
break
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def kill_proc_gracefully(proc: Any) -> None:
|
|
59
|
-
if proc.poll() is None:
|
|
60
|
-
proc.send_signal(signal.SIGINT)
|
|
61
|
-
wait_for_popen(proc, 13)
|
|
62
|
-
|
|
63
|
-
if proc.poll() is None:
|
|
64
|
-
proc.terminate()
|
|
65
|
-
wait_for_popen(proc, 5)
|
|
66
|
-
|
|
67
|
-
if proc.poll() is None:
|
|
68
|
-
proc.kill()
|
|
69
|
-
wait_for_popen(proc, 2)
|
|
File without changes
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
from typing import (
|
|
2
|
-
Any,
|
|
3
|
-
Dict,
|
|
4
|
-
Iterable,
|
|
5
|
-
List,
|
|
6
|
-
Tuple,
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
from eth_typing import (
|
|
10
|
-
URI,
|
|
11
|
-
Address,
|
|
12
|
-
ContractName,
|
|
13
|
-
Manifest,
|
|
14
|
-
)
|
|
15
|
-
from eth_utils import (
|
|
16
|
-
to_dict,
|
|
17
|
-
to_hex,
|
|
18
|
-
to_list,
|
|
19
|
-
)
|
|
20
|
-
from eth_utils.toolz import (
|
|
21
|
-
assoc,
|
|
22
|
-
assoc_in,
|
|
23
|
-
dissoc,
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
from ethpm import (
|
|
27
|
-
Package,
|
|
28
|
-
)
|
|
29
|
-
from ethpm.uri import (
|
|
30
|
-
check_if_chain_matches_chain_uri,
|
|
31
|
-
)
|
|
32
|
-
from web3 import (
|
|
33
|
-
Web3,
|
|
34
|
-
)
|
|
35
|
-
from web3.tools.pytest_ethereum.exceptions import (
|
|
36
|
-
LinkerError,
|
|
37
|
-
)
|
|
38
|
-
from web3.types import (
|
|
39
|
-
TxReceipt,
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def pluck_matching_uri(deployment_data: Dict[URI, Dict[str, str]], w3: Web3) -> URI:
|
|
44
|
-
"""
|
|
45
|
-
Return any blockchain uri that matches w3-connected chain, if one
|
|
46
|
-
is present in the deployment data keys.
|
|
47
|
-
"""
|
|
48
|
-
for uri in deployment_data.keys():
|
|
49
|
-
if check_if_chain_matches_chain_uri(w3, uri):
|
|
50
|
-
return uri
|
|
51
|
-
raise LinkerError(
|
|
52
|
-
"No matching blockchain URI found in deployment_data: "
|
|
53
|
-
f"{list(deployment_data.keys())}, for w3 instance: {w3.__repr__()}."
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def contains_matching_uri(deployment_data: Dict[str, Dict[str, str]], w3: Web3) -> bool:
|
|
58
|
-
"""
|
|
59
|
-
Returns true if any blockchain uri in deployment data matches
|
|
60
|
-
w3-connected chain.
|
|
61
|
-
"""
|
|
62
|
-
for uri in deployment_data.keys():
|
|
63
|
-
if check_if_chain_matches_chain_uri(w3, uri):
|
|
64
|
-
return True
|
|
65
|
-
return False
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def insert_deployment(
|
|
69
|
-
package: Package,
|
|
70
|
-
deployment_name: str,
|
|
71
|
-
deployment_data: Dict[str, str],
|
|
72
|
-
latest_block_uri: URI,
|
|
73
|
-
) -> Manifest:
|
|
74
|
-
"""
|
|
75
|
-
Returns a new manifest. If a matching chain uri is found
|
|
76
|
-
in the old manifest, it will update the chain uri along
|
|
77
|
-
with the new deployment data. If no match, it will simply add
|
|
78
|
-
the new chain uri and deployment data.
|
|
79
|
-
"""
|
|
80
|
-
old_deployments_data = package.manifest.get("deployments")
|
|
81
|
-
if old_deployments_data and contains_matching_uri(old_deployments_data, package.w3):
|
|
82
|
-
old_chain_uri = pluck_matching_uri(old_deployments_data, package.w3)
|
|
83
|
-
old_deployments_chain_data = old_deployments_data[old_chain_uri]
|
|
84
|
-
# Replace specific on-chain deployment (i.e. deployment_name)
|
|
85
|
-
new_deployments_chain_data_init = dissoc(
|
|
86
|
-
old_deployments_chain_data, deployment_name
|
|
87
|
-
)
|
|
88
|
-
new_deployments_chain_data = {
|
|
89
|
-
**new_deployments_chain_data_init,
|
|
90
|
-
**{deployment_name: deployment_data},
|
|
91
|
-
}
|
|
92
|
-
# Replace all on-chain deployments
|
|
93
|
-
new_deployments_data_init = dissoc(
|
|
94
|
-
old_deployments_data, "deployments", old_chain_uri
|
|
95
|
-
)
|
|
96
|
-
new_deployments_data = {
|
|
97
|
-
**new_deployments_data_init,
|
|
98
|
-
**{latest_block_uri: new_deployments_chain_data},
|
|
99
|
-
}
|
|
100
|
-
return assoc(package.manifest, "deployments", new_deployments_data)
|
|
101
|
-
|
|
102
|
-
return assoc_in(
|
|
103
|
-
package.manifest,
|
|
104
|
-
("deployments", latest_block_uri, deployment_name),
|
|
105
|
-
deployment_data,
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
@to_dict
|
|
110
|
-
def create_deployment_data(
|
|
111
|
-
contract_name: ContractName,
|
|
112
|
-
new_address: Address,
|
|
113
|
-
tx_receipt: TxReceipt,
|
|
114
|
-
link_refs: List[Dict[str, Any]] = None,
|
|
115
|
-
) -> Iterable[Tuple[str, Any]]:
|
|
116
|
-
yield "contractType", contract_name
|
|
117
|
-
yield "address", new_address
|
|
118
|
-
yield "transaction", to_hex(tx_receipt["transactionHash"])
|
|
119
|
-
yield "block", to_hex(tx_receipt["blockHash"])
|
|
120
|
-
if link_refs:
|
|
121
|
-
yield "runtimeBytecode", {"linkDependencies": create_link_dep(link_refs)}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
@to_list
|
|
125
|
-
def create_link_dep(link_refs: List[Dict[str, Any]]) -> Iterable[Dict[str, Any]]:
|
|
126
|
-
for link_ref in link_refs:
|
|
127
|
-
yield {
|
|
128
|
-
"offsets": link_ref["offsets"],
|
|
129
|
-
"type": "reference",
|
|
130
|
-
"value": link_ref["name"],
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def get_deployment_address(linked_type: str, package: Package) -> Address:
|
|
135
|
-
"""
|
|
136
|
-
Return the address of a linked_type found in a package's manifest deployments.
|
|
137
|
-
"""
|
|
138
|
-
try:
|
|
139
|
-
deployment_address = package.deployments.get(linked_type)["address"]
|
|
140
|
-
except KeyError:
|
|
141
|
-
raise LinkerError(
|
|
142
|
-
f"Package data does not contain a valid deployment of {linked_type} on the "
|
|
143
|
-
"current w3-connected chain."
|
|
144
|
-
)
|
|
145
|
-
return deployment_address
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
from typing import (
|
|
2
|
-
Any,
|
|
3
|
-
Callable,
|
|
4
|
-
Dict,
|
|
5
|
-
)
|
|
6
|
-
|
|
7
|
-
from eth_typing import (
|
|
8
|
-
ContractName,
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
from ethpm import (
|
|
12
|
-
Package,
|
|
13
|
-
)
|
|
14
|
-
from web3.tools.pytest_ethereum.exceptions import (
|
|
15
|
-
DeployerError,
|
|
16
|
-
)
|
|
17
|
-
from web3.tools.pytest_ethereum.linker import (
|
|
18
|
-
deploy,
|
|
19
|
-
linker,
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class Deployer:
|
|
24
|
-
def __init__(self, package: Package) -> None:
|
|
25
|
-
if not isinstance(package, Package):
|
|
26
|
-
raise TypeError(
|
|
27
|
-
f"Expected a Package object, instead received {type(package)}."
|
|
28
|
-
)
|
|
29
|
-
self.package = package
|
|
30
|
-
self.strategies = {} # type: Dict[str, Callable[[Package], Package]]
|
|
31
|
-
|
|
32
|
-
def deploy(self, contract_type: ContractName, *args: Any, **kwargs: Any) -> Package:
|
|
33
|
-
factory = self.package.get_contract_factory(contract_type)
|
|
34
|
-
if contract_type in self.strategies:
|
|
35
|
-
strategy = self.strategies[contract_type]
|
|
36
|
-
return strategy(self.package)
|
|
37
|
-
if factory.needs_bytecode_linking:
|
|
38
|
-
raise DeployerError(
|
|
39
|
-
"Unable to deploy an unlinked factory. "
|
|
40
|
-
"Please register a strategy for this contract type."
|
|
41
|
-
)
|
|
42
|
-
strategy = linker(deploy(contract_type, *args, **kwargs))
|
|
43
|
-
return strategy(self.package)
|
|
44
|
-
|
|
45
|
-
def register_strategy(
|
|
46
|
-
self, contract_type: ContractName, strategy: Callable[[Package], Package]
|
|
47
|
-
) -> None:
|
|
48
|
-
self.strategies[contract_type] = strategy
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
class PytestEthereumError(Exception):
|
|
2
|
-
"""
|
|
3
|
-
Base class for all Pytest-Ethereum errors.
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
pass
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class DeployerError(PytestEthereumError):
|
|
10
|
-
"""
|
|
11
|
-
Raised when the Deployer is unable to deploy a contract type.
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
pass
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class LinkerError(PytestEthereumError):
|
|
18
|
-
"""
|
|
19
|
-
Raised when the Linker is unable to link two contract types.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
pass
|