From 5862d2ed49c83ca17341e7bddf70486c6ae0b803 Mon Sep 17 00:00:00 2001 From: Harmouch101 Date: Fri, 30 Apr 2021 22:33:38 +0300 Subject: [PATCH 1/6] Audit .rst & .py files and convert all Web3 instance variables to use w3 name. Signed-off-by: Harmouch101 --- docs/contributing.rst | 4 ++-- docs/examples.rst | 4 ++-- docs/v4_migration.rst | 6 +++--- docs/web3.beacon.rst | 2 +- docs/web3.main.rst | 2 +- docs/web3.pm.rst | 2 +- ens/main.py | 2 +- tests/core/contracts/conftest.py | 8 ++++---- tests/core/contracts/test_concise_contract.py | 2 +- tests/core/contracts/test_contract_class_construction.py | 2 +- tests/core/contracts/test_contract_init.py | 2 +- .../filtering/test_filter_against_pending_transactions.py | 4 ++-- .../filtering/test_filter_against_transaction_logs.py | 4 ++-- tests/core/middleware/test_gas_price_strategy.py | 4 ++-- tests/core/middleware/test_http_request_retry.py | 8 ++++---- tests/core/middleware/test_stalecheck.py | 4 ++-- tests/core/mining-module/test_miner_hashrate.py | 2 +- tests/core/mining-module/test_miner_setExtra.py | 4 ++-- tests/core/mining-module/test_miner_setGasPrice.py | 4 ++-- tests/core/mining-module/test_miner_start.py | 2 +- tests/core/mining-module/test_miner_stop.py | 2 +- tests/core/mining-module/test_setEtherBase.py | 4 ++-- tests/core/providers/test_http_provider.py | 6 +++--- tests/core/providers/test_provider.py | 4 ++-- tests/core/txpool-module/test_txpool_content.py | 2 +- tests/core/txpool-module/test_txpool_inspect.py | 2 +- tests/integration/generate_fixtures/go_ethereum.py | 4 ++-- tests/integration/generate_fixtures/parity.py | 2 +- tests/integration/go_ethereum/test_goethereum_http.py | 2 +- tests/integration/go_ethereum/test_goethereum_ipc.py | 2 +- tests/integration/go_ethereum/test_goethereum_ws.py | 2 +- tests/integration/parity/test_parity_http.py | 2 +- tests/integration/parity/test_parity_ipc.py | 2 +- tests/integration/parity/test_parity_ws.py | 2 +- tests/integration/test_ethereum_tester.py | 2 +- web3/contract.py | 6 +++--- web3/manager.py | 2 +- web3/module.py | 2 +- 38 files changed, 61 insertions(+), 61 deletions(-) diff --git a/docs/contributing.rst b/docs/contributing.rst index 438011a3a9..0b459235ef 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -202,7 +202,7 @@ virtualenv for smoke testing: >>> ... -Verify the latest documentation +Verify the latest documentation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To preview the documentation that will get published: @@ -321,7 +321,7 @@ Parity/OpenEthereum fixtures .. code:: sh $ python /tests/integration/generate_fixtures/parity.py /tests/integration/parity-X.Y.Z-fixture - + 5. The output of this script is your fixture, a zip file. Store the fixture in the ``/tests/integration/`` directory and update the ``/tests/integration/parity/conftest.py`` file to point the new fixture. diff --git a/docs/examples.rst b/docs/examples.rst index 803952e33f..7a664290cf 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -876,7 +876,7 @@ The script can be run with: ``python ./eventscanner.py `` self.logger = logger self.contract = contract - self.web3 = web3 + self.w3 = web3 self.state = state self.events = events self.filters = filters @@ -1356,7 +1356,7 @@ The script can be run with: ``python ./eventscanner.py `` # throttle down. provider.middlewares.clear() - web3 = Web3(provider) + w3 = Web3(provider) # Prepare stub ERC-20 contract object abi = json.loads(ABI) diff --git a/docs/v4_migration.rst b/docs/v4_migration.rst index 14ca20f2e1..739f0b17e2 100644 --- a/docs/v4_migration.rst +++ b/docs/v4_migration.rst @@ -91,9 +91,9 @@ These providers are fairly uncommon. If you don't recognize the names, you can probably skip the section. However, if you were using web3.py for testing contracts, -you might have been using TestRPCProvider or EthereumTesterProvider. +you might have been using TestRPCProvider or EthereumTesterProvider. -In v4 there is a new :class:`EthereumTesterProvider`, and the old v3 implementation has been +In v4 there is a new :class:`EthereumTesterProvider`, and the old v3 implementation has been removed. Web3.py v4 uses :class:`eth_tester.main.EthereumTester` under the hood, instead of eth-testrpc. While ``eth-tester`` is still in beta, many parts are already in better shape than testrpc, so we decided to replace it in v4. @@ -101,7 +101,7 @@ already in better shape than testrpc, so we decided to replace it in v4. If you were using TestRPC, or were explicitly importing EthereumTesterProvider, like: ``from web3.providers.tester import EthereumTesterProvider``, then you will need to update. -With v4 you should import with ``from web3 import EthereumTesterProvider``. As before, you'll +With v4 you should import with ``from web3 import EthereumTesterProvider``. As before, you'll need to install Web3.py with the ``tester`` extra to get these features, like: .. code-block:: bash diff --git a/docs/web3.beacon.rst b/docs/web3.beacon.rst index 957e924ab3..863a4510dd 100644 --- a/docs/web3.beacon.rst +++ b/docs/web3.beacon.rst @@ -241,7 +241,7 @@ Methods 'signature': '0x967dd2946358db7e426ed19d4576bc75123520ef6a489ca50002222070ee4611f9cef394e5e3071236a93b825f18a4ad07f1d5a1405e6c984f1d71e03f535d13a2156d6ba22cb0c2b148df23a7b8a7293315d6e74b9a26b64283e8393f2ad4c5' } ], - 'deposits': [], + 'deposits': [], 'voluntary_exits': [] } }, diff --git a/docs/web3.main.rst b/docs/web3.main.rst index 4d9ec25c36..455c306801 100644 --- a/docs/web3.main.rst +++ b/docs/web3.main.rst @@ -33,7 +33,7 @@ Attributes Returns the current Web3 version. .. code-block:: python - + >>> web3.api "4.7.0" diff --git a/docs/web3.pm.rst b/docs/web3.pm.rst index 289859ce9d..4c0f32f107 100644 --- a/docs/web3.pm.rst +++ b/docs/web3.pm.rst @@ -48,7 +48,7 @@ Creating your own Registry class If you want to implement your own registry and use it with ``web3.pm``, you must create a subclass that inherits from ``ERC1319Registry``, and implements all the `ERC 1319 standard methods `_ prefixed with an underscore in ``ERC1319Registry``. Then, you have to manually set it as the ``registry`` attribute on ``web3.pm``. .. code-block:: python - + custom_registry = CustomRegistryClass(address, w3) w3.pm.registry = custom_registry diff --git a/ens/main.py b/ens/main.py index f1cc28ff45..f94fbf9e4a 100644 --- a/ens/main.py +++ b/ens/main.py @@ -84,7 +84,7 @@ def __init__( :param hex-string addr: the address of the ENS registry on-chain. If not provided, ENS.py will default to the mainnet ENS registry address. """ - self.web3 = init_web3(provider) + self.w3 = init_web3(provider) ens_addr = addr if addr else ENS_MAINNET_ADDR self.ens = self.web3.eth.contract(abi=abis.ENS, address=ens_addr) diff --git a/tests/core/contracts/conftest.py b/tests/core/contracts/conftest.py index a3b97b745a..17f7fefbd0 100644 --- a/tests/core/contracts/conftest.py +++ b/tests/core/contracts/conftest.py @@ -478,7 +478,7 @@ def EVENT_CONTRACT( @pytest.fixture() def EventContract(web3_empty, EVENT_CONTRACT): - web3 = web3_empty + w3 = web3_empty return web3.eth.contract(**EVENT_CONTRACT) @@ -490,7 +490,7 @@ def event_contract( wait_for_block, address_conversion_func): - web3 = web3_empty + w3 = web3_empty wait_for_block(web3) deploy_txn_hash = EventContract.constructor().transact({ @@ -535,7 +535,7 @@ def INDEXED_EVENT_CONTRACT( @pytest.fixture() def IndexedEventContract(web3_empty, INDEXED_EVENT_CONTRACT): - web3 = web3_empty + w3 = web3_empty return web3.eth.contract(**INDEXED_EVENT_CONTRACT) @@ -547,7 +547,7 @@ def indexed_event( wait_for_block, address_conversion_func): - web3 = web3_empty + w3 = web3_empty wait_for_block(web3) deploy_txn_hash = IndexedEventContract.constructor().transact({ diff --git a/tests/core/contracts/test_concise_contract.py b/tests/core/contracts/test_concise_contract.py index 82cb5a3693..c1d6b42963 100644 --- a/tests/core/contracts/test_concise_contract.py +++ b/tests/core/contracts/test_concise_contract.py @@ -94,7 +94,7 @@ def test_class_construction_sets_class_vars(web3, ) classic = MathContract(some_address) - assert classic.web3 == web3 + assert classic.w3 == web3 assert classic.bytecode == decode_hex(MATH_CODE) assert classic.bytecode_runtime == decode_hex(MATH_RUNTIME) diff --git a/tests/core/contracts/test_contract_class_construction.py b/tests/core/contracts/test_contract_class_construction.py index 1f5557081d..3d553dd54d 100644 --- a/tests/core/contracts/test_contract_class_construction.py +++ b/tests/core/contracts/test_contract_class_construction.py @@ -23,7 +23,7 @@ def test_class_construction_sets_class_vars(web3, bytecode_runtime=MATH_RUNTIME, ) - assert MathContract.web3 == web3 + assert MathContract.w3 == web3 assert MathContract.bytecode == decode_hex(MATH_CODE) assert MathContract.bytecode_runtime == decode_hex(MATH_RUNTIME) diff --git a/tests/core/contracts/test_contract_init.py b/tests/core/contracts/test_contract_init.py index cdf202205f..97f8b02b93 100644 --- a/tests/core/contracts/test_contract_init.py +++ b/tests/core/contracts/test_contract_init.py @@ -12,7 +12,7 @@ @pytest.fixture() def math_addr(MathContract, address_conversion_func): - web3 = MathContract.web3 + w3 = MathContract.web3 deploy_txn = MathContract.constructor().transact({'from': web3.eth.coinbase}) deploy_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn) assert deploy_receipt is not None diff --git a/tests/core/filtering/test_filter_against_pending_transactions.py b/tests/core/filtering/test_filter_against_pending_transactions.py index e3162a9b8c..0e0e792d62 100644 --- a/tests/core/filtering/test_filter_against_pending_transactions.py +++ b/tests/core/filtering/test_filter_against_pending_transactions.py @@ -16,7 +16,7 @@ def test_sync_filter_against_pending_transactions(web3_empty, wait_for_transaction, skip_if_testrpc ): - web3 = web3_empty + w3 = web3_empty skip_if_testrpc(web3) txn_filter = web3.eth.filter("pending") @@ -51,7 +51,7 @@ def test_async_filter_against_pending_transactions(web3_empty, wait_for_transaction, skip_if_testrpc ): - web3 = web3_empty + w3 = web3_empty skip_if_testrpc(web3) seen_txns = [] diff --git a/tests/core/filtering/test_filter_against_transaction_logs.py b/tests/core/filtering/test_filter_against_transaction_logs.py index b0c13a03ca..c7f0c7d813 100644 --- a/tests/core/filtering/test_filter_against_transaction_logs.py +++ b/tests/core/filtering/test_filter_against_transaction_logs.py @@ -18,7 +18,7 @@ def test_sync_filter_against_log_events(web3_empty, emitter_log_topics, emitter_event_ids ): - web3 = web3_empty + w3 = web3_empty txn_filter = web3.eth.filter({}) @@ -45,7 +45,7 @@ def test_async_filter_against_log_events(web3_empty, emitter_log_topics, emitter_event_ids ): - web3 = web3_empty + w3 = web3_empty seen_logs = [] txn_filter = web3.eth.filter({}) diff --git a/tests/core/middleware/test_gas_price_strategy.py b/tests/core/middleware/test_gas_price_strategy.py index 14bb9bd8c4..c9661fa9ea 100644 --- a/tests/core/middleware/test_gas_price_strategy.py +++ b/tests/core/middleware/test_gas_price_strategy.py @@ -10,9 +10,9 @@ @pytest.fixture def the_gas_price_strategy_middleware(web3): - make_request, web3 = Mock(), Mock() + make_request, w3 = Mock(), Mock() initialized = gas_price_strategy_middleware(make_request, web3) - initialized.web3 = web3 + initialized.w3 = web3 initialized.make_request = make_request return initialized diff --git a/tests/core/middleware/test_http_request_retry.py b/tests/core/middleware/test_http_request_retry.py index 7558a9df1c..f8cd919cd6 100644 --- a/tests/core/middleware/test_http_request_retry.py +++ b/tests/core/middleware/test_http_request_retry.py @@ -24,11 +24,11 @@ @pytest.fixture def exception_retry_request_setup(): - web3 = Mock() + w3 = Mock() provider = HTTPProvider() errors = (ConnectionError, HTTPError, Timeout, TooManyRedirects) setup = exception_retry_middleware(provider.make_request, web3, errors, 5) - setup.web3 = web3 + setup.w3 = web3 return setup @@ -68,10 +68,10 @@ def test_valid_method_retried(make_post_request_mock, exception_retry_request_se def test_is_strictly_default_http_middleware(): - web3 = HTTPProvider() + w3 = HTTPProvider() assert 'http_retry_request' in web3.middlewares - web3 = IPCProvider() + w3 = IPCProvider() assert 'http_retry_request' not in web3.middlewares diff --git a/tests/core/middleware/test_stalecheck.py b/tests/core/middleware/test_stalecheck.py index f406fa50bf..1d9def8403 100644 --- a/tests/core/middleware/test_stalecheck.py +++ b/tests/core/middleware/test_stalecheck.py @@ -30,10 +30,10 @@ def allowable_delay(): @pytest.fixture def request_middleware(allowable_delay): middleware = make_stalecheck_middleware(allowable_delay) - make_request, web3 = Mock(), Mock() + make_request, w3 = Mock(), Mock() initialized = middleware(make_request, web3) # for easier mocking, later: - initialized.web3 = web3 + initialized.w3 = web3 initialized.make_request = make_request return initialized diff --git a/tests/core/mining-module/test_miner_hashrate.py b/tests/core/mining-module/test_miner_hashrate.py index d28acfcc72..efb592da73 100644 --- a/tests/core/mining-module/test_miner_hashrate.py +++ b/tests/core/mining-module/test_miner_hashrate.py @@ -5,7 +5,7 @@ @flaky(max_runs=3) def test_miner_hashrate(web3_empty, wait_for_miner_start): - web3 = web3_empty + w3 = web3_empty hashrate = web3.eth.hashrate assert hashrate > 0 diff --git a/tests/core/mining-module/test_miner_setExtra.py b/tests/core/mining-module/test_miner_setExtra.py index ecbf4786bf..ba9824ee5b 100644 --- a/tests/core/mining-module/test_miner_setExtra.py +++ b/tests/core/mining-module/test_miner_setExtra.py @@ -15,7 +15,7 @@ @flaky(max_runs=3) def test_miner_set_extra(web3_empty, wait_for_block): - web3 = web3_empty + w3 = web3_empty initial_extra = decode_hex(web3.eth.get_block(web3.eth.block_number)['extraData']) @@ -40,7 +40,7 @@ def test_miner_set_extra(web3_empty, wait_for_block): @flaky(max_runs=3) def test_miner_setExtra(web3_empty, wait_for_block): - web3 = web3_empty + w3 = web3_empty initial_extra = decode_hex(web3.eth.get_block(web3.eth.block_number)['extraData']) diff --git a/tests/core/mining-module/test_miner_setGasPrice.py b/tests/core/mining-module/test_miner_setGasPrice.py index 70852cf20a..f3065fbbe0 100644 --- a/tests/core/mining-module/test_miner_setGasPrice.py +++ b/tests/core/mining-module/test_miner_setGasPrice.py @@ -12,7 +12,7 @@ @flaky(max_runs=3) def test_miner_set_gas_price(web3_empty, wait_for_block): - web3 = web3_empty + w3 = web3_empty initial_gas_price = web3.eth.gas_price @@ -31,7 +31,7 @@ def test_miner_set_gas_price(web3_empty, wait_for_block): @flaky(max_runs=3) def test_miner_setGasPrice(web3_empty, wait_for_block): - web3 = web3_empty + w3 = web3_empty initial_gas_price = web3.eth.gas_price assert web3.eth.gas_price > 1000 diff --git a/tests/core/mining-module/test_miner_start.py b/tests/core/mining-module/test_miner_start.py index 80de7839c4..a6e9fe0040 100644 --- a/tests/core/mining-module/test_miner_start.py +++ b/tests/core/mining-module/test_miner_start.py @@ -11,7 +11,7 @@ @flaky(max_runs=3) def test_miner_start(web3_empty, wait_for_miner_start): - web3 = web3_empty + w3 = web3_empty # sanity assert web3.eth.mining diff --git a/tests/core/mining-module/test_miner_stop.py b/tests/core/mining-module/test_miner_stop.py index 60b6633b3f..5b962cf5d1 100644 --- a/tests/core/mining-module/test_miner_stop.py +++ b/tests/core/mining-module/test_miner_stop.py @@ -11,7 +11,7 @@ @flaky(max_runs=3) def test_miner_stop(web3_empty): - web3 = web3_empty + w3 = web3_empty assert web3.eth.mining assert web3.eth.hashrate diff --git a/tests/core/mining-module/test_setEtherBase.py b/tests/core/mining-module/test_setEtherBase.py index a057e851e4..a1bab63e9e 100644 --- a/tests/core/mining-module/test_setEtherBase.py +++ b/tests/core/mining-module/test_setEtherBase.py @@ -2,7 +2,7 @@ def test_miner_set_etherbase(web3_empty): - web3 = web3_empty + w3 = web3_empty assert web3.eth.coinbase == web3.eth.accounts[0] new_account = web3.personal.newAccount('this-is-a-password') web3.geth.miner.set_etherbase(new_account) @@ -10,7 +10,7 @@ def test_miner_set_etherbase(web3_empty): def test_miner_setEtherbase(web3_empty): - web3 = web3_empty + w3 = web3_empty assert web3.eth.coinbase == web3.eth.accounts[0] new_account = web3.personal.newAccount('this-is-a-password') with pytest.warns(DeprecationWarning): diff --git a/tests/core/providers/test_http_provider.py b/tests/core/providers/test_http_provider.py index f0e28c43aa..24c94b584d 100644 --- a/tests/core/providers/test_http_provider.py +++ b/tests/core/providers/test_http_provider.py @@ -18,14 +18,14 @@ def test_no_args(): provider = HTTPProvider() - web3 = Web3(provider) + w3 = Web3(provider) assert web3.manager.provider == provider def test_init_kwargs(): provider = HTTPProvider(endpoint_uri=URI, request_kwargs={'timeout': 60}) - web3 = Web3(provider) + w3 = Web3(provider) assert web3.manager.provider == provider @@ -36,7 +36,7 @@ def test_user_provided_session(): session.mount('https://', adapter) provider = HTTPProvider(endpoint_uri=URI, session=session) - web3 = Web3(provider) + w3 = Web3(provider) assert web3.manager.provider == provider session = request._get_session(URI) diff --git a/tests/core/providers/test_provider.py b/tests/core/providers/test_provider.py index d71744fb3a..87c605308e 100644 --- a/tests/core/providers/test_provider.py +++ b/tests/core/providers/test_provider.py @@ -19,7 +19,7 @@ def test_isConnected_connected(): """ Web3.isConnected() returns True when connected to a node. """ - web3 = Web3(ConnectedProvider()) + w3 = Web3(ConnectedProvider()) assert web3.isConnected() is True @@ -28,7 +28,7 @@ def test_isConnected_disconnected(): Web3.isConnected() returns False when configured with a provider that's not connected to a node. """ - web3 = Web3(DisconnectedProvider()) + w3 = Web3(DisconnectedProvider()) assert web3.isConnected() is False diff --git a/tests/core/txpool-module/test_txpool_content.py b/tests/core/txpool-module/test_txpool_content.py index 10a7a364e3..3375626d23 100644 --- a/tests/core/txpool-module/test_txpool_content.py +++ b/tests/core/txpool-module/test_txpool_content.py @@ -6,7 +6,7 @@ def test_txpool_content(web3_empty): - web3 = web3_empty + w3 = web3_empty web3.geth.miner.stop() diff --git a/tests/core/txpool-module/test_txpool_inspect.py b/tests/core/txpool-module/test_txpool_inspect.py index 2e2c5239f3..defd6ec80b 100644 --- a/tests/core/txpool-module/test_txpool_inspect.py +++ b/tests/core/txpool-module/test_txpool_inspect.py @@ -6,7 +6,7 @@ def test_txpool_inspect(web3_empty): - web3 = web3_empty + w3 = web3_empty web3.geth.miner.stop() diff --git a/tests/integration/generate_fixtures/go_ethereum.py b/tests/integration/generate_fixtures/go_ethereum.py index 41ff0682e0..f6e152f6a9 100644 --- a/tests/integration/generate_fixtures/go_ethereum.py +++ b/tests/integration/generate_fixtures/go_ethereum.py @@ -136,7 +136,7 @@ def generate_go_ethereum_fixture(destination_dir): geth_port=geth_port): common.wait_for_socket(geth_ipc_path) - web3 = Web3(Web3.IPCProvider(geth_ipc_path)) + w3 = Web3(Web3.IPCProvider(geth_ipc_path)) chain_data = setup_chain_state(web3) # close geth by exiting context # must be closed before copying data dir @@ -152,7 +152,7 @@ def generate_go_ethereum_fixture(destination_dir): geth_port=geth_port): common.wait_for_socket(geth_ipc_path) - web3 = Web3(Web3.IPCProvider(geth_ipc_path)) + w3 = Web3(Web3.IPCProvider(geth_ipc_path)) verify_chain_state(web3, chain_data) static_data = { diff --git a/tests/integration/generate_fixtures/parity.py b/tests/integration/generate_fixtures/parity.py index d6eb24688a..ca74ccae7d 100644 --- a/tests/integration/generate_fixtures/parity.py +++ b/tests/integration/generate_fixtures/parity.py @@ -288,7 +288,7 @@ def generate_parity_fixture(destination_dir): )) common.wait_for_socket(parity_ipc_path) - web3 = Web3(Web3.IPCProvider(parity_ipc_path)) + w3 = Web3(Web3.IPCProvider(parity_ipc_path)) time.sleep(10) connect_nodes(web3, web3_geth) diff --git a/tests/integration/go_ethereum/test_goethereum_http.py b/tests/integration/go_ethereum/test_goethereum_http.py index fca859ff9a..ffdeae1d7e 100644 --- a/tests/integration/go_ethereum/test_goethereum_http.py +++ b/tests/integration/go_ethereum/test_goethereum_http.py @@ -59,7 +59,7 @@ def geth_command_arguments(rpc_port, @pytest.fixture(scope="module") def web3(geth_process, endpoint_uri): wait_for_http(endpoint_uri) - _web3 = Web3(Web3.HTTPProvider(endpoint_uri)) + _w3 = Web3(Web3.HTTPProvider(endpoint_uri)) return _web3 diff --git a/tests/integration/go_ethereum/test_goethereum_ipc.py b/tests/integration/go_ethereum/test_goethereum_ipc.py index f95db63853..9d9d2a70f2 100644 --- a/tests/integration/go_ethereum/test_goethereum_ipc.py +++ b/tests/integration/go_ethereum/test_goethereum_ipc.py @@ -54,7 +54,7 @@ def geth_ipc_path(datadir): @pytest.fixture(scope="module") def web3(geth_process, geth_ipc_path): wait_for_socket(geth_ipc_path) - _web3 = Web3(Web3.IPCProvider(geth_ipc_path)) + _w3 = Web3(Web3.IPCProvider(geth_ipc_path)) return _web3 diff --git a/tests/integration/go_ethereum/test_goethereum_ws.py b/tests/integration/go_ethereum/test_goethereum_ws.py index 449fd64179..6c1980f1a1 100644 --- a/tests/integration/go_ethereum/test_goethereum_ws.py +++ b/tests/integration/go_ethereum/test_goethereum_ws.py @@ -65,7 +65,7 @@ def geth_command_arguments(geth_binary, @pytest.fixture(scope="module") def web3(geth_process, endpoint_uri, event_loop): event_loop.run_until_complete(wait_for_ws(endpoint_uri, event_loop)) - _web3 = Web3(Web3.WebsocketProvider(endpoint_uri)) + _w3 = Web3(Web3.WebsocketProvider(endpoint_uri)) return _web3 diff --git a/tests/integration/parity/test_parity_http.py b/tests/integration/parity/test_parity_http.py index 3c2cc7cd0f..c6bf6b1d96 100644 --- a/tests/integration/parity/test_parity_http.py +++ b/tests/integration/parity/test_parity_http.py @@ -76,7 +76,7 @@ def parity_import_blocks_command(parity_binary, rpc_port, datadir, passwordfile) @pytest.fixture(scope="module") # noqa: F811 def web3(parity_process, endpoint_uri): wait_for_http(endpoint_uri) - _web3 = Web3(Web3.HTTPProvider(endpoint_uri)) + _w3 = Web3(Web3.HTTPProvider(endpoint_uri)) return _web3 diff --git a/tests/integration/parity/test_parity_ipc.py b/tests/integration/parity/test_parity_ipc.py index e0f202fc65..4be012054a 100644 --- a/tests/integration/parity/test_parity_ipc.py +++ b/tests/integration/parity/test_parity_ipc.py @@ -74,7 +74,7 @@ def parity_import_blocks_command(parity_binary, ipc_path, datadir, passwordfile) @pytest.fixture(scope="module") # noqa: F811 def web3(parity_process, ipc_path): wait_for_socket(ipc_path) - _web3 = Web3(Web3.IPCProvider(ipc_path)) + _w3 = Web3(Web3.IPCProvider(ipc_path)) return _web3 diff --git a/tests/integration/parity/test_parity_ws.py b/tests/integration/parity/test_parity_ws.py index 330a5d9fa5..4bc44f00e3 100644 --- a/tests/integration/parity/test_parity_ws.py +++ b/tests/integration/parity/test_parity_ws.py @@ -79,7 +79,7 @@ def parity_import_blocks_command(parity_binary, ws_port, datadir, passwordfile): @pytest.fixture(scope="module") # noqa: F811 def web3(parity_process, endpoint_uri, event_loop): event_loop.run_until_complete(wait_for_ws(endpoint_uri, event_loop)) - _web3 = Web3(Web3.WebsocketProvider(endpoint_uri)) + _w3 = Web3(Web3.WebsocketProvider(endpoint_uri)) return _web3 diff --git a/tests/integration/test_ethereum_tester.py b/tests/integration/test_ethereum_tester.py index 2caaf1b398..08b42739fa 100644 --- a/tests/integration/test_ethereum_tester.py +++ b/tests/integration/test_ethereum_tester.py @@ -46,7 +46,7 @@ def eth_tester_provider(eth_tester): @pytest.fixture(scope="module") def web3(eth_tester_provider): - _web3 = Web3(eth_tester_provider) + _w3 = Web3(eth_tester_provider) return _web3 diff --git a/web3/contract.py b/web3/contract.py index 340d384b46..659f7744c4 100644 --- a/web3/contract.py +++ b/web3/contract.py @@ -156,7 +156,7 @@ class ContractFunctions: def __init__(self, abi: ABI, web3: 'Web3', address: Optional[ChecksumAddress] = None) -> None: self.abi = abi - self.web3 = web3 + self.w3 = web3 self.address = address if self.abi: @@ -597,7 +597,7 @@ class ContractConstructor: def __init__( self, web3: 'Web3', abi: ABI, bytecode: HexStr, *args: Any, **kwargs: Any ) -> None: - self.web3 = web3 + self.w3 = web3 self.abi = abi self.bytecode = bytecode self.data_in_transaction = self._encode_data_in_transaction(*args, **kwargs) @@ -1372,7 +1372,7 @@ def __init__(self, address: ChecksumAddress, transaction: Optional[TxParams] = None, block_identifier: BlockIdentifier = 'latest') -> None: - self.web3 = web3 + self.w3 = web3 self.address = address self.abi = abi self._functions = None diff --git a/web3/manager.py b/web3/manager.py index 9402096397..0ecb909dff 100644 --- a/web3/manager.py +++ b/web3/manager.py @@ -77,7 +77,7 @@ def __init__( provider: Optional[BaseProvider] = None, middlewares: Optional[Sequence[Tuple[Middleware, str]]] = None ) -> None: - self.web3 = web3 + self.w3 = web3 self.pending_requests: Dict[UUID, ThreadWithReturn[RPCResponse]] = {} if middlewares is None: diff --git a/web3/module.py b/web3/module.py index 1d3f6de4fa..8d6c6b9817 100644 --- a/web3/module.py +++ b/web3/module.py @@ -83,5 +83,5 @@ def __init__(self, web3: "Web3") -> None: self.retrieve_caller_fn = retrieve_async_method_call_fn(web3, self) else: self.retrieve_caller_fn = retrieve_blocking_method_call_fn(web3, self) - self.web3 = web3 + self.w3 = web3 self.codec: ABICodec = web3.codec From 9a2ed1345d38e7fc32f2d5f642622eb6352b9091 Mon Sep 17 00:00:00 2001 From: Harmouch101 Date: Fri, 30 Apr 2021 22:55:52 +0300 Subject: [PATCH 2/6] Audit .rst & .py files and convert all Web3 instance variables to use w3 name. Signed-off-by: Harmouch101 --- docs/contributing.rst | 4 ++-- docs/v4_migration.rst | 6 +++--- docs/web3.beacon.rst | 2 +- docs/web3.main.rst | 2 +- docs/web3.pm.rst | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/contributing.rst b/docs/contributing.rst index 0b459235ef..438011a3a9 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -202,7 +202,7 @@ virtualenv for smoke testing: >>> ... -Verify the latest documentation +Verify the latest documentation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To preview the documentation that will get published: @@ -321,7 +321,7 @@ Parity/OpenEthereum fixtures .. code:: sh $ python /tests/integration/generate_fixtures/parity.py /tests/integration/parity-X.Y.Z-fixture - + 5. The output of this script is your fixture, a zip file. Store the fixture in the ``/tests/integration/`` directory and update the ``/tests/integration/parity/conftest.py`` file to point the new fixture. diff --git a/docs/v4_migration.rst b/docs/v4_migration.rst index 739f0b17e2..14ca20f2e1 100644 --- a/docs/v4_migration.rst +++ b/docs/v4_migration.rst @@ -91,9 +91,9 @@ These providers are fairly uncommon. If you don't recognize the names, you can probably skip the section. However, if you were using web3.py for testing contracts, -you might have been using TestRPCProvider or EthereumTesterProvider. +you might have been using TestRPCProvider or EthereumTesterProvider. -In v4 there is a new :class:`EthereumTesterProvider`, and the old v3 implementation has been +In v4 there is a new :class:`EthereumTesterProvider`, and the old v3 implementation has been removed. Web3.py v4 uses :class:`eth_tester.main.EthereumTester` under the hood, instead of eth-testrpc. While ``eth-tester`` is still in beta, many parts are already in better shape than testrpc, so we decided to replace it in v4. @@ -101,7 +101,7 @@ already in better shape than testrpc, so we decided to replace it in v4. If you were using TestRPC, or were explicitly importing EthereumTesterProvider, like: ``from web3.providers.tester import EthereumTesterProvider``, then you will need to update. -With v4 you should import with ``from web3 import EthereumTesterProvider``. As before, you'll +With v4 you should import with ``from web3 import EthereumTesterProvider``. As before, you'll need to install Web3.py with the ``tester`` extra to get these features, like: .. code-block:: bash diff --git a/docs/web3.beacon.rst b/docs/web3.beacon.rst index 863a4510dd..957e924ab3 100644 --- a/docs/web3.beacon.rst +++ b/docs/web3.beacon.rst @@ -241,7 +241,7 @@ Methods 'signature': '0x967dd2946358db7e426ed19d4576bc75123520ef6a489ca50002222070ee4611f9cef394e5e3071236a93b825f18a4ad07f1d5a1405e6c984f1d71e03f535d13a2156d6ba22cb0c2b148df23a7b8a7293315d6e74b9a26b64283e8393f2ad4c5' } ], - 'deposits': [], + 'deposits': [], 'voluntary_exits': [] } }, diff --git a/docs/web3.main.rst b/docs/web3.main.rst index 455c306801..8a49ec6bcb 100644 --- a/docs/web3.main.rst +++ b/docs/web3.main.rst @@ -33,7 +33,7 @@ Attributes Returns the current Web3 version. .. code-block:: python - + >>> web3.api "4.7.0" diff --git a/docs/web3.pm.rst b/docs/web3.pm.rst index 4c0f32f107..289859ce9d 100644 --- a/docs/web3.pm.rst +++ b/docs/web3.pm.rst @@ -48,7 +48,7 @@ Creating your own Registry class If you want to implement your own registry and use it with ``web3.pm``, you must create a subclass that inherits from ``ERC1319Registry``, and implements all the `ERC 1319 standard methods `_ prefixed with an underscore in ``ERC1319Registry``. Then, you have to manually set it as the ``registry`` attribute on ``web3.pm``. .. code-block:: python - + custom_registry = CustomRegistryClass(address, w3) w3.pm.registry = custom_registry From a77419abe415a4bb0142abd46c39aeff71ba266e Mon Sep 17 00:00:00 2001 From: Harmouch101 Date: Fri, 30 Apr 2021 23:00:00 +0300 Subject: [PATCH 3/6] Audit .rst & .py files and convert all Web3 instance variables to use w3 name. Signed-off-by: Harmouch101 --- docs/contributing.rst | 4 +- docs/examples.rst | 6 +-- docs/v4_migration.rst | 6 +-- docs/web3.beacon.rst | 2 +- docs/web3.main.rst | 2 +- docs/web3.pm.rst | 2 +- ens/main.py | 8 ++-- web3/contract.py | 102 +++++++++++++++++++++--------------------- web3/eth.py | 16 +++---- web3/manager.py | 4 +- web3/parity.py | 4 +- web3/pm.py | 18 ++++---- web3/testing.py | 10 ++--- 13 files changed, 92 insertions(+), 92 deletions(-) diff --git a/docs/contributing.rst b/docs/contributing.rst index 438011a3a9..0b459235ef 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -202,7 +202,7 @@ virtualenv for smoke testing: >>> ... -Verify the latest documentation +Verify the latest documentation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To preview the documentation that will get published: @@ -321,7 +321,7 @@ Parity/OpenEthereum fixtures .. code:: sh $ python /tests/integration/generate_fixtures/parity.py /tests/integration/parity-X.Y.Z-fixture - + 5. The output of this script is your fixture, a zip file. Store the fixture in the ``/tests/integration/`` directory and update the ``/tests/integration/parity/conftest.py`` file to point the new fixture. diff --git a/docs/examples.rst b/docs/examples.rst index 7a664290cf..e4ad1c2d9b 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -901,7 +901,7 @@ The script can be run with: ``python ./eventscanner.py `` def get_block_timestamp(self, block_num) -> datetime.datetime: """Get Ethereum block timestamp""" try: - block_info = self.web3.eth.getBlock(block_num) + block_info = self.w3.eth.getBlock(block_num) except BlockNotFound: # Block was not mined yet, # minor chain reorganisation? @@ -929,7 +929,7 @@ The script can be run with: ``python ./eventscanner.py `` # Do not scan all the way to the final block, as this # block might not be mined yet - return self.web3.eth.blockNumber - 1 + return self.w3.eth.blockNumber - 1 def get_last_scanned_block(self) -> int: return self.state.get_last_scanned_block() @@ -962,7 +962,7 @@ The script can be run with: ``python ./eventscanner.py `` # Callable that takes care of the underlying web3 call def _fetch_events(_start_block, _end_block): - return _fetch_events_for_all_contracts(self.web3, + return _fetch_events_for_all_contracts(self.w3, event_type, self.filters, from_block=_start_block, diff --git a/docs/v4_migration.rst b/docs/v4_migration.rst index 14ca20f2e1..739f0b17e2 100644 --- a/docs/v4_migration.rst +++ b/docs/v4_migration.rst @@ -91,9 +91,9 @@ These providers are fairly uncommon. If you don't recognize the names, you can probably skip the section. However, if you were using web3.py for testing contracts, -you might have been using TestRPCProvider or EthereumTesterProvider. +you might have been using TestRPCProvider or EthereumTesterProvider. -In v4 there is a new :class:`EthereumTesterProvider`, and the old v3 implementation has been +In v4 there is a new :class:`EthereumTesterProvider`, and the old v3 implementation has been removed. Web3.py v4 uses :class:`eth_tester.main.EthereumTester` under the hood, instead of eth-testrpc. While ``eth-tester`` is still in beta, many parts are already in better shape than testrpc, so we decided to replace it in v4. @@ -101,7 +101,7 @@ already in better shape than testrpc, so we decided to replace it in v4. If you were using TestRPC, or were explicitly importing EthereumTesterProvider, like: ``from web3.providers.tester import EthereumTesterProvider``, then you will need to update. -With v4 you should import with ``from web3 import EthereumTesterProvider``. As before, you'll +With v4 you should import with ``from web3 import EthereumTesterProvider``. As before, you'll need to install Web3.py with the ``tester`` extra to get these features, like: .. code-block:: bash diff --git a/docs/web3.beacon.rst b/docs/web3.beacon.rst index 957e924ab3..863a4510dd 100644 --- a/docs/web3.beacon.rst +++ b/docs/web3.beacon.rst @@ -241,7 +241,7 @@ Methods 'signature': '0x967dd2946358db7e426ed19d4576bc75123520ef6a489ca50002222070ee4611f9cef394e5e3071236a93b825f18a4ad07f1d5a1405e6c984f1d71e03f535d13a2156d6ba22cb0c2b148df23a7b8a7293315d6e74b9a26b64283e8393f2ad4c5' } ], - 'deposits': [], + 'deposits': [], 'voluntary_exits': [] } }, diff --git a/docs/web3.main.rst b/docs/web3.main.rst index 8a49ec6bcb..455c306801 100644 --- a/docs/web3.main.rst +++ b/docs/web3.main.rst @@ -33,7 +33,7 @@ Attributes Returns the current Web3 version. .. code-block:: python - + >>> web3.api "4.7.0" diff --git a/docs/web3.pm.rst b/docs/web3.pm.rst index 289859ce9d..4c0f32f107 100644 --- a/docs/web3.pm.rst +++ b/docs/web3.pm.rst @@ -48,7 +48,7 @@ Creating your own Registry class If you want to implement your own registry and use it with ``web3.pm``, you must create a subclass that inherits from ``ERC1319Registry``, and implements all the `ERC 1319 standard methods `_ prefixed with an underscore in ``ERC1319Registry``. Then, you have to manually set it as the ``registry`` attribute on ``web3.pm``. .. code-block:: python - + custom_registry = CustomRegistryClass(address, w3) w3.pm.registry = custom_registry diff --git a/ens/main.py b/ens/main.py index f94fbf9e4a..a9a12b4de5 100644 --- a/ens/main.py +++ b/ens/main.py @@ -87,8 +87,8 @@ def __init__( self.w3 = init_web3(provider) ens_addr = addr if addr else ENS_MAINNET_ADDR - self.ens = self.web3.eth.contract(abi=abis.ENS, address=ens_addr) - self._resolverContract = self.web3.eth.contract(abi=abis.RESOLVER) + self.ens = self.w3.eth.contract(abi=abis.ENS, address=ens_addr) + self._resolverContract = self.w3.eth.contract(abi=abis.RESOLVER) @classmethod def fromWeb3(cls, web3: 'Web3', addr: ChecksumAddress = None) -> 'ENS': @@ -294,7 +294,7 @@ def setup_owner( def _assert_control(self, account: ChecksumAddress, name: str, parent_owned: Optional[str] = None) -> None: - if not address_in(account, self.web3.eth.accounts): + if not address_in(account, self.w3.eth.accounts): raise UnauthorizedError( "in order to modify %r, you must control account %r, which owns %r" % ( name, account, parent_owned or name @@ -362,4 +362,4 @@ def _setup_reverse( def _reverse_registrar(self) -> 'Contract': addr = self.ens.caller.owner(normal_name_to_hash(REVERSE_REGISTRAR_DOMAIN)) - return self.web3.eth.contract(address=addr, abi=abis.REVERSE_REGISTRAR) + return self.w3.eth.contract(address=addr, abi=abis.REVERSE_REGISTRAR) diff --git a/web3/contract.py b/web3/contract.py index 659f7744c4..1212288a42 100644 --- a/web3/contract.py +++ b/web3/contract.py @@ -167,7 +167,7 @@ def __init__(self, abi: ABI, web3: 'Web3', address: Optional[ChecksumAddress] = func['name'], ContractFunction.factory( func['name'], - web3=self.web3, + web3=self.w3, contract_abi=self.abi, address=self.address, function_identifier=func['name'])) @@ -327,23 +327,23 @@ def __init__(self, address: Optional[ChecksumAddress] = None) -> None: :param address: Contract address as 0x hex string """ - if self.web3 is None: + if self.w3 is None: raise AttributeError( 'The `Contract` class has not been initialized. Please use the ' '`web3.contract` interface to create your contract class.' ) if address: - self.address = normalize_address(self.web3.ens, address) + self.address = normalize_address(self.w3.ens, address) if not self.address: raise TypeError("The address argument is required to instantiate a contract.") - self.functions = ContractFunctions(self.abi, self.web3, self.address) - self.caller = ContractCaller(self.abi, self.web3, self.address) - self.events = ContractEvents(self.abi, self.web3, self.address) - self.fallback = Contract.get_fallback_function(self.abi, self.web3, self.address) - self.receive = Contract.get_receive_function(self.abi, self.web3, self.address) + self.functions = ContractFunctions(self.abi, self.w3, self.address) + self.caller = ContractCaller(self.abi, self.w3, self.address) + self.events = ContractEvents(self.abi, self.w3, self.address) + self.fallback = Contract.get_fallback_function(self.abi, self.w3, self.address) + self.receive = Contract.get_receive_function(self.abi, self.w3, self.address) @classmethod def factory(cls, web3: 'Web3', class_name: Optional[str] = None, **kwargs: Any) -> 'Contract': @@ -416,7 +416,7 @@ def encodeABI(cls, fn_name: str, args: Optional[Any] = None, @combomethod def all_functions(self) -> List['ContractFunction']: return find_functions_by_identifier( - self.abi, self.web3, self.address, lambda _: True + self.abi, self.w3, self.address, lambda _: True ) @combomethod @@ -430,7 +430,7 @@ def get_function_by_signature(self, signature: str) -> 'ContractFunction': def callable_check(fn_abi: ABIFunction) -> bool: return abi_to_signature(fn_abi) == signature - fns = find_functions_by_identifier(self.abi, self.web3, self.address, callable_check) + fns = find_functions_by_identifier(self.abi, self.w3, self.address, callable_check) return get_function_by_identifier(fns, 'signature') @combomethod @@ -439,7 +439,7 @@ def callable_check(fn_abi: ABIFunction) -> bool: return fn_abi['name'] == fn_name return find_functions_by_identifier( - self.abi, self.web3, self.address, callable_check + self.abi, self.w3, self.address, callable_check ) @combomethod @@ -454,7 +454,7 @@ def callable_check(fn_abi: ABIFunction) -> bool: # https://github.com/python/mypy/issues/4976 return encode_hex(function_abi_to_4byte_selector(fn_abi)) == to_4byte_hex(selector) # type: ignore # noqa: E501 - fns = find_functions_by_identifier(self.abi, self.web3, self.address, callable_check) + fns = find_functions_by_identifier(self.abi, self.w3, self.address, callable_check) return get_function_by_identifier(fns, 'selector') @combomethod @@ -467,7 +467,7 @@ def decode_function_input(self, data: HexStr) -> Tuple['ContractFunction', Dict[ names = get_abi_input_names(func.abi) types = get_abi_input_types(func.abi) - decoded = self.web3.codec.decode_abi(types, cast(HexBytes, params)) + decoded = self.w3.codec.decode_abi(types, cast(HexBytes, params)) normalized = map_abi_data(BASE_RETURN_NORMALIZERS, types, decoded) return func, dict(zip(names, normalized)) @@ -475,10 +475,10 @@ def decode_function_input(self, data: HexStr) -> Tuple['ContractFunction', Dict[ @combomethod def find_functions_by_args(self, *args: Any) -> List['ContractFunction']: def callable_check(fn_abi: ABIFunction) -> bool: - return check_if_arguments_can_be_encoded(fn_abi, self.web3.codec, args=args, kwargs={}) + return check_if_arguments_can_be_encoded(fn_abi, self.w3.codec, args=args, kwargs={}) return find_functions_by_identifier( - self.abi, self.web3, self.address, callable_check + self.abi, self.w3, self.address, callable_check ) @combomethod @@ -614,7 +614,7 @@ def _encode_data_in_transaction(self, *args: Any, **kwargs: Any) -> HexStr: arguments = merge_args_and_kwargs(constructor_abi, args, kwargs) data = add_0x_prefix( - encode_abi(self.web3, constructor_abi, arguments, data=self.bytecode) + encode_abi(self.w3, constructor_abi, arguments, data=self.bytecode) ) else: data = to_hex(self.bytecode) @@ -633,13 +633,13 @@ def estimateGas( self.check_forbidden_keys_in_transaction(estimate_gas_transaction, ["data", "to"]) - if self.web3.eth.default_account is not empty: + if self.w3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - estimate_gas_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore # noqa: E501 + estimate_gas_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore # noqa: E501 estimate_gas_transaction['data'] = self.data_in_transaction - return self.web3.eth.estimate_gas( + return self.w3.eth.estimate_gas( estimate_gas_transaction, block_identifier=block_identifier ) @@ -652,14 +652,14 @@ def transact(self, transaction: Optional[TxParams] = None) -> HexBytes: self.check_forbidden_keys_in_transaction(transact_transaction, ["data", "to"]) - if self.web3.eth.default_account is not empty: + if self.w3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - transact_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore + transact_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore transact_transaction['data'] = self.data_in_transaction # TODO: handle asynchronous contract creation - return self.web3.eth.send_transaction(transact_transaction) + return self.w3.eth.send_transaction(transact_transaction) @combomethod def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams: @@ -674,13 +674,13 @@ def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams: self.check_forbidden_keys_in_transaction(built_transaction, ["data", "to"]) - if self.web3.eth.default_account is not empty: + if self.w3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - built_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore + built_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore built_transaction['data'] = self.data_in_transaction built_transaction['to'] = Address(b'') - return fill_transaction_defaults(self.web3, built_transaction) + return fill_transaction_defaults(self.w3, built_transaction) @staticmethod def check_forbidden_keys_in_transaction( @@ -879,7 +879,7 @@ def _set_function_info(self) -> None: if not self.abi: self.abi = find_matching_fn_abi( self.contract_abi, - self.web3.codec, + self.w3.codec, self.function_identifier, self.args, self.kwargs @@ -933,9 +933,9 @@ def call( if self.address: call_transaction.setdefault('to', self.address) - if self.web3.eth.default_account is not empty: + if self.w3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - call_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore + call_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore if 'to' not in call_transaction: if isinstance(self, type): @@ -949,10 +949,10 @@ def call( "Please ensure that this contract instance has an address." ) - block_id = parse_block_identifier(self.web3, block_identifier) + block_id = parse_block_identifier(self.w3, block_identifier) return call_contract_function( - self.web3, + self.w3, self.address, self._return_data_normalizers, self.function_identifier, @@ -975,9 +975,9 @@ def transact(self, transaction: Optional[TxParams] = None) -> HexBytes: if self.address is not None: transact_transaction.setdefault('to', self.address) - if self.web3.eth.default_account is not empty: + if self.w3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - transact_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore + transact_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore if 'to' not in transact_transaction: if isinstance(self, type): @@ -992,7 +992,7 @@ def transact(self, transaction: Optional[TxParams] = None) -> HexBytes: return transact_with_contract_function( self.address, - self.web3, + self.w3, self.function_identifier, transact_transaction, self.contract_abi, @@ -1017,9 +1017,9 @@ def estimateGas( if self.address: estimate_gas_transaction.setdefault('to', self.address) - if self.web3.eth.default_account is not empty: + if self.w3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - estimate_gas_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore # noqa: E501 + estimate_gas_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore # noqa: E501 if 'to' not in estimate_gas_transaction: if isinstance(self, type): @@ -1034,7 +1034,7 @@ def estimateGas( return estimate_gas_for_function( self.address, - self.web3, + self.w3, self.function_identifier, estimate_gas_transaction, self.contract_abi, @@ -1074,7 +1074,7 @@ def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams: return build_transaction_for_function( self.address, - self.web3, + self.w3, self.function_identifier, built_transaction, self.contract_abi, @@ -1147,7 +1147,7 @@ def _parse_logs( for log in txn_receipt['logs']: try: - rich_log = get_event_data(self.web3.codec, self.abi, log) + rich_log = get_event_data(self.w3.codec, self.abi, log) except (MismatchedABI, LogTopicError, InvalidEventABI, TypeError) as e: if errors == DISCARD: continue @@ -1169,7 +1169,7 @@ def _parse_logs( @combomethod def processLog(self, log: HexStr) -> EventData: - return get_event_data(self.web3.codec, self.abi, log) + return get_event_data(self.w3.codec, self.abi, log) @combomethod def createFilter( @@ -1197,7 +1197,7 @@ def createFilter( _, event_filter_params = construct_event_filter_params( self._get_event_abi(), - self.web3.codec, + self.w3.codec, contract_address=self.address, argument_filters=_filters, fromBlock=fromBlock, @@ -1206,7 +1206,7 @@ def createFilter( topics=topics, ) - filter_builder = EventFilterBuilder(event_abi, self.web3.codec) + filter_builder = EventFilterBuilder(event_abi, self.w3.codec) filter_builder.address = cast(ChecksumAddress, event_filter_params.get('address')) filter_builder.fromBlock = event_filter_params.get('fromBlock') filter_builder.toBlock = event_filter_params.get('toBlock') @@ -1224,8 +1224,8 @@ def createFilter( for arg, value in match_single_vals.items(): filter_builder.args[arg].match_single(value) - log_filter = filter_builder.deploy(self.web3) - log_filter.log_entry_formatter = get_event_data(self.web3.codec, self._get_event_abi()) + log_filter = filter_builder.deploy(self.w3) + log_filter.log_entry_formatter = get_event_data(self.w3.codec, self._get_event_abi()) log_filter.builder = filter_builder return log_filter @@ -1234,8 +1234,8 @@ def createFilter( def build_filter(self) -> EventFilterBuilder: builder = EventFilterBuilder( self._get_event_abi(), - self.web3.codec, - formatter=get_event_data(self.web3.codec, self._get_event_abi())) + self.w3.codec, + formatter=get_event_data(self.w3.codec, self._get_event_abi())) builder.address = self.address return builder @@ -1322,7 +1322,7 @@ def getLogs(self, # Namely, convert event names to their keccak signatures data_filter_set, event_filter_params = construct_event_filter_params( abi, - self.web3.codec, + self.w3.codec, contract_address=self.address, argument_filters=_filters, fromBlock=fromBlock, @@ -1334,10 +1334,10 @@ def getLogs(self, event_filter_params['blockHash'] = blockHash # Call JSON-RPC API - logs = self.web3.eth.get_logs(event_filter_params) + logs = self.w3.eth.get_logs(event_filter_params) # Convert raw binary data to Python proxy objects as described by ABI - return tuple(get_event_data(self.web3.codec, abi, entry) for entry in logs) + return tuple(get_event_data(self.w3.codec, abi, entry) for entry in logs) @classmethod def factory(cls, class_name: str, **kwargs: Any) -> PropertyCheckingFactory: @@ -1385,12 +1385,12 @@ def __init__(self, for func in self._functions: fn: ContractFunction = ContractFunction.factory( func['name'], - web3=self.web3, + web3=self.w3, contract_abi=self.abi, address=self.address, function_identifier=func['name']) - block_id = parse_block_identifier(self.web3, block_identifier) + block_id = parse_block_identifier(self.w3, block_identifier) caller_method = partial(self.call_function, fn, transaction=transaction, @@ -1431,7 +1431,7 @@ def __call__( if transaction is None: transaction = {} return type(self)(self.abi, - self.web3, + self.w3, self.address, transaction=transaction, block_identifier=block_identifier) diff --git a/web3/eth.py b/web3/eth.py index af857e18b8..6001dd17c6 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -431,7 +431,7 @@ def wait_for_transaction_receipt( self, transaction_hash: _Hash32, timeout: int = 120, poll_latency: float = 0.1 ) -> TxReceipt: try: - return wait_for_transaction_receipt(self.web3, transaction_hash, timeout, poll_latency) + return wait_for_transaction_receipt(self.w3, transaction_hash, timeout, poll_latency) except Timeout: raise TimeExhausted( "Transaction {} is not in the chain, after {} seconds".format( @@ -455,8 +455,8 @@ def replaceTransaction(self, transaction_hash: _Hash32, new_transaction: TxParam return self.replace_transaction(transaction_hash, new_transaction) def replace_transaction(self, transaction_hash: _Hash32, new_transaction: TxParams) -> HexBytes: - current_transaction = get_required_transaction(self.web3, transaction_hash) - return replace_transaction(self.web3, current_transaction, new_transaction) + current_transaction = get_required_transaction(self.w3, transaction_hash) + return replace_transaction(self.w3, current_transaction, new_transaction) # todo: Update Any to stricter kwarg checking with TxParams # https://github.com/python/mypy/issues/4441 @@ -470,10 +470,10 @@ def modify_transaction( self, transaction_hash: _Hash32, **transaction_params: Any ) -> HexBytes: assert_valid_transaction_params(cast(TxParams, transaction_params)) - current_transaction = get_required_transaction(self.web3, transaction_hash) + current_transaction = get_required_transaction(self.w3, transaction_hash) current_transaction_params = extract_valid_transaction_params(current_transaction) new_transaction = merge(current_transaction_params, transaction_params) - return replace_transaction(self.web3, current_transaction, new_transaction) + return replace_transaction(self.w3, current_transaction, new_transaction) def send_transaction_munger(self, transaction: TxParams) -> Tuple[TxParams]: # TODO: move to middleware @@ -485,7 +485,7 @@ def send_transaction_munger(self, transaction: TxParams) -> Tuple[TxParams]: transaction = assoc( transaction, 'gas', - get_buffered_gas_estimate(self.web3, transaction), + get_buffered_gas_estimate(self.w3, transaction), ) return (transaction,) @@ -645,7 +645,7 @@ def contract( # noqa: F811 ) -> Union[Type[Contract], Contract]: ContractFactoryClass = kwargs.pop('ContractFactoryClass', self.defaultContractFactory) - ContractFactory = ContractFactoryClass.factory(self.web3, **kwargs) + ContractFactory = ContractFactoryClass.factory(self.w3, **kwargs) if address: return ContractFactory(address) @@ -677,7 +677,7 @@ def generateGasPrice(self, transaction_params: Optional[TxParams] = None) -> Opt def generate_gas_price(self, transaction_params: Optional[TxParams] = None) -> Optional[Wei]: if self.gasPriceStrategy: - return self.gasPriceStrategy(self.web3, transaction_params) + return self.gasPriceStrategy(self.w3, transaction_params) return None @deprecated_for("set_gas_price_strategy") diff --git a/web3/manager.py b/web3/manager.py index 0ecb909dff..fce4cef45d 100644 --- a/web3/manager.py +++ b/web3/manager.py @@ -127,7 +127,7 @@ def _make_request( self, method: Union[RPCEndpoint, Callable[..., RPCEndpoint]], params: Any ) -> RPCResponse: request_func = self.provider.request_func( - self.web3, + self.w3, self.middleware_onion) self.logger.debug("Making request. Method: %s", method) return request_func(method, params) @@ -136,7 +136,7 @@ async def _coro_make_request( self, method: Union[RPCEndpoint, Callable[..., RPCEndpoint]], params: Any ) -> RPCResponse: request_func = self.provider.request_func( - self.web3, + self.w3, self.middleware_onion) self.logger.debug("Making request. Method: %s", method) # type ignored b/c request_func is an awaitable in async model diff --git a/web3/parity.py b/web3/parity.py index 2c32c3b96f..84bcaa5c44 100644 --- a/web3/parity.py +++ b/web3/parity.py @@ -186,8 +186,8 @@ def trace_call_munger( block_identifier: Optional[BlockIdentifier] = None ) -> Tuple[TxParams, ParityTraceMode, BlockIdentifier]: # TODO: move to middleware - if 'from' not in transaction and is_checksum_address(self.web3.eth.default_account): - transaction = assoc(transaction, 'from', self.web3.eth.default_account) + if 'from' not in transaction and is_checksum_address(self.w3.eth.default_account): + transaction = assoc(transaction, 'from', self.w3.eth.default_account) # TODO: move to middleware if block_identifier is None: diff --git a/web3/pm.py b/web3/pm.py index 5257db22bd..24c658f6c9 100644 --- a/web3/pm.py +++ b/web3/pm.py @@ -327,7 +327,7 @@ def get_package_from_manifest(self, manifest: Manifest) -> Package: * Parameters: * ``manifest``: A dict representing a valid manifest """ - return Package(manifest, self.web3) + return Package(manifest, self.w3) def get_package_from_uri(self, manifest_uri: URI) -> Package: """ @@ -339,7 +339,7 @@ def get_package_from_uri(self, manifest_uri: URI) -> Package: * Parameters: * ``uri``: Must be a valid content-addressed URI """ - return Package.from_uri(manifest_uri, self.web3) + return Package.from_uri(manifest_uri, self.w3) def get_local_package(self, package_name: str, ethpm_dir: Path = None) -> Package: """ @@ -381,17 +381,17 @@ def set_registry(self, address: Union[Address, ChecksumAddress, ENS]) -> None: """ if is_canonical_address(address): addr_string = to_text(address) - self.registry = SimpleRegistry(to_checksum_address(addr_string), self.web3) + self.registry = SimpleRegistry(to_checksum_address(addr_string), self.w3) elif is_checksum_address(address): - self.registry = SimpleRegistry(cast(ChecksumAddress, address), self.web3) + self.registry = SimpleRegistry(cast(ChecksumAddress, address), self.w3) elif is_ens_name(address): self._validate_set_ens() - addr_lookup = self.web3.ens.address(str(address)) + addr_lookup = self.w3.ens.address(str(address)) if not addr_lookup: raise NameNotFound( "No address found after ENS lookup for name: {0}.".format(address) ) - self.registry = SimpleRegistry(addr_lookup, self.web3) + self.registry = SimpleRegistry(addr_lookup, self.w3) else: raise PMError( "Expected a canonical/checksummed address or ENS name for the address, " @@ -409,7 +409,7 @@ def deploy_and_set_registry(self) -> ChecksumAddress: w3.ens.setup_address(ens_name, w3.pm.registry.address) """ - self.registry = SimpleRegistry.deploy_new_instance(self.web3) + self.registry = SimpleRegistry.deploy_new_instance(self.w3) return to_checksum_address(self.registry.address) def release_package( @@ -554,11 +554,11 @@ def _validate_set_registry(self) -> None: ) def _validate_set_ens(self) -> None: - if not self.web3: + if not self.w3: raise InvalidAddress( "Could not look up ENS address because no web3 " "connection available" ) - elif not self.web3.ens: + elif not self.w3.ens: raise InvalidAddress( "Could not look up ENS address because web3.ens is " "set to None" ) diff --git a/web3/testing.py b/web3/testing.py index 4537df8c80..f421c83a22 100644 --- a/web3/testing.py +++ b/web3/testing.py @@ -12,21 +12,21 @@ class Testing(Module): def timeTravel(self, timestamp: int) -> None: - return self.web3.manager.request_blocking(RPC.testing_timeTravel, [timestamp]) + return self.w3.manager.request_blocking(RPC.testing_timeTravel, [timestamp]) def mine(self, num_blocks: int = 1) -> None: - return self.web3.manager.request_blocking(RPC.evm_mine, [num_blocks]) + return self.w3.manager.request_blocking(RPC.evm_mine, [num_blocks]) def snapshot(self) -> int: - self.last_snapshot_idx = self.web3.manager.request_blocking(RPC.evm_snapshot, []) + self.last_snapshot_idx = self.w3.manager.request_blocking(RPC.evm_snapshot, []) return self.last_snapshot_idx def reset(self) -> None: - return self.web3.manager.request_blocking(RPC.evm_reset, []) + return self.w3.manager.request_blocking(RPC.evm_reset, []) def revert(self, snapshot_idx: Optional[int] = None) -> None: if snapshot_idx is None: revert_target = self.last_snapshot_idx else: revert_target = snapshot_idx - return self.web3.manager.request_blocking(RPC.evm_revert, [revert_target]) + return self.w3.manager.request_blocking(RPC.evm_revert, [revert_target]) From 6a6e53b7f938102f4d4970d22024bd98dd6f18c2 Mon Sep 17 00:00:00 2001 From: Harmouch101 Date: Fri, 30 Apr 2021 23:03:46 +0300 Subject: [PATCH 4/6] Audit .rst & .py files and convert all Web3 instance variables to use w3 name. Signed-off-by: Harmouch101 --- docs/examples.rst | 4 ++-- docs/web3.main.rst | 2 +- ens/main.py | 4 ++-- ens/utils.py | 6 +++--- tests/core/pm-module/test_ens_integration.py | 2 +- tests/core/providers/test_auto_provider.py | 18 +++++++++--------- tests/core/providers/test_ipc_provider.py | 2 +- tests/core/web3-module/test_api.py | 2 +- tests/core/web3-module/test_clientVersion.py | 2 +- tests/ens/test_utils.py | 4 ++-- tests/ethpm/test_package.py | 6 +++--- tests/integration/go_ethereum/common.py | 2 +- .../go_ethereum/test_goethereum_http.py | 2 +- .../go_ethereum/test_goethereum_ipc.py | 2 +- .../go_ethereum/test_goethereum_ws.py | 2 +- tests/integration/parity/common.py | 2 +- tests/integration/parity/test_parity_http.py | 2 +- tests/integration/parity/test_parity_ipc.py | 2 +- tests/integration/parity/test_parity_ws.py | 2 +- tests/integration/test_ethereum_tester.py | 4 ++-- web3/_utils/module_testing/web3_module.py | 6 +++--- web3/middleware/formatting.py | 6 +++--- web3/middleware/validation.py | 6 +++--- 23 files changed, 45 insertions(+), 45 deletions(-) diff --git a/docs/examples.rst b/docs/examples.rst index e4ad1c2d9b..c9295c27a5 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -970,7 +970,7 @@ The script can be run with: ``python ./eventscanner.py `` # Do `n` retries on `eth_getLogs`, # throttle down block range if needed - end_block, events = _retry_web3_call( + end_block, events = _retry_w3_call( _fetch_events, start_block=start_block, end_block=end_block, @@ -1089,7 +1089,7 @@ The script can be run with: ``python ./eventscanner.py `` return all_processed, total_chunks_scanned - def _retry_web3_call(func, start_block, end_block, retries, delay) -> Tuple[int, list]: + def _retry_w3_call(func, start_block, end_block, retries, delay) -> Tuple[int, list]: """A custom retry loop to throttle down block range. If our JSON-RPC server cannot serve all incoming `eth_getLogs` in a single request, diff --git a/docs/web3.main.rst b/docs/web3.main.rst index 455c306801..d6720b5ad1 100644 --- a/docs/web3.main.rst +++ b/docs/web3.main.rst @@ -1,4 +1,4 @@ -.. _web3_base: +.. _w3_base: Web3 API ======== diff --git a/ens/main.py b/ens/main.py index a9a12b4de5..3191cf9220 100644 --- a/ens/main.py +++ b/ens/main.py @@ -37,7 +37,7 @@ address_to_reverse_domain, default, dict_copy, - init_web3, + init_w3, is_none_or_zero_address, is_valid_name, label_to_hash, @@ -84,7 +84,7 @@ def __init__( :param hex-string addr: the address of the ENS registry on-chain. If not provided, ENS.py will default to the mainnet ENS registry address. """ - self.w3 = init_web3(provider) + self.w3 = init_w3(provider) ens_addr = addr if addr else ENS_MAINNET_ADDR self.ens = self.w3.eth.contract(abi=abis.ENS, address=ens_addr) diff --git a/ens/utils.py b/ens/utils.py index c32afdb347..e71a56520c 100644 --- a/ens/utils.py +++ b/ens/utils.py @@ -74,7 +74,7 @@ def ensure_hex(data: HexBytes) -> HexBytes: return data -def init_web3(provider: 'BaseProvider' = cast('BaseProvider', default)) -> '_Web3': +def init_w3(provider: 'BaseProvider' = cast('BaseProvider', default)) -> '_Web3': from web3 import Web3 as Web3Main if provider is default: @@ -82,10 +82,10 @@ def init_web3(provider: 'BaseProvider' = cast('BaseProvider', default)) -> '_Web else: w3 = Web3Main(provider, ens=None) - return customize_web3(w3) + return customize_w3(w3) -def customize_web3(w3: '_Web3') -> '_Web3': +def customize_w3(w3: '_Web3') -> '_Web3': from web3.middleware import make_stalecheck_middleware w3.middleware_onion.remove('name_to_address') diff --git a/tests/core/pm-module/test_ens_integration.py b/tests/core/pm-module/test_ens_integration.py index 163dcae8ff..428a3ec4ec 100644 --- a/tests/core/pm-module/test_ens_integration.py +++ b/tests/core/pm-module/test_ens_integration.py @@ -127,7 +127,7 @@ def test_ens_must_be_set_before_ens_methods_can_be_used(ens): w3.pm.set_registry("tester.eth") -def test_web3_ens(ens): +def test_w3_ens(ens): w3 = ens.web3 ns = ENS.fromWeb3(w3, ens.ens.address) w3.ens = ns diff --git a/tests/core/providers/test_auto_provider.py b/tests/core/providers/test_auto_provider.py index 6fd773a90a..753487fb6b 100644 --- a/tests/core/providers/test_auto_provider.py +++ b/tests/core/providers/test_auto_provider.py @@ -52,7 +52,7 @@ def test_load_provider_from_env(monkeypatch, uri, expected_type, expected_attrs) @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_web3_auto_infura_empty_key(monkeypatch, caplog, environ_name): +def test_w3_auto_infura_empty_key(monkeypatch, caplog, environ_name): monkeypatch.setenv('WEB3_INFURA_SCHEME', 'https') monkeypatch.setenv(environ_name, '') @@ -61,7 +61,7 @@ def test_web3_auto_infura_empty_key(monkeypatch, caplog, environ_name): @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_web3_auto_infura_deleted_key(monkeypatch, caplog, environ_name): +def test_w3_auto_infura_deleted_key(monkeypatch, caplog, environ_name): monkeypatch.setenv('WEB3_INFURA_SCHEME', 'https') monkeypatch.delenv(environ_name, raising=False) @@ -71,7 +71,7 @@ def test_web3_auto_infura_deleted_key(monkeypatch, caplog, environ_name): @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_web3_auto_infura_websocket_empty_key(monkeypatch, caplog, environ_name): +def test_w3_auto_infura_websocket_empty_key(monkeypatch, caplog, environ_name): monkeypatch.setenv(environ_name, '') with pytest.raises(InfuraKeyNotFound): @@ -79,7 +79,7 @@ def test_web3_auto_infura_websocket_empty_key(monkeypatch, caplog, environ_name) @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_web3_auto_infura_websocket_deleted_key(monkeypatch, caplog, environ_name): +def test_w3_auto_infura_websocket_deleted_key(monkeypatch, caplog, environ_name): monkeypatch.delenv(environ_name, raising=False) with pytest.raises(InfuraKeyNotFound): @@ -87,7 +87,7 @@ def test_web3_auto_infura_websocket_deleted_key(monkeypatch, caplog, environ_nam @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_web3_auto_infura(monkeypatch, caplog, environ_name): +def test_w3_auto_infura(monkeypatch, caplog, environ_name): monkeypatch.setenv('WEB3_INFURA_SCHEME', 'https') API_KEY = 'aoeuhtns' @@ -103,7 +103,7 @@ def test_web3_auto_infura(monkeypatch, caplog, environ_name): @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_web3_auto_infura_websocket_default(monkeypatch, caplog, environ_name): +def test_w3_auto_infura_websocket_default(monkeypatch, caplog, environ_name): monkeypatch.setenv('WEB3_INFURA_SCHEME', 'wss') API_KEY = 'aoeuhtns' monkeypatch.setenv(environ_name, API_KEY) @@ -117,7 +117,7 @@ def test_web3_auto_infura_websocket_default(monkeypatch, caplog, environ_name): assert getattr(w3.provider, 'endpoint_uri') == expected_url -def test_web3_auto_infura_raises_error_with_nonexistent_scheme(monkeypatch): +def test_w3_auto_infura_raises_error_with_nonexistent_scheme(monkeypatch): monkeypatch.setenv('WEB3_INFURA_API_KEY', 'test') monkeypatch.setenv('WEB3_INFURA_SCHEME', 'not-a-scheme') @@ -127,7 +127,7 @@ def test_web3_auto_infura_raises_error_with_nonexistent_scheme(monkeypatch): @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_web3_auto_infura_websocket_with_secret(monkeypatch, caplog, environ_name): +def test_w3_auto_infura_websocket_with_secret(monkeypatch, caplog, environ_name): monkeypatch.setenv(environ_name, 'test') monkeypatch.setenv('WEB3_INFURA_API_SECRET', 'secret') @@ -140,7 +140,7 @@ def test_web3_auto_infura_websocket_with_secret(monkeypatch, caplog, environ_nam @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_web3_auto_infura_with_secret(monkeypatch, caplog, environ_name): +def test_w3_auto_infura_with_secret(monkeypatch, caplog, environ_name): monkeypatch.setenv('WEB3_INFURA_SCHEME', 'https') monkeypatch.setenv(environ_name, 'test') monkeypatch.setenv('WEB3_INFURA_API_SECRET', 'secret') diff --git a/tests/core/providers/test_ipc_provider.py b/tests/core/providers/test_ipc_provider.py index 2b1042b007..d1bd609db0 100644 --- a/tests/core/providers/test_ipc_provider.py +++ b/tests/core/providers/test_ipc_provider.py @@ -86,7 +86,7 @@ def test_sync_waits_for_full_result(jsonrpc_ipc_pipe_path, serve_empty_result): provider._socket.sock.close() -def test_web3_auto_gethdev(): +def test_w3_auto_gethdev(): assert isinstance(w3.provider, IPCProvider) return_block_with_long_extra_data = construct_fixture_middleware({ 'eth_getBlockByNumber': {'extraData': '0x' + 'ff' * 33}, diff --git a/tests/core/web3-module/test_api.py b/tests/core/web3-module/test_api.py index 1f404e695e..61ff832bb6 100644 --- a/tests/core/web3-module/test_api.py +++ b/tests/core/web3-module/test_api.py @@ -1,2 +1,2 @@ -def test_web3_api(web3): +def test_w3_api(web3): assert web3.api.startswith("5") diff --git a/tests/core/web3-module/test_clientVersion.py b/tests/core/web3-module/test_clientVersion.py index 4f2783adcf..b3102bdcc4 100644 --- a/tests/core/web3-module/test_clientVersion.py +++ b/tests/core/web3-module/test_clientVersion.py @@ -1,2 +1,2 @@ -def test_web3_clientVersion(web3): +def test_w3_clientVersion(web3): assert web3.clientVersion.startswith("EthereumTester/") diff --git a/tests/ens/test_utils.py b/tests/ens/test_utils.py index 052670a533..6daf5a40e5 100644 --- a/tests/ens/test_utils.py +++ b/tests/ens/test_utils.py @@ -1,10 +1,10 @@ from ens.utils import ( - init_web3, + init_w3, ) def test_init_adds_middlewares(): - w3 = init_web3() + w3 = init_w3() middlewares = map(str, w3.manager.middleware_onion) assert 'stalecheck_middleware' in next(middlewares) diff --git a/tests/ethpm/test_package.py b/tests/ethpm/test_package.py index 1202b54715..3f2fab0249 100644 --- a/tests/ethpm/test_package.py +++ b/tests/ethpm/test_package.py @@ -28,12 +28,12 @@ def deployed_safe_math(safe_math_package, w3): return safe_math_package, tx_receipt.contractAddress -def test_package_object_instantiates_with_a_web3_object(all_manifests, w3): +def test_package_object_instantiates_with_a_w3_object(all_manifests, w3): package = Package(all_manifests, w3) assert package.w3 is w3 -def test_update_web3(deployed_safe_math, w3): +def test_update_w3(deployed_safe_math, w3): new_w3 = Web3(Web3.EthereumTesterProvider()) original_package, _ = deployed_safe_math assert original_package.w3 is w3 @@ -45,7 +45,7 @@ def test_update_web3(deployed_safe_math, w3): new_package.deployments -def test_get_contract_factory_with_default_web3(safe_math_package, w3): +def test_get_contract_factory_with_default_w3(safe_math_package, w3): contract_factory = safe_math_package.get_contract_factory("SafeMathLib") assert hasattr(contract_factory, "address") assert hasattr(contract_factory, "abi") diff --git a/tests/integration/go_ethereum/common.py b/tests/integration/go_ethereum/common.py index ff747167dd..a73d010046 100644 --- a/tests/integration/go_ethereum/common.py +++ b/tests/integration/go_ethereum/common.py @@ -14,7 +14,7 @@ class GoEthereumTest(Web3ModuleTest): - def _check_web3_clientVersion(self, client_version): + def _check_w3_clientVersion(self, client_version): assert client_version.startswith('Geth/') diff --git a/tests/integration/go_ethereum/test_goethereum_http.py b/tests/integration/go_ethereum/test_goethereum_http.py index ffdeae1d7e..c075b28bef 100644 --- a/tests/integration/go_ethereum/test_goethereum_http.py +++ b/tests/integration/go_ethereum/test_goethereum_http.py @@ -60,7 +60,7 @@ def geth_command_arguments(rpc_port, def web3(geth_process, endpoint_uri): wait_for_http(endpoint_uri) _w3 = Web3(Web3.HTTPProvider(endpoint_uri)) - return _web3 + return _w3 class TestGoEthereumTest(GoEthereumTest): diff --git a/tests/integration/go_ethereum/test_goethereum_ipc.py b/tests/integration/go_ethereum/test_goethereum_ipc.py index 9d9d2a70f2..3f29c1a294 100644 --- a/tests/integration/go_ethereum/test_goethereum_ipc.py +++ b/tests/integration/go_ethereum/test_goethereum_ipc.py @@ -55,7 +55,7 @@ def geth_ipc_path(datadir): def web3(geth_process, geth_ipc_path): wait_for_socket(geth_ipc_path) _w3 = Web3(Web3.IPCProvider(geth_ipc_path)) - return _web3 + return _w3 class TestGoEthereumTest(GoEthereumTest): diff --git a/tests/integration/go_ethereum/test_goethereum_ws.py b/tests/integration/go_ethereum/test_goethereum_ws.py index 6c1980f1a1..47b4bd6dda 100644 --- a/tests/integration/go_ethereum/test_goethereum_ws.py +++ b/tests/integration/go_ethereum/test_goethereum_ws.py @@ -66,7 +66,7 @@ def geth_command_arguments(geth_binary, def web3(geth_process, endpoint_uri, event_loop): event_loop.run_until_complete(wait_for_ws(endpoint_uri, event_loop)) _w3 = Web3(Web3.WebsocketProvider(endpoint_uri)) - return _web3 + return _w3 class TestGoEthereumTest(GoEthereumTest): diff --git a/tests/integration/parity/common.py b/tests/integration/parity/common.py index b38356f91b..23212cb38d 100644 --- a/tests/integration/parity/common.py +++ b/tests/integration/parity/common.py @@ -21,7 +21,7 @@ class ParityWeb3ModuleTest(Web3ModuleTest): - def _check_web3_clientVersion(self, client_version): + def _check_w3_clientVersion(self, client_version): assert client_version.startswith('Parity-Ethereum/') diff --git a/tests/integration/parity/test_parity_http.py b/tests/integration/parity/test_parity_http.py index c6bf6b1d96..ae88cd8494 100644 --- a/tests/integration/parity/test_parity_http.py +++ b/tests/integration/parity/test_parity_http.py @@ -77,7 +77,7 @@ def parity_import_blocks_command(parity_binary, rpc_port, datadir, passwordfile) def web3(parity_process, endpoint_uri): wait_for_http(endpoint_uri) _w3 = Web3(Web3.HTTPProvider(endpoint_uri)) - return _web3 + return _w3 class TestParityWeb3ModuleTest(ParityWeb3ModuleTest): diff --git a/tests/integration/parity/test_parity_ipc.py b/tests/integration/parity/test_parity_ipc.py index 4be012054a..702b46d142 100644 --- a/tests/integration/parity/test_parity_ipc.py +++ b/tests/integration/parity/test_parity_ipc.py @@ -75,7 +75,7 @@ def parity_import_blocks_command(parity_binary, ipc_path, datadir, passwordfile) def web3(parity_process, ipc_path): wait_for_socket(ipc_path) _w3 = Web3(Web3.IPCProvider(ipc_path)) - return _web3 + return _w3 class TestParityWeb3ModuleTest(ParityWeb3ModuleTest): diff --git a/tests/integration/parity/test_parity_ws.py b/tests/integration/parity/test_parity_ws.py index 4bc44f00e3..5479679969 100644 --- a/tests/integration/parity/test_parity_ws.py +++ b/tests/integration/parity/test_parity_ws.py @@ -80,7 +80,7 @@ def parity_import_blocks_command(parity_binary, ws_port, datadir, passwordfile): def web3(parity_process, endpoint_uri, event_loop): event_loop.run_until_complete(wait_for_ws(endpoint_uri, event_loop)) _w3 = Web3(Web3.WebsocketProvider(endpoint_uri)) - return _web3 + return _w3 class TestParityWeb3ModuleTest(ParityWeb3ModuleTest): diff --git a/tests/integration/test_ethereum_tester.py b/tests/integration/test_ethereum_tester.py index 08b42739fa..49379838c0 100644 --- a/tests/integration/test_ethereum_tester.py +++ b/tests/integration/test_ethereum_tester.py @@ -47,7 +47,7 @@ def eth_tester_provider(eth_tester): @pytest.fixture(scope="module") def web3(eth_tester_provider): _w3 = Web3(eth_tester_provider) - return _web3 + return _w3 # @@ -211,7 +211,7 @@ def funded_account_for_raw_txn(web3): class TestEthereumTesterWeb3Module(Web3ModuleTest): - def _check_web3_clientVersion(self, client_version): + def _check_w3_clientVersion(self, client_version): assert client_version.startswith('EthereumTester/') diff --git a/web3/_utils/module_testing/web3_module.py b/web3/_utils/module_testing/web3_module.py index a8eb73f332..fd2bf6df89 100644 --- a/web3/_utils/module_testing/web3_module.py +++ b/web3/_utils/module_testing/web3_module.py @@ -25,11 +25,11 @@ class Web3ModuleTest: - def test_web3_clientVersion(self, web3: Web3) -> None: + def test_w3_clientVersion(self, web3: Web3) -> None: client_version = web3.clientVersion - self._check_web3_clientVersion(client_version) + self._check_w3_clientVersion(client_version) - def _check_web3_clientVersion(self, client_version: str) -> NoReturn: + def _check_w3_clientVersion(self, client_version: str) -> NoReturn: raise NotImplementedError("Must be implemented by subclasses") # Contract that calculated test values can be found at diff --git a/web3/middleware/formatting.py b/web3/middleware/formatting.py index 3542583a9a..dd1199c87b 100644 --- a/web3/middleware/formatting.py +++ b/web3/middleware/formatting.py @@ -28,7 +28,7 @@ def construct_formatting_middleware( result_formatters: Optional[Formatters] = None, error_formatters: Optional[Formatters] = None ) -> Middleware: - def ignore_web3_in_standard_formatters( + def ignore_w3_in_standard_formatters( w3: "Web3", ) -> FormattersDict: return dict( @@ -37,10 +37,10 @@ def ignore_web3_in_standard_formatters( error_formatters=error_formatters or {}, ) - return construct_web3_formatting_middleware(ignore_web3_in_standard_formatters) + return construct_w3_formatting_middleware(ignore_w3_in_standard_formatters) -def construct_web3_formatting_middleware( +def construct_w3_formatting_middleware( web3_formatters_builder: Callable[["Web3"], FormattersDict] ) -> Middleware: def formatter_middleware( diff --git a/web3/middleware/validation.py b/web3/middleware/validation.py index 2e956655f4..4132172133 100644 --- a/web3/middleware/validation.py +++ b/web3/middleware/validation.py @@ -32,7 +32,7 @@ ValidationError, ) from web3.middleware.formatting import ( - construct_web3_formatting_middleware, + construct_w3_formatting_middleware, ) from web3.types import ( FormattersDict, @@ -117,7 +117,7 @@ def chain_id_validator(web3: "Web3") -> Callable[..., Any]: ) -def build_validators_with_web3(w3: "Web3") -> FormattersDict: +def build_validators_with_w3(w3: "Web3") -> FormattersDict: return dict( request_formatters={ RPC.eth_sendTransaction: chain_id_validator(w3), @@ -131,4 +131,4 @@ def build_validators_with_web3(w3: "Web3") -> FormattersDict: ) -validation_middleware = construct_web3_formatting_middleware(build_validators_with_web3) +validation_middleware = construct_w3_formatting_middleware(build_validators_with_w3) From 8f6ef58949b0d28c762e03df63990a9ebd7090cb Mon Sep 17 00:00:00 2001 From: Harmouch101 Date: Fri, 30 Apr 2021 23:08:06 +0300 Subject: [PATCH 5/6] Audit .rst & .py files and convert all Web3 instance variables to use w3 name. Signed-off-by: Harmouch101 --- docs/examples.rst | 4 +- ens/main.py | 4 +- ethpm/_utils/chains.py | 2 +- ethpm/contract.py | 2 +- ethpm/uri.py | 2 +- tests/core/eth-module/test_transactions.py | 4 +- .../go_ethereum/test_goethereum_http.py | 6 +- .../go_ethereum/test_goethereum_ws.py | 6 +- tests/integration/test_ethereum_tester.py | 4 +- web3/_utils/contracts.py | 6 +- web3/_utils/module_testing/eth_module.py | 236 +++++++++--------- .../go_ethereum_admin_module.py | 16 +- web3/_utils/module_testing/net_module.py | 10 +- web3/_utils/module_testing/parity_module.py | 52 ++-- web3/_utils/module_testing/personal_module.py | 78 +++--- web3/_utils/module_testing/version_module.py | 4 +- web3/_utils/module_testing/web3_module.py | 10 +- web3/_utils/transactions.py | 16 +- web3/contract.py | 34 +-- web3/gas_strategies/rpc.py | 2 +- web3/gas_strategies/time_based.py | 2 +- web3/manager.py | 6 +- web3/method.py | 2 +- web3/middleware/__init__.py | 2 +- web3/middleware/attrdict.py | 2 +- web3/middleware/cache.py | 6 +- web3/middleware/exception_handling.py | 2 +- web3/middleware/exception_retry_request.py | 4 +- web3/middleware/fixture.py | 6 +- web3/middleware/gas_price_strategy.py | 2 +- web3/middleware/normalize_errors.py | 2 +- .../simulate_unmined_transaction.py | 2 +- web3/middleware/stalecheck.py | 2 +- web3/middleware/validation.py | 6 +- web3/module.py | 2 +- web3/providers/base.py | 4 +- web3/providers/eth_tester/middleware.py | 8 +- 37 files changed, 279 insertions(+), 279 deletions(-) diff --git a/docs/examples.rst b/docs/examples.rst index c9295c27a5..37bd79de1b 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -863,7 +863,7 @@ The script can be run with: ``python ./eventscanner.py `` because it cannot correctly throttle and decrease the `eth_getLogs` block number range. """ - def __init__(self, web3: Web3, contract: Contract, state: EventScannerState, events: List, filters: {}, + def __init__(self, w3: Web3, contract: Contract, state: EventScannerState, events: List, filters: {}, max_chunk_scan_size: int = 10000, max_request_retries: int = 30, request_retry_seconds: float = 3.0): """ :param contract: Contract @@ -1366,7 +1366,7 @@ The script can be run with: ``python ./eventscanner.py `` state = JSONifiedState() state.restore() - # chain_id: int, web3: Web3, abi: dict, state: EventScannerState, events: List, filters: {}, max_chunk_scan_size: int=10000 + # chain_id: int, w3: Web3, abi: dict, state: EventScannerState, events: List, filters: {}, max_chunk_scan_size: int=10000 scanner = EventScanner( web3=web3, contract=ERC20, diff --git a/ens/main.py b/ens/main.py index 3191cf9220..b175a88382 100644 --- a/ens/main.py +++ b/ens/main.py @@ -91,11 +91,11 @@ def __init__( self._resolverContract = self.w3.eth.contract(abi=abis.RESOLVER) @classmethod - def fromWeb3(cls, web3: 'Web3', addr: ChecksumAddress = None) -> 'ENS': + def fromWeb3(cls, w3: 'Web3', addr: ChecksumAddress = None) -> 'ENS': """ Generate an ENS instance with web3 - :param `web3.Web3` web3: to infer connection information + :param `web3.Web3` w3: to infer connection information :param hex-string addr: the address of the ENS registry on-chain. If not provided, ENS.py will default to the mainnet ENS registry address. """ diff --git a/ethpm/_utils/chains.py b/ethpm/_utils/chains.py index cbdaee7a61..54166c77a0 100644 --- a/ethpm/_utils/chains.py +++ b/ethpm/_utils/chains.py @@ -30,7 +30,7 @@ from web3 import Web3 # noqa: F401 -def get_genesis_block_hash(web3: "Web3") -> HexBytes: +def get_genesis_block_hash(w3: "Web3") -> HexBytes: return web3.eth.get_block(BlockNumber(0))["hash"] diff --git a/ethpm/contract.py b/ethpm/contract.py index 92dfa2faaf..5df60956c3 100644 --- a/ethpm/contract.py +++ b/ethpm/contract.py @@ -60,7 +60,7 @@ def __init__(self, address: bytes, **kwargs: Any) -> None: @classmethod def factory( - cls, web3: "Web3", class_name: str = None, **kwargs: Any + cls, w3: "Web3", class_name: str = None, **kwargs: Any ) -> Contract: dep_link_refs = kwargs.get("unlinked_references") bytecode = kwargs.get("bytecode") diff --git a/ethpm/uri.py b/ethpm/uri.py index 35c8288399..b77ec216c4 100644 --- a/ethpm/uri.py +++ b/ethpm/uri.py @@ -120,7 +120,7 @@ def create_latest_block_uri(w3: "Web3", from_blocks_ago: int = 3) -> URI: @curry -def check_if_chain_matches_chain_uri(web3: "Web3", blockchain_uri: URI) -> bool: +def check_if_chain_matches_chain_uri(w3: "Web3", blockchain_uri: URI) -> bool: chain_id, resource_type, resource_hash = parse_BIP122_uri(blockchain_uri) genesis_block = web3.eth.get_block("earliest") diff --git a/tests/core/eth-module/test_transactions.py b/tests/core/eth-module/test_transactions.py index cbdc7b927d..827b5925d0 100644 --- a/tests/core/eth-module/test_transactions.py +++ b/tests/core/eth-module/test_transactions.py @@ -20,11 +20,11 @@ 'make_chain_id, expect_success', ( ( - lambda web3: web3.eth.chain_id, + lambda w3: web3.eth.chain_id, True, ), pytest.param( - lambda web3: 999999999999, + lambda w3: 999999999999, False, ), ), diff --git a/tests/integration/go_ethereum/test_goethereum_http.py b/tests/integration/go_ethereum/test_goethereum_http.py index c075b28bef..af7faa43c7 100644 --- a/tests/integration/go_ethereum/test_goethereum_http.py +++ b/tests/integration/go_ethereum/test_goethereum_http.py @@ -69,15 +69,15 @@ class TestGoEthereumTest(GoEthereumTest): class TestGoEthereumAdminModuleTest(GoEthereumAdminModuleTest): @pytest.mark.xfail(reason="running geth with the --nodiscover flag doesn't allow peer addition") - def test_admin_peers(self, web3: "Web3") -> None: + def test_admin_peers(self, w3: "Web3") -> None: super().test_admin_peers(web3) - def test_admin_start_stop_rpc(self, web3: "Web3") -> None: + def test_admin_start_stop_rpc(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run pytest.xfail(reason='Only one RPC endpoint is allowed to be active at any time') super().test_admin_start_stop_rpc(web3) - def test_admin_start_stop_ws(self, web3: "Web3") -> None: + def test_admin_start_stop_ws(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run pytest.xfail(reason='Only one WS endpoint is allowed to be active at any time') super().test_admin_start_stop_ws(web3) diff --git a/tests/integration/go_ethereum/test_goethereum_ws.py b/tests/integration/go_ethereum/test_goethereum_ws.py index 47b4bd6dda..bcbe54ff4a 100644 --- a/tests/integration/go_ethereum/test_goethereum_ws.py +++ b/tests/integration/go_ethereum/test_goethereum_ws.py @@ -75,15 +75,15 @@ class TestGoEthereumTest(GoEthereumTest): class TestGoEthereumAdminModuleTest(GoEthereumAdminModuleTest): @pytest.mark.xfail(reason="running geth with the --nodiscover flag doesn't allow peer addition") - def test_admin_peers(self, web3: "Web3") -> None: + def test_admin_peers(self, w3: "Web3") -> None: super().test_admin_peers(web3) - def test_admin_start_stop_ws(self, web3: "Web3") -> None: + def test_admin_start_stop_ws(self, w3: "Web3") -> None: # This test inconsistently causes all tests after it to fail on CI if it's allowed to run pytest.xfail(reason='Only one WebSocket endpoint is allowed to be active at any time') super().test_admin_start_stop_ws(web3) - def test_admin_start_stop_rpc(self, web3: "Web3") -> None: + def test_admin_start_stop_rpc(self, w3: "Web3") -> None: pytest.xfail(reason="This test inconsistently causes all tests after it on CI to fail if it's allowed to run") # noqa: E501 super().test_admin_start_stop_ws(web3) diff --git a/tests/integration/test_ethereum_tester.py b/tests/integration/test_ethereum_tester.py index 49379838c0..04ab807f01 100644 --- a/tests/integration/test_ethereum_tester.py +++ b/tests/integration/test_ethereum_tester.py @@ -266,7 +266,7 @@ class TestEthereumTesterEthModule(EthModuleTest): test_eth_submit_work = not_implemented(EthModuleTest.test_eth_submit_work, ValueError) def test_eth_getBlockByHash_pending( - self, web3: "Web3" + self, w3: "Web3" ) -> None: block = web3.eth.get_block('pending') assert block['hash'] is not None @@ -464,5 +464,5 @@ def test_personal_unlockAccount_failure_deprecated(self, assert result is False @pytest.mark.xfail(raises=ValueError, reason="list_wallets not implemented in eth-tester") - def test_personal_list_wallets(self, web3: "Web3") -> None: + def test_personal_list_wallets(self, w3: "Web3") -> None: super().test_personal_list_wallets(web3) diff --git a/web3/_utils/contracts.py b/web3/_utils/contracts.py index c7d6f45829..4e4b8fd2ab 100644 --- a/web3/_utils/contracts.py +++ b/web3/_utils/contracts.py @@ -164,7 +164,7 @@ def find_matching_fn_abi( def encode_abi( - web3: "Web3", abi: ABIFunction, arguments: Sequence[Any], data: Optional[HexStr] = None + w3: "Web3", abi: ABIFunction, arguments: Sequence[Any], data: Optional[HexStr] = None ) -> HexStr: argument_types = get_abi_input_types(abi) @@ -200,7 +200,7 @@ def encode_abi( def prepare_transaction( address: ChecksumAddress, - web3: "Web3", + w3: "Web3", fn_identifier: Union[str, Type[FallbackFn], Type[ReceiveFn]], contract_abi: Optional[ABI] = None, fn_abi: Optional[ABIFunction] = None, @@ -242,7 +242,7 @@ def prepare_transaction( def encode_transaction_data( - web3: "Web3", + w3: "Web3", fn_identifier: Union[str, Type[FallbackFn], Type[ReceiveFn]], contract_abi: Optional[ABI] = None, fn_abi: Optional[ABIFunction] = None, diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index bb25323542..64f49aab56 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -59,7 +59,7 @@ class EthModuleTest: - def test_eth_protocol_version(self, web3: "Web3") -> None: + def test_eth_protocol_version(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning, match="This method has been deprecated in some clients"): protocol_version = web3.eth.protocol_version @@ -67,14 +67,14 @@ def test_eth_protocol_version(self, web3: "Web3") -> None: assert is_string(protocol_version) assert protocol_version.isdigit() - def test_eth_protocolVersion(self, web3: "Web3") -> None: + def test_eth_protocolVersion(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): protocol_version = web3.eth.protocolVersion assert is_string(protocol_version) assert protocol_version.isdigit() - def test_eth_syncing(self, web3: "Web3") -> None: + def test_eth_syncing(self, w3: "Web3") -> None: syncing = web3.eth.syncing assert is_boolean(syncing) or is_dict(syncing) @@ -91,42 +91,42 @@ def test_eth_syncing(self, web3: "Web3") -> None: assert is_integer(sync_dict['currentBlock']) assert is_integer(sync_dict['highestBlock']) - def test_eth_coinbase(self, web3: "Web3") -> None: + def test_eth_coinbase(self, w3: "Web3") -> None: coinbase = web3.eth.coinbase assert is_checksum_address(coinbase) - def test_eth_mining(self, web3: "Web3") -> None: + def test_eth_mining(self, w3: "Web3") -> None: mining = web3.eth.mining assert is_boolean(mining) - def test_eth_hashrate(self, web3: "Web3") -> None: + def test_eth_hashrate(self, w3: "Web3") -> None: hashrate = web3.eth.hashrate assert is_integer(hashrate) assert hashrate >= 0 - def test_eth_chain_id(self, web3: "Web3") -> None: + def test_eth_chain_id(self, w3: "Web3") -> None: chain_id = web3.eth.chain_id # chain id value from geth fixture genesis file assert chain_id == 131277322940537 - def test_eth_chainId(self, web3: "Web3") -> None: + def test_eth_chainId(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): chain_id = web3.eth.chainId # chain id value from geth fixture genesis file assert chain_id == 131277322940537 - def test_eth_gas_price(self, web3: "Web3") -> None: + def test_eth_gas_price(self, w3: "Web3") -> None: gas_price = web3.eth.gas_price assert is_integer(gas_price) assert gas_price > 0 - def test_eth_gasPrice_deprecated(self, web3: "Web3") -> None: + def test_eth_gasPrice_deprecated(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): gas_price = web3.eth.gasPrice assert is_integer(gas_price) assert gas_price > 0 - def test_eth_accounts(self, web3: "Web3") -> None: + def test_eth_accounts(self, w3: "Web3") -> None: accounts = web3.eth.accounts assert is_list_like(accounts) assert len(accounts) != 0 @@ -137,24 +137,24 @@ def test_eth_accounts(self, web3: "Web3") -> None: )) assert web3.eth.coinbase in accounts - def test_eth_block_number(self, web3: "Web3") -> None: + def test_eth_block_number(self, w3: "Web3") -> None: block_number = web3.eth.block_number assert is_integer(block_number) assert block_number >= 0 - def test_eth_get_block_number(self, web3: "Web3") -> None: + def test_eth_get_block_number(self, w3: "Web3") -> None: block_number = web3.eth.get_block_number() assert is_integer(block_number) assert block_number >= 0 - def test_eth_blockNumber(self, web3: "Web3") -> None: + def test_eth_blockNumber(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): block_number = web3.eth.blockNumber assert is_integer(block_number) assert block_number >= 0 - def test_eth_get_balance(self, web3: "Web3") -> None: + def test_eth_get_balance(self, w3: "Web3") -> None: coinbase = web3.eth.coinbase with pytest.raises(InvalidAddress): @@ -165,7 +165,7 @@ def test_eth_get_balance(self, web3: "Web3") -> None: assert is_integer(balance) assert balance >= 0 - def test_eth_getBalance_deprecated(self, web3: "Web3") -> None: + def test_eth_getBalance_deprecated(self, w3: "Web3") -> None: coinbase = web3.eth.coinbase with pytest.warns(DeprecationWarning, @@ -175,7 +175,7 @@ def test_eth_getBalance_deprecated(self, web3: "Web3") -> None: assert is_integer(balance) assert balance >= 0 - def test_eth_get_balance_with_block_identifier(self, web3: "Web3") -> None: + def test_eth_get_balance_with_block_identifier(self, w3: "Web3") -> None: miner_address = web3.eth.get_block(1)['miner'] genesis_balance = web3.eth.get_balance(miner_address, 0) later_balance = web3.eth.get_balance(miner_address, 1) @@ -189,7 +189,7 @@ def test_eth_get_balance_with_block_identifier(self, web3: "Web3") -> None: ('not-an-address.eth', False) ]) def test_eth_get_balance_with_ens_name( - self, web3: "Web3", address: ChecksumAddress, expect_success: bool + self, w3: "Web3", address: ChecksumAddress, expect_success: bool ) -> None: with ens_addresses(web3, {'test-address.eth': web3.eth.accounts[0]}): if expect_success: @@ -201,39 +201,39 @@ def test_eth_get_balance_with_ens_name( web3.eth.get_balance(address) def test_eth_get_storage_at( - self, web3: "Web3", emitter_contract_address: ChecksumAddress + self, w3: "Web3", emitter_contract_address: ChecksumAddress ) -> None: storage = web3.eth.get_storage_at(emitter_contract_address, 0) assert isinstance(storage, HexBytes) def test_eth_getStorageAt_deprecated( - self, web3: "Web3", emitter_contract_address: ChecksumAddress + self, w3: "Web3", emitter_contract_address: ChecksumAddress ) -> None: with pytest.warns(DeprecationWarning): storage = web3.eth.getStorageAt(emitter_contract_address, 0) assert isinstance(storage, HexBytes) def test_eth_get_storage_at_ens_name( - self, web3: "Web3", emitter_contract_address: ChecksumAddress + self, w3: "Web3", emitter_contract_address: ChecksumAddress ) -> None: with ens_addresses(web3, {'emitter.eth': emitter_contract_address}): storage = web3.eth.get_storage_at('emitter.eth', 0) assert isinstance(storage, HexBytes) - def test_eth_get_storage_at_invalid_address(self, web3: "Web3") -> None: + def test_eth_get_storage_at_invalid_address(self, w3: "Web3") -> None: coinbase = web3.eth.coinbase with pytest.raises(InvalidAddress): web3.eth.get_storage_at(ChecksumAddress(HexAddress(HexStr(coinbase.lower()))), 0) def test_eth_get_transaction_count( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: transaction_count = web3.eth.get_transaction_count(unlocked_account_dual_type) assert is_integer(transaction_count) assert transaction_count >= 0 def test_eth_getTransactionCount_deprecated( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: with pytest.warns(DeprecationWarning): transaction_count = web3.eth.getTransactionCount(unlocked_account_dual_type) @@ -241,20 +241,20 @@ def test_eth_getTransactionCount_deprecated( assert transaction_count >= 0 def test_eth_get_transaction_count_ens_name( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: with ens_addresses(web3, {'unlocked-acct-dual-type.eth': unlocked_account_dual_type}): transaction_count = web3.eth.get_transaction_count('unlocked-acct-dual-type.eth') assert is_integer(transaction_count) assert transaction_count >= 0 - def test_eth_get_transaction_count_invalid_address(self, web3: "Web3") -> None: + def test_eth_get_transaction_count_invalid_address(self, w3: "Web3") -> None: coinbase = web3.eth.coinbase with pytest.raises(InvalidAddress): web3.eth.get_transaction_count(ChecksumAddress(HexAddress(HexStr(coinbase.lower())))) def test_eth_getBlockTransactionCountByHash_empty_block( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: transaction_count = web3.eth.get_block_transaction_count(empty_block['hash']) @@ -262,7 +262,7 @@ def test_eth_getBlockTransactionCountByHash_empty_block( assert transaction_count == 0 def test_eth_getBlockTransactionCountByNumber_empty_block( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: transaction_count = web3.eth.get_block_transaction_count(empty_block['number']) @@ -270,7 +270,7 @@ def test_eth_getBlockTransactionCountByNumber_empty_block( assert transaction_count == 0 def test_eth_getBlockTransactionCountByHash_block_with_txn( - self, web3: "Web3", block_with_txn: BlockData + self, w3: "Web3", block_with_txn: BlockData ) -> None: transaction_count = web3.eth.get_block_transaction_count(block_with_txn['hash']) @@ -278,7 +278,7 @@ def test_eth_getBlockTransactionCountByHash_block_with_txn( assert transaction_count >= 1 def test_eth_getBlockTransactionCountByNumber_block_with_txn( - self, web3: "Web3", block_with_txn: BlockData + self, w3: "Web3", block_with_txn: BlockData ) -> None: transaction_count = web3.eth.get_block_transaction_count(block_with_txn['number']) @@ -286,7 +286,7 @@ def test_eth_getBlockTransactionCountByNumber_block_with_txn( assert transaction_count >= 1 def test_eth_getBlockTransactionCountByHash_block_with_txn_deprecated( - self, web3: "Web3", block_with_txn: BlockData + self, w3: "Web3", block_with_txn: BlockData ) -> None: with pytest.warns( DeprecationWarning, @@ -298,7 +298,7 @@ def test_eth_getBlockTransactionCountByHash_block_with_txn_deprecated( assert transaction_count >= 1 def test_eth_getBlockTransactionCountByNumber_block_with_txn_deprecated( - self, web3: "Web3", block_with_txn: BlockData + self, w3: "Web3", block_with_txn: BlockData ) -> None: with pytest.warns( DeprecationWarning, @@ -309,14 +309,14 @@ def test_eth_getBlockTransactionCountByNumber_block_with_txn_deprecated( assert is_integer(transaction_count) assert transaction_count >= 1 - def test_eth_getUncleCountByBlockHash(self, web3: "Web3", empty_block: BlockData) -> None: + def test_eth_getUncleCountByBlockHash(self, w3: "Web3", empty_block: BlockData) -> None: uncle_count = web3.eth.get_uncle_count(empty_block['hash']) assert is_integer(uncle_count) assert uncle_count == 0 def test_eth_getUncleCountByBlockHash_deprecated(self, - web3: "Web3", + w3: "Web3", empty_block: BlockData) -> None: with pytest.warns(DeprecationWarning, match='getUncleCount is deprecated in favor of get_uncle_count'): @@ -325,14 +325,14 @@ def test_eth_getUncleCountByBlockHash_deprecated(self, assert is_integer(uncle_count) assert uncle_count == 0 - def test_eth_getUncleCountByBlockNumber(self, web3: "Web3", empty_block: BlockData) -> None: + def test_eth_getUncleCountByBlockNumber(self, w3: "Web3", empty_block: BlockData) -> None: uncle_count = web3.eth.get_uncle_count(empty_block['number']) assert is_integer(uncle_count) assert uncle_count == 0 def test_eth_getUncleCountByBlockNumber_deprecated(self, - web3: "Web3", + w3: "Web3", empty_block: BlockData) -> None: with pytest.warns(DeprecationWarning, match='getUncleCount is deprecated in favor of get_uncle_count'): @@ -341,13 +341,13 @@ def test_eth_getUncleCountByBlockNumber_deprecated(self, assert is_integer(uncle_count) assert uncle_count == 0 - def test_eth_get_code(self, web3: "Web3", math_contract_address: ChecksumAddress) -> None: + def test_eth_get_code(self, w3: "Web3", math_contract_address: ChecksumAddress) -> None: code = web3.eth.get_code(math_contract_address) assert isinstance(code, HexBytes) assert len(code) > 0 def test_eth_getCode_deprecated(self, - web3: "Web3", + w3: "Web3", math_contract_address: ChecksumAddress) -> None: with pytest.warns(DeprecationWarning, match='getCode is deprecated in favor of get_code'): code = web3.eth.getCode(math_contract_address) @@ -355,7 +355,7 @@ def test_eth_getCode_deprecated(self, assert len(code) > 0 def test_eth_get_code_ens_address( - self, web3: "Web3", math_contract_address: ChecksumAddress + self, w3: "Web3", math_contract_address: ChecksumAddress ) -> None: with ens_addresses( web3, {'mathcontract.eth': math_contract_address} @@ -364,18 +364,18 @@ def test_eth_get_code_ens_address( assert isinstance(code, HexBytes) assert len(code) > 0 - def test_eth_get_code_invalid_address(self, web3: "Web3", math_contract: "Contract") -> None: + def test_eth_get_code_invalid_address(self, w3: "Web3", math_contract: "Contract") -> None: with pytest.raises(InvalidAddress): web3.eth.get_code(ChecksumAddress(HexAddress(HexStr(math_contract.address.lower())))) def test_eth_get_code_with_block_identifier( - self, web3: "Web3", emitter_contract: "Contract" + self, w3: "Web3", emitter_contract: "Contract" ) -> None: code = web3.eth.get_code(emitter_contract.address, block_identifier=web3.eth.block_number) assert isinstance(code, HexBytes) assert len(code) > 0 - def test_eth_sign(self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress) -> None: + def test_eth_sign(self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress) -> None: signature = web3.eth.sign( unlocked_account_dual_type, text='Message tö sign. Longer than hash!' ) @@ -408,7 +408,7 @@ def test_eth_sign(self, web3: "Web3", unlocked_account_dual_type: ChecksumAddres assert new_signature != signature def test_eth_sign_ens_names( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: with ens_addresses(web3, {'unlocked-acct.eth': unlocked_account_dual_type}): signature = web3.eth.sign( @@ -419,7 +419,7 @@ def test_eth_sign_ens_names( def test_eth_sign_typed_data( self, - web3: "Web3", + w3: "Web3", unlocked_account_dual_type: ChecksumAddress, skip_if_testrpc: Callable[["Web3"], None], ) -> None: @@ -471,7 +471,7 @@ def test_eth_sign_typed_data( def test_eth_signTypedData_deprecated( self, - web3: "Web3", + w3: "Web3", unlocked_account_dual_type: ChecksumAddress, skip_if_testrpc: Callable[["Web3"], None], ) -> None: @@ -523,7 +523,7 @@ def test_eth_signTypedData_deprecated( def test_invalid_eth_sign_typed_data( self, - web3: "Web3", + w3: "Web3", unlocked_account_dual_type: ChecksumAddress, skip_if_testrpc: Callable[["Web3"], None] ) -> None: @@ -574,7 +574,7 @@ def test_invalid_eth_sign_typed_data( json.loads(invalid_typed_message) ) - def test_eth_sign_transaction(self, web3: "Web3", unlocked_account: ChecksumAddress) -> None: + def test_eth_sign_transaction(self, w3: "Web3", unlocked_account: ChecksumAddress) -> None: txn_params: TxParams = { 'from': unlocked_account, 'to': unlocked_account, @@ -593,7 +593,7 @@ def test_eth_sign_transaction(self, web3: "Web3", unlocked_account: ChecksumAddr assert result['tx']['nonce'] == txn_params['nonce'] def test_eth_signTransaction_deprecated(self, - web3: "Web3", + w3: "Web3", unlocked_account: ChecksumAddress) -> None: txn_params: TxParams = { 'from': unlocked_account, @@ -615,7 +615,7 @@ def test_eth_signTransaction_deprecated(self, assert result['tx']['nonce'] == txn_params['nonce'] def test_eth_sign_transaction_ens_names( - self, web3: "Web3", unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: with ens_addresses(web3, {'unlocked-account.eth': unlocked_account}): txn_params: TxParams = { @@ -636,7 +636,7 @@ def test_eth_sign_transaction_ens_names( assert result['tx']['nonce'] == txn_params['nonce'] def test_eth_send_transaction_addr_checksum_required( - self, web3: "Web3", unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: non_checksum_addr = unlocked_account.lower() txn_params: TxParams = { @@ -656,7 +656,7 @@ def test_eth_send_transaction_addr_checksum_required( web3.eth.send_transaction(invalid_params) def test_eth_send_transaction( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account_dual_type, @@ -675,7 +675,7 @@ def test_eth_send_transaction( assert txn['gasPrice'] == txn_params['gasPrice'] def test_eth_sendTransaction_deprecated( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account_dual_type, @@ -696,7 +696,7 @@ def test_eth_sendTransaction_deprecated( assert txn['gasPrice'] == txn_params['gasPrice'] def test_eth_send_transaction_with_nonce( - self, web3: "Web3", unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account, @@ -718,7 +718,7 @@ def test_eth_send_transaction_with_nonce( assert txn['nonce'] == txn_params['nonce'] def test_eth_replace_transaction( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account_dual_type, @@ -740,7 +740,7 @@ def test_eth_replace_transaction( assert replace_txn['gasPrice'] == txn_params['gasPrice'] def test_eth_replaceTransaction_deprecated( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account_dual_type, @@ -766,7 +766,7 @@ def test_eth_replaceTransaction_deprecated( assert replace_txn['gasPrice'] == txn_params['gasPrice'] def test_eth_replace_transaction_non_existing_transaction( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account_dual_type, @@ -782,7 +782,7 @@ def test_eth_replace_transaction_non_existing_transaction( ) def test_eth_replace_transaction_already_mined( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account_dual_type, @@ -799,7 +799,7 @@ def test_eth_replace_transaction_already_mined( web3.eth.replace_transaction(txn_hash, txn_params) def test_eth_replace_transaction_incorrect_nonce( - self, web3: "Web3", unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account, @@ -817,7 +817,7 @@ def test_eth_replace_transaction_incorrect_nonce( web3.eth.replace_transaction(txn_hash, txn_params) def test_eth_replace_transaction_gas_price_too_low( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account_dual_type, @@ -833,7 +833,7 @@ def test_eth_replace_transaction_gas_price_too_low( web3.eth.replace_transaction(txn_hash, txn_params) def test_eth_replace_transaction_gas_price_defaulting_minimum( - self, web3: "Web3", unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account, @@ -851,7 +851,7 @@ def test_eth_replace_transaction_gas_price_defaulting_minimum( assert replace_txn['gasPrice'] == 12 # minimum gas price def test_eth_replace_transaction_gas_price_defaulting_strategy_higher( - self, web3: "Web3", unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account, @@ -862,7 +862,7 @@ def test_eth_replace_transaction_gas_price_defaulting_strategy_higher( } txn_hash = web3.eth.send_transaction(txn_params) - def higher_gas_price_strategy(web3: "Web3", txn: TxParams) -> Wei: + def higher_gas_price_strategy(w3: "Web3", txn: TxParams) -> Wei: return Wei(20) web3.eth.set_gas_price_strategy(higher_gas_price_strategy) @@ -873,7 +873,7 @@ def higher_gas_price_strategy(web3: "Web3", txn: TxParams) -> Wei: assert replace_txn['gasPrice'] == 20 # Strategy provides higher gas price def test_eth_replace_transaction_gas_price_defaulting_strategy_lower( - self, web3: "Web3", unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account, @@ -884,7 +884,7 @@ def test_eth_replace_transaction_gas_price_defaulting_strategy_lower( } txn_hash = web3.eth.send_transaction(txn_params) - def lower_gas_price_strategy(web3: "Web3", txn: TxParams) -> Wei: + def lower_gas_price_strategy(w3: "Web3", txn: TxParams) -> Wei: return Wei(5) web3.eth.set_gas_price_strategy(lower_gas_price_strategy) @@ -896,7 +896,7 @@ def lower_gas_price_strategy(web3: "Web3", txn: TxParams) -> Wei: assert replace_txn['gasPrice'] == 12 def test_eth_modify_transaction( - self, web3: "Web3", unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account, @@ -919,7 +919,7 @@ def test_eth_modify_transaction( assert modified_txn['gasPrice'] == cast(int, txn_params['gasPrice']) * 2 def test_eth_modifyTransaction_deprecated( - self, web3: "Web3", unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { 'from': unlocked_account, @@ -957,7 +957,7 @@ def test_eth_modifyTransaction_deprecated( ) def test_eth_send_raw_transaction( self, - web3: "Web3", + w3: "Web3", raw_transaction: Union[HexStr, bytes], funded_account_for_raw_txn: ChecksumAddress, expected_hash: HexStr, @@ -966,7 +966,7 @@ def test_eth_send_raw_transaction( assert txn_hash == web3.toBytes(hexstr=expected_hash) def test_eth_call( - self, web3: "Web3", math_contract: "Contract" + self, w3: "Web3", math_contract: "Contract" ) -> None: coinbase = web3.eth.coinbase txn_params = math_contract._prepare_transaction( @@ -980,7 +980,7 @@ def test_eth_call( assert result == 18 def test_eth_call_with_override( - self, web3: "Web3", revert_contract: "Contract" + self, w3: "Web3", revert_contract: "Contract" ) -> None: coinbase = web3.eth.coinbase txn_params = revert_contract._prepare_transaction( @@ -1002,7 +1002,7 @@ def test_eth_call_with_override( assert result is False def test_eth_call_with_0_result( - self, web3: "Web3", math_contract: "Contract" + self, w3: "Web3", math_contract: "Contract" ) -> None: coinbase = web3.eth.coinbase txn_params = math_contract._prepare_transaction( @@ -1017,7 +1017,7 @@ def test_eth_call_with_0_result( def test_eth_call_revert_with_msg( self, - web3: "Web3", + w3: "Web3", revert_contract: "Contract", unlocked_account: ChecksumAddress, ) -> None: @@ -1034,7 +1034,7 @@ def test_eth_call_revert_with_msg( def test_eth_call_revert_without_msg( self, - web3: "Web3", + w3: "Web3", revert_contract: "Contract", unlocked_account: ChecksumAddress, ) -> None: @@ -1050,7 +1050,7 @@ def test_eth_call_revert_without_msg( def test_eth_estimate_gas_revert_with_msg( self, - web3: "Web3", + w3: "Web3", revert_contract: "Contract", unlocked_account: ChecksumAddress, ) -> None: @@ -1067,7 +1067,7 @@ def test_eth_estimate_gas_revert_with_msg( def test_eth_estimate_gas_revert_without_msg( self, - web3: "Web3", + w3: "Web3", revert_contract: "Contract", unlocked_account: ChecksumAddress, ) -> None: @@ -1082,7 +1082,7 @@ def test_eth_estimate_gas_revert_without_msg( web3.eth.estimate_gas(txn_params) def test_eth_estimate_gas( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: gas_estimate = web3.eth.estimate_gas({ 'from': unlocked_account_dual_type, @@ -1093,7 +1093,7 @@ def test_eth_estimate_gas( assert gas_estimate > 0 def test_eth_estimateGas_deprecated( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: with pytest.warns(DeprecationWarning, match="estimateGas is deprecated in favor of estimate_gas"): @@ -1106,7 +1106,7 @@ def test_eth_estimateGas_deprecated( assert gas_estimate > 0 def test_eth_estimate_gas_with_block( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: gas_estimate = web3.eth.estimate_gas({ 'from': unlocked_account_dual_type, @@ -1117,65 +1117,65 @@ def test_eth_estimate_gas_with_block( assert gas_estimate > 0 def test_eth_getBlock_deprecated( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: with pytest.warns(DeprecationWarning, match="getBlock is deprecated in favor of get_block"): block = web3.eth.getBlock(empty_block['hash']) assert block['hash'] == empty_block['hash'] def test_eth_getBlockByHash( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: block = web3.eth.get_block(empty_block['hash']) assert block['hash'] == empty_block['hash'] def test_eth_getBlockByHash_not_found( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: with pytest.raises(BlockNotFound): web3.eth.get_block(UNKNOWN_HASH) def test_eth_getBlockByHash_pending( - self, web3: "Web3" + self, w3: "Web3" ) -> None: block = web3.eth.get_block('pending') assert block['hash'] is None def test_eth_getBlockByNumber_with_integer( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: block = web3.eth.get_block(empty_block['number']) assert block['number'] == empty_block['number'] def test_eth_getBlockByNumber_with_integer_deprecated( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: with pytest.warns(DeprecationWarning, match="getBlock is deprecated in favor of get_block"): block = web3.eth.getBlock(empty_block['number']) assert block['number'] == empty_block['number'] def test_eth_getBlockByNumber_latest( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: current_block_number = web3.eth.block_number block = web3.eth.get_block('latest') assert block['number'] == current_block_number def test_eth_getBlockByNumber_not_found( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: with pytest.raises(BlockNotFound): web3.eth.get_block(BlockNumber(12345)) def test_eth_getBlockByNumber_pending( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: current_block_number = web3.eth.block_number block = web3.eth.get_block('pending') assert block['number'] == current_block_number + 1 def test_eth_getBlockByNumber_earliest( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: genesis_block = web3.eth.get_block(BlockNumber(0)) block = web3.eth.get_block('earliest') @@ -1183,21 +1183,21 @@ def test_eth_getBlockByNumber_earliest( assert block['hash'] == genesis_block['hash'] def test_eth_getBlockByNumber_full_transactions( - self, web3: "Web3", block_with_txn: BlockData + self, w3: "Web3", block_with_txn: BlockData ) -> None: block = web3.eth.get_block(block_with_txn['number'], True) transaction = block['transactions'][0] assert transaction['hash'] == block_with_txn['transactions'][0] # type: ignore def test_eth_getTransactionByHash( - self, web3: "Web3", mined_txn_hash: HexStr + self, w3: "Web3", mined_txn_hash: HexStr ) -> None: transaction = web3.eth.get_transaction(mined_txn_hash) assert is_dict(transaction) assert transaction['hash'] == HexBytes(mined_txn_hash) def test_eth_getTransactionByHash_deprecated( - self, web3: "Web3", mined_txn_hash: HexStr + self, w3: "Web3", mined_txn_hash: HexStr ) -> None: with pytest.warns(DeprecationWarning, match='getTransaction is deprecated in favor of get_transaction'): @@ -1206,21 +1206,21 @@ def test_eth_getTransactionByHash_deprecated( assert transaction['hash'] == HexBytes(mined_txn_hash) def test_eth_getTransactionByHash_contract_creation( - self, web3: "Web3", math_contract_deploy_txn_hash: HexStr + self, w3: "Web3", math_contract_deploy_txn_hash: HexStr ) -> None: transaction = web3.eth.get_transaction(math_contract_deploy_txn_hash) assert is_dict(transaction) assert transaction['to'] is None, "to field is %r" % transaction['to'] def test_eth_getTransactionByBlockHashAndIndex( - self, web3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr + self, w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: transaction = web3.eth.get_transaction_by_block(block_with_txn['hash'], 0) assert is_dict(transaction) assert transaction['hash'] == HexBytes(mined_txn_hash) def test_eth_getTransactionByBlockHashAndIndex_deprecated( - self, web3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr + self, w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: with pytest.warns( DeprecationWarning, @@ -1231,14 +1231,14 @@ def test_eth_getTransactionByBlockHashAndIndex_deprecated( assert transaction['hash'] == HexBytes(mined_txn_hash) def test_eth_getTransactionByBlockNumberAndIndex( - self, web3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr + self, w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: transaction = web3.eth.get_transaction_by_block(block_with_txn['number'], 0) assert is_dict(transaction) assert transaction['hash'] == HexBytes(mined_txn_hash) def test_eth_getTransactionByBlockNumberAndIndex_deprecated( - self, web3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr + self, w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: with pytest.warns( DeprecationWarning, @@ -1249,7 +1249,7 @@ def test_eth_getTransactionByBlockNumberAndIndex_deprecated( assert transaction['hash'] == HexBytes(mined_txn_hash) def test_eth_get_transaction_receipt_mined( - self, web3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr + self, w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: receipt = web3.eth.get_transaction_receipt(mined_txn_hash) assert is_dict(receipt) @@ -1262,7 +1262,7 @@ def test_eth_get_transaction_receipt_mined( assert is_checksum_address(receipt['from']) def test_eth_getTransactionReceipt_mined_deprecated( - self, web3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr + self, w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: with pytest.warns( DeprecationWarning, @@ -1278,7 +1278,7 @@ def test_eth_getTransactionReceipt_mined_deprecated( assert is_checksum_address(receipt['from']) def test_eth_get_transaction_receipt_unmined( - self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_hash = web3.eth.send_transaction({ 'from': unlocked_account_dual_type, @@ -1292,7 +1292,7 @@ def test_eth_get_transaction_receipt_unmined( def test_eth_get_transaction_receipt_with_log_entry( self, - web3: "Web3", + w3: "Web3", block_with_txn_with_log: BlockData, emitter_contract: "Contract", txn_hash_with_log: HexStr, @@ -1314,15 +1314,15 @@ def test_eth_get_transaction_receipt_with_log_entry( assert log_entry['transactionIndex'] == 0 assert log_entry['transactionHash'] == HexBytes(txn_hash_with_log) - def test_eth_getUncleByBlockHashAndIndex(self, web3: "Web3") -> None: + def test_eth_getUncleByBlockHashAndIndex(self, w3: "Web3") -> None: # TODO: how do we make uncles.... pass - def test_eth_getUncleByBlockNumberAndIndex(self, web3: "Web3") -> None: + def test_eth_getUncleByBlockNumberAndIndex(self, w3: "Web3") -> None: # TODO: how do we make uncles.... pass - def test_eth_newFilter(self, web3: "Web3") -> None: + def test_eth_newFilter(self, w3: "Web3") -> None: filter = web3.eth.filter({}) changes = web3.eth.get_filter_changes(filter.filter_id) @@ -1336,7 +1336,7 @@ def test_eth_newFilter(self, web3: "Web3") -> None: result = web3.eth.uninstall_filter(filter.filter_id) assert result is True - def test_eth_newFilter_deprecated(self, web3: "Web3") -> None: + def test_eth_newFilter_deprecated(self, w3: "Web3") -> None: filter = web3.eth.filter({}) changes = web3.eth.get_filter_changes(filter.filter_id) @@ -1352,7 +1352,7 @@ def test_eth_newFilter_deprecated(self, web3: "Web3") -> None: result = web3.eth.uninstall_filter(filter.filter_id) assert result is True - def test_eth_newBlockFilter(self, web3: "Web3") -> None: + def test_eth_newBlockFilter(self, w3: "Web3") -> None: filter = web3.eth.filter('latest') assert is_string(filter.filter_id) @@ -1368,7 +1368,7 @@ def test_eth_newBlockFilter(self, web3: "Web3") -> None: result = web3.eth.uninstall_filter(filter.filter_id) assert result is True - def test_eth_newPendingTransactionFilter(self, web3: "Web3") -> None: + def test_eth_newPendingTransactionFilter(self, w3: "Web3") -> None: filter = web3.eth.filter('pending') assert is_string(filter.filter_id) @@ -1385,7 +1385,7 @@ def test_eth_newPendingTransactionFilter(self, web3: "Web3") -> None: assert result is True def test_eth_get_logs_without_logs( - self, web3: "Web3", block_with_txn_with_log: BlockData + self, w3: "Web3", block_with_txn_with_log: BlockData ) -> None: # Test with block range @@ -1426,7 +1426,7 @@ def test_eth_get_logs_without_logs( def test_eth_get_logs_with_logs( self, - web3: "Web3", + w3: "Web3", block_with_txn_with_log: BlockData, emitter_contract_address: ChecksumAddress, txn_hash_with_log: HexStr, @@ -1468,7 +1468,7 @@ def assert_contains_log(result: Sequence[LogReceipt]) -> None: def test_eth_get_logs_with_logs_topic_args( self, - web3: "Web3", + w3: "Web3", block_with_txn_with_log: BlockData, emitter_contract_address: ChecksumAddress, txn_hash_with_log: HexStr, @@ -1505,7 +1505,7 @@ def assert_contains_log(result: Sequence[LogReceipt]) -> None: result = web3.eth.get_logs(filter_params) assert_contains_log(result) - def test_eth_get_logs_with_logs_none_topic_args(self, web3: "Web3") -> None: + def test_eth_get_logs_with_logs_none_topic_args(self, w3: "Web3") -> None: # Test with None overflowing filter_params: FilterParams = { "fromBlock": BlockNumber(0), @@ -1516,7 +1516,7 @@ def test_eth_get_logs_with_logs_none_topic_args(self, web3: "Web3") -> None: assert len(result) == 0 def test_eth_call_old_contract_state( - self, web3: "Web3", math_contract: "Contract", unlocked_account: ChecksumAddress + self, w3: "Web3", math_contract: "Contract", unlocked_account: ChecksumAddress ) -> None: start_block = web3.eth.get_block('latest') block_num = start_block["number"] @@ -1544,7 +1544,7 @@ def test_eth_call_old_contract_state( if pending_call_result != 1: raise AssertionError("pending call result was %d instead of 1" % pending_call_result) - def test_eth_uninstallFilter_deprecated(self, web3: "Web3") -> None: + def test_eth_uninstallFilter_deprecated(self, w3: "Web3") -> None: filter = web3.eth.filter({}) assert is_string(filter.filter_id) @@ -1558,7 +1558,7 @@ def test_eth_uninstallFilter_deprecated(self, web3: "Web3") -> None: failure = web3.eth.uninstallFilter(filter.filter_id) assert failure is False - def test_eth_uninstall_filter(self, web3: "Web3") -> None: + def test_eth_uninstall_filter(self, w3: "Web3") -> None: filter = web3.eth.filter({}) assert is_string(filter.filter_id) @@ -1569,22 +1569,22 @@ def test_eth_uninstall_filter(self, web3: "Web3") -> None: assert failure is False def test_eth_getTransactionFromBlock_deprecation( - self, web3: "Web3", block_with_txn: BlockData + self, w3: "Web3", block_with_txn: BlockData ) -> None: with pytest.raises(DeprecationWarning): web3.eth.getTransactionFromBlock(block_with_txn['hash'], 0) - def test_eth_getCompilers_deprecation(self, web3: "Web3") -> None: + def test_eth_getCompilers_deprecation(self, w3: "Web3") -> None: with pytest.raises(DeprecationWarning): web3.eth.getCompilers() - def test_eth_submit_hashrate(self, web3: "Web3") -> None: + def test_eth_submit_hashrate(self, w3: "Web3") -> None: # node_id from EIP 1474: https://github.com/ethereum/EIPs/pull/1474/files node_id = HexStr('59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c') result = web3.eth.submit_hashrate(5000, node_id) assert result is True - def test_eth_submitHashrate_deprecated(self, web3: "Web3") -> None: + def test_eth_submitHashrate_deprecated(self, w3: "Web3") -> None: # node_id from EIP 1474: https://github.com/ethereum/EIPs/pull/1474/files node_id = HexStr('59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c') with pytest.warns(DeprecationWarning, @@ -1592,14 +1592,14 @@ def test_eth_submitHashrate_deprecated(self, web3: "Web3") -> None: result = web3.eth.submitHashrate(5000, node_id) assert result is True - def test_eth_submit_work(self, web3: "Web3") -> None: + def test_eth_submit_work(self, w3: "Web3") -> None: nonce = 1 pow_hash = HexStr('0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef') mix_digest = HexStr('0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000') result = web3.eth.submit_work(nonce, pow_hash, mix_digest) assert result is False - def test_eth_submitWork_deprecated(self, web3: "Web3") -> None: + def test_eth_submitWork_deprecated(self, w3: "Web3") -> None: nonce = 1 pow_hash = HexStr('0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef') mix_digest = HexStr('0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000') diff --git a/web3/_utils/module_testing/go_ethereum_admin_module.py b/web3/_utils/module_testing/go_ethereum_admin_module.py index bdfaba9600..b98a354b02 100644 --- a/web3/_utils/module_testing/go_ethereum_admin_module.py +++ b/web3/_utils/module_testing/go_ethereum_admin_module.py @@ -15,16 +15,16 @@ class GoEthereumAdminModuleTest: - def test_add_peer(self, web3: "Web3") -> None: + def test_add_peer(self, w3: "Web3") -> None: result = web3.geth.admin.add_peer( EnodeURI('enode://f1a6b0bdbf014355587c3018454d070ac57801f05d3b39fe85da574f002a32e929f683d72aa5a8318382e4d3c7a05c9b91687b0d997a39619fb8a6e7ad88e512@1.1.1.1:30303'),) # noqa: E501 assert result is True - def test_admin_datadir(self, web3: "Web3", datadir: str) -> None: + def test_admin_datadir(self, w3: "Web3", datadir: str) -> None: result = web3.geth.admin.datadir() assert result == datadir - def test_admin_node_info(self, web3: "Web3") -> None: + def test_admin_node_info(self, w3: "Web3") -> None: result = web3.geth.admin.node_info() expected = AttributeDict({ 'id': '', @@ -38,13 +38,13 @@ def test_admin_node_info(self, web3: "Web3") -> None: # Test that result gives at least the keys that are listed in `expected` assert not set(expected.keys()).difference(result.keys()) - def test_admin_peers(self, web3: "Web3") -> None: + def test_admin_peers(self, w3: "Web3") -> None: enode = web3.geth.admin.node_info()['enode'] web3.geth.admin.add_peer(enode) result = web3.geth.admin.peers() assert len(result) == 1 - def test_admin_start_stop_rpc(self, web3: "Web3") -> None: + def test_admin_start_stop_rpc(self, w3: "Web3") -> None: stop = web3.geth.admin.stop_rpc() assert stop is True @@ -59,7 +59,7 @@ def test_admin_start_stop_rpc(self, web3: "Web3") -> None: start = web3.geth.admin.startRPC() assert start is True - def test_admin_start_stop_ws(self, web3: "Web3") -> None: + def test_admin_start_stop_ws(self, w3: "Web3") -> None: stop = web3.geth.admin.stop_ws() assert stop is True @@ -77,14 +77,14 @@ def test_admin_start_stop_ws(self, web3: "Web3") -> None: # # Deprecated # - def test_admin_addPeer(self, web3: "Web3") -> None: + def test_admin_addPeer(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): result = web3.geth.admin.addPeer( 'enode://f1a6b0bdbf014355587c3018454d070ac57801f05d3b39fe85da574f002a32e929f683d72aa5a8318382e4d3c7a05c9b91687b0d997a39619fb8a6e7ad88e512@1.1.1.1:30303', # noqa: E501 ) assert result is True - def test_admin_nodeInfo(self, web3: "Web3") -> None: + def test_admin_nodeInfo(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): result = web3.geth.admin.nodeInfo() expected = AttributeDict({ diff --git a/web3/_utils/module_testing/net_module.py b/web3/_utils/module_testing/net_module.py index 2330489175..f8fa2f5999 100644 --- a/web3/_utils/module_testing/net_module.py +++ b/web3/_utils/module_testing/net_module.py @@ -14,28 +14,28 @@ class NetModuleTest: - def test_net_version(self, web3: "Web3") -> None: + def test_net_version(self, w3: "Web3") -> None: version = web3.net.version assert is_string(version) assert version.isdigit() - def test_net_listening(self, web3: "Web3") -> None: + def test_net_listening(self, w3: "Web3") -> None: listening = web3.net.listening assert is_boolean(listening) - def test_net_peer_count(self, web3: "Web3") -> None: + def test_net_peer_count(self, w3: "Web3") -> None: peer_count = web3.net.peer_count assert is_integer(peer_count) - def test_net_peerCount(self, web3: "Web3") -> None: + def test_net_peerCount(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): peer_count = web3.net.peerCount assert is_integer(peer_count) - def test_net_chainId_deprecation(self, web3: "Web3") -> None: + def test_net_chainId_deprecation(self, w3: "Web3") -> None: with pytest.raises(DeprecationWarning): web3.net.chainId diff --git a/web3/_utils/module_testing/parity_module.py b/web3/_utils/module_testing/parity_module.py index 3b401c1145..f8a76d1f9b 100644 --- a/web3/_utils/module_testing/parity_module.py +++ b/web3/_utils/module_testing/parity_module.py @@ -32,7 +32,7 @@ class ParityTraceModuleTest: def test_traceReplayTransaction_deprecated( - self, web3: "Web3", parity_fixture_data: Dict[str, str], + self, w3: "Web3", parity_fixture_data: Dict[str, str], ) -> None: with pytest.warns(DeprecationWarning, match='traceReplayTransaction is deprecated in favor of ' @@ -46,7 +46,7 @@ def test_traceReplayTransaction_deprecated( ) def test_trace_replay_transaction( - self, web3: "Web3", parity_fixture_data: Dict[str, str], + self, w3: "Web3", parity_fixture_data: Dict[str, str], ) -> None: trace = web3.parity.trace_replay_transaction(HexStr(parity_fixture_data['mined_txn_hash'])) @@ -57,7 +57,7 @@ def test_trace_replay_transaction( ) def test_trace_replay_block_transactions( - self, web3: "Web3", block_with_txn: BlockData, parity_fixture_data: Dict[str, str] + self, w3: "Web3", block_with_txn: BlockData, parity_fixture_data: Dict[str, str] ) -> None: trace = web3.parity.trace_replay_block_transactions(block_with_txn['number']) assert len(trace) > 0 @@ -65,7 +65,7 @@ def test_trace_replay_block_transactions( assert trace_0_action['from'] == add_0x_prefix(HexStr(parity_fixture_data['coinbase'])) def test_traceReplayBlockTransactions_deprecated( - self, web3: "Web3", block_with_txn: BlockData, parity_fixture_data: Dict[str, str] + self, w3: "Web3", block_with_txn: BlockData, parity_fixture_data: Dict[str, str] ) -> None: with pytest.warns(DeprecationWarning, match='traceReplayBlockTransactions is deprecated in favor of ' @@ -76,27 +76,27 @@ def test_traceReplayBlockTransactions_deprecated( assert trace_0_action['from'] == add_0x_prefix(HexStr(parity_fixture_data['coinbase'])) def test_trace_replay_block_without_transactions( - self, web3: "Web3", empty_block: BlockData + self, w3: "Web3", empty_block: BlockData ) -> None: trace = web3.parity.trace_replay_block_transactions(empty_block['number']) assert len(trace) == 0 - def test_trace_block(self, web3: "Web3", block_with_txn: BlockData) -> None: + def test_trace_block(self, w3: "Web3", block_with_txn: BlockData) -> None: trace = web3.parity.trace_block(block_with_txn['number']) assert trace[0]['blockNumber'] == block_with_txn['number'] - def test_traceBlock_deprecated(self, web3: "Web3", block_with_txn: BlockData) -> None: + def test_traceBlock_deprecated(self, w3: "Web3", block_with_txn: BlockData) -> None: with pytest.warns(DeprecationWarning, match='traceBlock is deprecated in favor of trace_block'): trace = web3.parity.traceBlock(block_with_txn['number']) assert trace[0]['blockNumber'] == block_with_txn['number'] - def test_trace_transaction(self, web3: "Web3", parity_fixture_data: Dict[str, str]) -> None: + def test_trace_transaction(self, w3: "Web3", parity_fixture_data: Dict[str, str]) -> None: trace = web3.parity.trace_transaction(HexStr(parity_fixture_data['mined_txn_hash'])) assert trace[0]['action']['from'] == add_0x_prefix(HexStr(parity_fixture_data['coinbase'])) def test_traceTransaction_deprecated( - self, web3: "Web3", parity_fixture_data: Dict[str, str] + self, w3: "Web3", parity_fixture_data: Dict[str, str] ) -> None: with pytest.warns(DeprecationWarning, match="traceTransaction is deprecated in favor of trace_transaction"): @@ -104,7 +104,7 @@ def test_traceTransaction_deprecated( assert trace[0]['action']['from'] == add_0x_prefix(HexStr(parity_fixture_data['coinbase'])) def test_traceCall_deprecated( - self, web3: "Web3", math_contract: "Contract", math_contract_address: ChecksumAddress + self, w3: "Web3", math_contract: "Contract", math_contract_address: ChecksumAddress ) -> None: coinbase = web3.eth.coinbase txn_params = math_contract._prepare_transaction( @@ -121,7 +121,7 @@ def test_traceCall_deprecated( assert result == 18 def test_trace_call( - self, web3: "Web3", math_contract: "Contract", math_contract_address: ChecksumAddress + self, w3: "Web3", math_contract: "Contract", math_contract_address: ChecksumAddress ) -> None: coinbase = web3.eth.coinbase txn_params = math_contract._prepare_transaction( @@ -136,7 +136,7 @@ def test_trace_call( assert result == 18 def test_trace_call_with_0_result( - self, web3: "Web3", math_contract: "Contract", math_contract_address: ChecksumAddress + self, w3: "Web3", math_contract: "Contract", math_contract_address: ChecksumAddress ) -> None: coinbase = web3.eth.coinbase txn_params = math_contract._prepare_transaction( @@ -152,7 +152,7 @@ def test_trace_call_with_0_result( def test_trace_raw_transaction( self, - web3: "Web3", + w3: "Web3", raw_transaction: HexStr, funded_account_for_raw_txn: ChecksumAddress, ) -> None: @@ -165,7 +165,7 @@ def test_trace_raw_transaction( def test_trace_raw_transaction_deprecated( self, - web3: "Web3", + w3: "Web3", raw_transaction: HexStr, funded_account_for_raw_txn: ChecksumAddress, ) -> None: @@ -182,7 +182,7 @@ def test_trace_raw_transaction_deprecated( def test_trace_filter( self, - web3: "Web3", + w3: "Web3", txn_filter_params: ParityFilterParams, parity_fixture_data: Dict[str, str], ) -> None: @@ -192,7 +192,7 @@ def test_trace_filter( def test_traceFilter_deprecated( self, - web3: "Web3", + w3: "Web3", txn_filter_params: ParityFilterParams, parity_fixture_data: Dict[str, str], ) -> None: @@ -205,37 +205,37 @@ def test_traceFilter_deprecated( class ParityModuleTest: - def test_add_reserved_peer(self, web3: "Web3") -> None: + def test_add_reserved_peer(self, w3: "Web3") -> None: peer_addr = EnodeURI('enode://f1a6b0bdbf014355587c3018454d070ac57801f05d3b39fe85da574f002a32e929f683d72aa5a8318382e4d3c7a05c9b91687b0d997a39619fb8a6e7ad88e512@1.1.1.1:30300') # noqa: E501 assert web3.parity.add_reserved_peer(peer_addr) - def test_addReservedPeer_deprecated(self, web3: "Web3") -> None: + def test_addReservedPeer_deprecated(self, w3: "Web3") -> None: peer_addr = EnodeURI('enode://f1a6b0bdbf014355587c3018454d070ac57801f05d3b39fe85da574f002a32e929f683d72aa5a8318382e4d3c7a05c9b91687b0d997a39619fb8a6e7ad88e512@1.1.1.1:30300') # noqa: E501 with pytest.warns(DeprecationWarning, match='addReservedPeer is deprecated in favor of add_reserved_peer'): assert web3.parity.addReservedPeer(peer_addr) def test_list_storage_keys_no_support( - self, web3: "Web3", emitter_contract_address: ChecksumAddress + self, w3: "Web3", emitter_contract_address: ChecksumAddress ) -> None: keys = web3.parity.list_storage_keys(emitter_contract_address, 10, None) assert keys == [] def test_list_storage_keys( - self, web3: "Web3", emitter_contract_address: ChecksumAddress + self, w3: "Web3", emitter_contract_address: ChecksumAddress ) -> None: keys = web3.parity.list_storage_keys(emitter_contract_address, 10, None) assert keys == [] def test_listStorageKeys_deprecated( - self, web3: "Web3", emitter_contract_address: ChecksumAddress + self, w3: "Web3", emitter_contract_address: ChecksumAddress ) -> None: with pytest.warns(DeprecationWarning, match='listStorageKeys is deprecated in favor of list_storage_keys'): keys = web3.parity.listStorageKeys(emitter_contract_address, 10, None) assert keys == [] - def test_mode(self, web3: "Web3") -> None: + def test_mode(self, w3: "Web3") -> None: assert web3.parity.mode() is not None @@ -250,19 +250,19 @@ class ParitySetModuleTest: ('passive'), ] ) - def test_set_mode(self, web3: "Web3", mode: ParityMode) -> None: + def test_set_mode(self, w3: "Web3", mode: ParityMode) -> None: assert web3.parity.set_mode(mode) is True - def test_set_mode_deprecated(self, web3: "Web3", mode: ParityMode) -> None: + def test_set_mode_deprecated(self, w3: "Web3", mode: ParityMode) -> None: with pytest.warns(DeprecationWarning, match="setMode is deprecated in favor of set_mode"): assert web3.parity.setMode(mode) is True - def test_set_mode_with_bad_string(self, web3: "Web3") -> None: + def test_set_mode_with_bad_string(self, w3: "Web3") -> None: with pytest.raises(InvalidParityMode, match="Couldn't parse parameters: mode"): # type ignored b/c it's an invalid literal ParityMode web3.parity.set_mode('not a mode') # type: ignore - def test_set_mode_with_no_argument(self, web3: "Web3") -> None: + def test_set_mode_with_no_argument(self, w3: "Web3") -> None: with pytest.raises( InvalidParityMode, match='Invalid params: invalid length 0, expected a tuple of size 1.' diff --git a/web3/_utils/module_testing/personal_module.py b/web3/_utils/module_testing/personal_module.py index 20f3793dfc..b5213664a6 100644 --- a/web3/_utils/module_testing/personal_module.py +++ b/web3/_utils/module_testing/personal_module.py @@ -38,16 +38,16 @@ class GoEthereumPersonalModuleTest: - def test_personal_import_raw_key(self, web3: "Web3") -> None: + def test_personal_import_raw_key(self, w3: "Web3") -> None: actual = web3.geth.personal.import_raw_key(PRIVATE_KEY_HEX, PASSWORD) assert actual == ADDRESS - def test_personal_importRawKey_deprecated(self, web3: "Web3") -> None: + def test_personal_importRawKey_deprecated(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): actual = web3.geth.personal.importRawKey(SECOND_PRIVATE_KEY_HEX, PASSWORD) assert actual == SECOND_ADDRESS - def test_personal_list_accounts(self, web3: "Web3") -> None: + def test_personal_list_accounts(self, w3: "Web3") -> None: accounts = web3.geth.personal.list_accounts() assert is_list_like(accounts) assert len(accounts) > 0 @@ -57,7 +57,7 @@ def test_personal_list_accounts(self, web3: "Web3") -> None: in accounts )) - def test_personal_listAccounts_deprecated(self, web3: "Web3") -> None: + def test_personal_listAccounts_deprecated(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): accounts = web3.geth.personal.listAccounts() assert is_list_like(accounts) @@ -68,7 +68,7 @@ def test_personal_listAccounts_deprecated(self, web3: "Web3") -> None: in accounts )) - def test_personal_list_wallets(self, web3: "Web3") -> None: + def test_personal_list_wallets(self, w3: "Web3") -> None: wallets = web3.geth.personal.list_wallets() assert is_list_like(wallets) assert len(wallets) > 0 @@ -78,13 +78,13 @@ def test_personal_list_wallets(self, web3: "Web3") -> None: assert is_string(wallets[0]['url']) def test_personal_lock_account( - self, web3: "Web3", unlockable_account_dual_type: ChecksumAddress + self, w3: "Web3", unlockable_account_dual_type: ChecksumAddress ) -> None: # TODO: how do we test this better? web3.geth.personal.lock_account(unlockable_account_dual_type) def test_personal_lockAccount_deprecated( - self, web3: "Web3", unlockable_account_dual_type: ChecksumAddress + self, w3: "Web3", unlockable_account_dual_type: ChecksumAddress ) -> None: with pytest.warns(DeprecationWarning): # TODO: how do we test this better? @@ -92,7 +92,7 @@ def test_personal_lockAccount_deprecated( def test_personal_unlock_account_success( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -104,7 +104,7 @@ def test_personal_unlock_account_success( def test_personal_unlockAccount_success_deprecated( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -116,30 +116,30 @@ def test_personal_unlockAccount_success_deprecated( assert result is True def test_personal_unlock_account_failure( - self, web3: "Web3", unlockable_account_dual_type: ChecksumAddress + self, w3: "Web3", unlockable_account_dual_type: ChecksumAddress ) -> None: with pytest.raises(ValueError): web3.geth.personal.unlock_account(unlockable_account_dual_type, 'bad-password') def test_personal_unlockAccount_failure_deprecated( - self, web3: "Web3", unlockable_account_dual_type: ChecksumAddress + self, w3: "Web3", unlockable_account_dual_type: ChecksumAddress ) -> None: with pytest.warns(DeprecationWarning): with pytest.raises(ValueError): web3.geth.personal.unlockAccount(unlockable_account_dual_type, 'bad-password') - def test_personal_new_account(self, web3: "Web3") -> None: + def test_personal_new_account(self, w3: "Web3") -> None: new_account = web3.geth.personal.new_account(PASSWORD) assert is_checksum_address(new_account) - def test_personal_newAccount_deprecated(self, web3: "Web3") -> None: + def test_personal_newAccount_deprecated(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): new_account = web3.geth.personal.newAccount(PASSWORD) assert is_checksum_address(new_account) def test_personal_send_transaction( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -163,7 +163,7 @@ def test_personal_send_transaction( def test_personal_sendTransaction_deprecated( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -189,7 +189,7 @@ def test_personal_sendTransaction_deprecated( def test_personal_sign_and_ecrecover( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -204,7 +204,7 @@ def test_personal_sign_and_ecrecover( def test_personal_sign_and_ecrecover_deprecated( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -223,7 +223,7 @@ def test_personal_sign_and_ecrecover_deprecated( ) def test_personal_sign_typed_data( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -283,7 +283,7 @@ def test_personal_sign_typed_data( @pytest.mark.xfail(reason="personal_signTypedData JSON RPC call has not been released in geth") def test_personal_sign_typed_data_deprecated( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -344,7 +344,7 @@ def test_personal_sign_typed_data_deprecated( class ParityPersonalModuleTest(): - def test_personal_list_accounts(self, web3: "Web3") -> None: + def test_personal_list_accounts(self, w3: "Web3") -> None: accounts = web3.parity.personal.list_accounts() assert is_list_like(accounts) assert len(accounts) > 0 @@ -354,7 +354,7 @@ def test_personal_list_accounts(self, web3: "Web3") -> None: in accounts )) - def test_personal_listAccounts_deprecated(self, web3: "Web3") -> None: + def test_personal_listAccounts_deprecated(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): accounts = web3.parity.personal.listAccounts() assert is_list_like(accounts) @@ -367,7 +367,7 @@ def test_personal_listAccounts_deprecated(self, web3: "Web3") -> None: def test_personal_unlock_account_success( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -380,7 +380,7 @@ def test_personal_unlock_account_success( def test_personal_unlockAccount_success_deprecated( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -395,7 +395,7 @@ def test_personal_unlockAccount_success_deprecated( # Seems to be an issue with Parity since this should return False def test_personal_unlock_account_failure( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, ) -> None: result = web3.parity.personal.unlock_account( @@ -408,7 +408,7 @@ def test_personal_unlock_account_failure( # Seems to be an issue with Parity since this should return False def test_personal_unlockAccount_failure_deprecated( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, ) -> None: with pytest.warns(DeprecationWarning): @@ -419,44 +419,44 @@ def test_personal_unlockAccount_failure_deprecated( ) assert result is True - def test_personal_new_account(self, web3: "Web3") -> None: + def test_personal_new_account(self, w3: "Web3") -> None: new_account = web3.parity.personal.new_account(PASSWORD) assert is_checksum_address(new_account) - def test_personal_newAccount_deprecated(self, web3: "Web3") -> None: + def test_personal_newAccount_deprecated(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): new_account = web3.parity.personal.newAccount(PASSWORD) assert is_checksum_address(new_account) @pytest.mark.xfail(reason='this non-standard json-rpc method is not implemented on parity') def test_personal_lock_account( - self, web3: "Web3", unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: # method undefined in superclass super().test_personal_lock_account(web3, unlocked_account) # type: ignore @pytest.mark.xfail(reason='this non-standard json-rpc method is not implemented on parity') def test_personal_lockAccount_deprecated( - self, web3: "Web3", unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: with pytest.warns(DeprecationWarning): # method undefined in superclass super().test_personal_lockAccount(web3, unlocked_account) # type: ignore @pytest.mark.xfail(reason='this non-standard json-rpc method is not implemented on parity') - def test_personal_import_raw_key(self, web3: "Web3") -> None: + def test_personal_import_raw_key(self, w3: "Web3") -> None: # method undefined in superclass super().test_personal_import_raw_key(web3) # type: ignore @pytest.mark.xfail(reason='this non-standard json-rpc method is not implemented on parity') - def test_personal_importRawKey_deprecated(self, web3: "Web3") -> None: + def test_personal_importRawKey_deprecated(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): # method undefined in superclass super().test_personal_importRawKey_deprecated(web3) # type: ignore def test_personal_send_transaction( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -480,7 +480,7 @@ def test_personal_send_transaction( def test_personal_sendTransaction_deprecated( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -505,7 +505,7 @@ def test_personal_sendTransaction_deprecated( def test_personal_sign_and_ecrecover( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -520,7 +520,7 @@ def test_personal_sign_and_ecrecover( def test_personal_sign_and_ecrecover_deprecated( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -536,7 +536,7 @@ def test_personal_sign_and_ecrecover_deprecated( def test_personal_sign_typed_data( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -595,7 +595,7 @@ def test_personal_sign_typed_data( def test_personal_sign_typed_data_deprecated( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -655,7 +655,7 @@ def test_personal_sign_typed_data_deprecated( def test_invalid_personal_sign_typed_data( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: @@ -708,7 +708,7 @@ def test_invalid_personal_sign_typed_data( def test_invalid_personal_sign_typed_data_deprecated( self, - web3: "Web3", + w3: "Web3", unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: diff --git a/web3/_utils/module_testing/version_module.py b/web3/_utils/module_testing/version_module.py index 69b7c907ed..820689334e 100644 --- a/web3/_utils/module_testing/version_module.py +++ b/web3/_utils/module_testing/version_module.py @@ -12,14 +12,14 @@ class VersionModuleTest: - def test_eth_protocol_version(self, web3: "Web3") -> None: + def test_eth_protocol_version(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): protocol_version = web3.eth.protocol_version assert is_string(protocol_version) assert protocol_version.isdigit() - def test_eth_protocolVersion(self, web3: "Web3") -> None: + def test_eth_protocolVersion(self, w3: "Web3") -> None: with pytest.warns(DeprecationWarning): protocol_version = web3.eth.protocolVersion diff --git a/web3/_utils/module_testing/web3_module.py b/web3/_utils/module_testing/web3_module.py index fd2bf6df89..066d57053d 100644 --- a/web3/_utils/module_testing/web3_module.py +++ b/web3/_utils/module_testing/web3_module.py @@ -25,7 +25,7 @@ class Web3ModuleTest: - def test_w3_clientVersion(self, web3: Web3) -> None: + def test_w3_clientVersion(self, w3: Web3) -> None: client_version = web3.clientVersion self._check_w3_clientVersion(client_version) @@ -176,7 +176,7 @@ def _check_w3_clientVersion(self, client_version: str) -> NoReturn: ), ) def test_solidityKeccak( - self, web3: "Web3", types: Sequence[TypeStr], values: Sequence[Any], expected: HexBytes + self, w3: "Web3", types: Sequence[TypeStr], values: Sequence[Any], expected: HexBytes ) -> None: if isinstance(expected, type) and issubclass(expected, Exception): with pytest.raises(expected): @@ -202,7 +202,7 @@ def test_solidityKeccak( ), ) def test_solidityKeccak_ens( - self, web3: "Web3", types: Sequence[TypeStr], values: Sequence[str], expected: HexBytes + self, w3: "Web3", types: Sequence[TypeStr], values: Sequence[str], expected: HexBytes ) -> None: with ens_addresses(web3, { 'one.eth': ChecksumAddress( @@ -229,10 +229,10 @@ def test_solidityKeccak_ens( ) ) def test_solidityKeccak_same_number_of_types_and_values( - self, web3: "Web3", types: Sequence[TypeStr], values: Sequence[Any] + self, w3: "Web3", types: Sequence[TypeStr], values: Sequence[Any] ) -> None: with pytest.raises(ValueError): web3.solidityKeccak(types, values) - def test_is_connected(self, web3: "Web3") -> None: + def test_is_connected(self, w3: "Web3") -> None: assert web3.isConnected() diff --git a/web3/_utils/transactions.py b/web3/_utils/transactions.py index e484960ffa..f4595aab5b 100644 --- a/web3/_utils/transactions.py +++ b/web3/_utils/transactions.py @@ -62,7 +62,7 @@ @curry -def fill_nonce(web3: "Web3", transaction: TxParams) -> TxParams: +def fill_nonce(w3: "Web3", transaction: TxParams) -> TxParams: if 'from' in transaction and 'nonce' not in transaction: return assoc( transaction, @@ -75,7 +75,7 @@ def fill_nonce(web3: "Web3", transaction: TxParams) -> TxParams: @curry -def fill_transaction_defaults(web3: "Web3", transaction: TxParams) -> TxParams: +def fill_transaction_defaults(w3: "Web3", transaction: TxParams) -> TxParams: """ if web3 is None, fill as much as possible while offline """ @@ -94,7 +94,7 @@ def fill_transaction_defaults(web3: "Web3", transaction: TxParams) -> TxParams: def wait_for_transaction_receipt( - web3: "Web3", txn_hash: _Hash32, timeout: float, poll_latency: float + w3: "Web3", txn_hash: _Hash32, timeout: float, poll_latency: float ) -> TxReceipt: with Timeout(timeout) as _timeout: while True: @@ -112,7 +112,7 @@ def wait_for_transaction_receipt( return txn_receipt -def get_block_gas_limit(web3: "Web3", block_identifier: Optional[BlockIdentifier] = None) -> Wei: +def get_block_gas_limit(w3: "Web3", block_identifier: Optional[BlockIdentifier] = None) -> Wei: if block_identifier is None: block_identifier = web3.eth.block_number block = web3.eth.get_block(block_identifier) @@ -120,7 +120,7 @@ def get_block_gas_limit(web3: "Web3", block_identifier: Optional[BlockIdentifier def get_buffered_gas_estimate( - web3: "Web3", transaction: TxParams, gas_buffer: Wei = Wei(100000) + w3: "Web3", transaction: TxParams, gas_buffer: Wei = Wei(100000) ) -> Wei: gas_estimate_transaction = cast(TxParams, dict(**transaction)) @@ -138,7 +138,7 @@ def get_buffered_gas_estimate( return Wei(min(gas_limit, gas_estimate + gas_buffer)) -def get_required_transaction(web3: "Web3", transaction_hash: _Hash32) -> TxData: +def get_required_transaction(w3: "Web3", transaction_hash: _Hash32) -> TxData: current_transaction = web3.eth.get_transaction(transaction_hash) if not current_transaction: raise ValueError('Supplied transaction with hash {} does not exist' @@ -180,7 +180,7 @@ def assert_valid_transaction_params(transaction_params: TxParams) -> None: def prepare_replacement_transaction( - web3: "Web3", + w3: "Web3", current_transaction: TxData, new_transaction: TxParams, gas_multiplier: float = 1.125 @@ -209,7 +209,7 @@ def prepare_replacement_transaction( def replace_transaction( - web3: "Web3", current_transaction: TxData, new_transaction: TxParams + w3: "Web3", current_transaction: TxData, new_transaction: TxParams ) -> HexBytes: new_transaction = prepare_replacement_transaction( web3, current_transaction, new_transaction diff --git a/web3/contract.py b/web3/contract.py index 1212288a42..fcc64cfefe 100644 --- a/web3/contract.py +++ b/web3/contract.py @@ -154,7 +154,7 @@ class ContractFunctions: """Class containing contract function objects """ - def __init__(self, abi: ABI, web3: 'Web3', address: Optional[ChecksumAddress] = None) -> None: + def __init__(self, abi: ABI, w3: 'Web3', address: Optional[ChecksumAddress] = None) -> None: self.abi = abi self.w3 = web3 self.address = address @@ -228,7 +228,7 @@ class ContractEvents: """ - def __init__(self, abi: ABI, web3: 'Web3', address: Optional[ChecksumAddress] = None) -> None: + def __init__(self, abi: ABI, w3: 'Web3', address: Optional[ChecksumAddress] = None) -> None: if abi: self.abi = abi self._events = filter_by_type('event', self.abi) @@ -293,7 +293,7 @@ class Contract: """ # set during class construction - web3: 'Web3' = None + w3: 'Web3' = None # instance level properties address: ChecksumAddress = None @@ -346,7 +346,7 @@ def __init__(self, address: Optional[ChecksumAddress] = None) -> None: self.receive = Contract.get_receive_function(self.abi, self.w3, self.address) @classmethod - def factory(cls, web3: 'Web3', class_name: Optional[str] = None, **kwargs: Any) -> 'Contract': + def factory(cls, w3: 'Web3', class_name: Optional[str] = None, **kwargs: Any) -> 'Contract': kwargs['web3'] = web3 @@ -530,7 +530,7 @@ def _find_matching_event_abi( @staticmethod def get_fallback_function( - abi: ABI, web3: 'Web3', address: Optional[ChecksumAddress] = None + abi: ABI, w3: 'Web3', address: Optional[ChecksumAddress] = None ) -> 'ContractFunction': if abi and fallback_func_abi_exists(abi): return ContractFunction.factory( @@ -544,7 +544,7 @@ def get_fallback_function( @staticmethod def get_receive_function( - abi: ABI, web3: 'Web3', address: Optional[ChecksumAddress] = None + abi: ABI, w3: 'Web3', address: Optional[ChecksumAddress] = None ) -> 'ContractFunction': if abi and receive_func_abi_exists(abi): return ContractFunction.factory( @@ -595,7 +595,7 @@ class ContractConstructor: Class for contract constructor API. """ def __init__( - self, web3: 'Web3', abi: ABI, bytecode: HexStr, *args: Any, **kwargs: Any + self, w3: 'Web3', abi: ABI, bytecode: HexStr, *args: Any, **kwargs: Any ) -> None: self.w3 = web3 self.abi = abi @@ -849,7 +849,7 @@ class ContractFunction: """ address: ChecksumAddress = None function_identifier: FunctionIdentifier = None - web3: 'Web3' = None + w3: 'Web3' = None contract_abi: ABI = None abi: ABIFunction = None transaction: TxParams = None @@ -1110,7 +1110,7 @@ class ContractEvent: """ address: ChecksumAddress = None event_name: str = None - web3: 'Web3' = None + w3: 'Web3' = None contract_abi: ABI = None abi: ABIEvent = None @@ -1368,7 +1368,7 @@ class ContractCaller: """ def __init__(self, abi: ABI, - web3: 'Web3', + w3: 'Web3', address: ChecksumAddress, transaction: Optional[TxParams] = None, block_identifier: BlockIdentifier = 'latest') -> None: @@ -1468,7 +1468,7 @@ def check_for_forbidden_api_filter_arguments( def call_contract_function( - web3: 'Web3', + w3: 'Web3', address: ChecksumAddress, normalizers: Tuple[Callable[..., Any], ...], function_identifier: FunctionIdentifier, @@ -1539,7 +1539,7 @@ def call_contract_function( return normalized_data -def parse_block_identifier(web3: 'Web3', block_identifier: BlockIdentifier) -> BlockIdentifier: +def parse_block_identifier(w3: 'Web3', block_identifier: BlockIdentifier) -> BlockIdentifier: if isinstance(block_identifier, int): return parse_block_identifier_int(web3, block_identifier) elif block_identifier in ['latest', 'earliest', 'pending']: @@ -1550,7 +1550,7 @@ def parse_block_identifier(web3: 'Web3', block_identifier: BlockIdentifier) -> B raise BlockNumberOutofRange -def parse_block_identifier_int(web3: 'Web3', block_identifier_int: int) -> BlockNumber: +def parse_block_identifier_int(w3: 'Web3', block_identifier_int: int) -> BlockNumber: if block_identifier_int >= 0: block_num = block_identifier_int else: @@ -1563,7 +1563,7 @@ def parse_block_identifier_int(web3: 'Web3', block_identifier_int: int) -> Block def transact_with_contract_function( address: ChecksumAddress, - web3: 'Web3', + w3: 'Web3', function_name: Optional[FunctionIdentifier] = None, transaction: Optional[TxParams] = None, contract_abi: Optional[ABI] = None, @@ -1591,7 +1591,7 @@ def transact_with_contract_function( def estimate_gas_for_function( address: ChecksumAddress, - web3: 'Web3', + w3: 'Web3', fn_identifier: Optional[FunctionIdentifier] = None, transaction: Optional[TxParams] = None, contract_abi: Optional[ABI] = None, @@ -1620,7 +1620,7 @@ def estimate_gas_for_function( def build_transaction_for_function( address: ChecksumAddress, - web3: 'Web3', + w3: 'Web3', function_name: Optional[FunctionIdentifier] = None, transaction: Optional[TxParams] = None, contract_abi: Optional[ABI] = None, @@ -1649,7 +1649,7 @@ def build_transaction_for_function( def find_functions_by_identifier( - contract_abi: ABI, web3: 'Web3', address: ChecksumAddress, callable_check: Callable[..., Any] + contract_abi: ABI, w3: 'Web3', address: ChecksumAddress, callable_check: Callable[..., Any] ) -> List[ContractFunction]: fns_abi = filter_by_type('function', contract_abi) return [ diff --git a/web3/gas_strategies/rpc.py b/web3/gas_strategies/rpc.py index 272c90ebe8..7b7818b2e4 100644 --- a/web3/gas_strategies/rpc.py +++ b/web3/gas_strategies/rpc.py @@ -12,7 +12,7 @@ ) -def rpc_gas_price_strategy(web3: Web3, +def rpc_gas_price_strategy(w3: Web3, transaction_params: Optional[TxParams] = None) -> Wei: """ A simple gas price strategy deriving it's value from the eth_gasPrice JSON-RPC call. diff --git a/web3/gas_strategies/time_based.py b/web3/gas_strategies/time_based.py index 4005435d0b..21ad83c13b 100644 --- a/web3/gas_strategies/time_based.py +++ b/web3/gas_strategies/time_based.py @@ -201,7 +201,7 @@ def construct_time_based_gas_price_strategy( and 100 means 100%. """ - def time_based_gas_price_strategy(web3: Web3, transaction_params: TxParams) -> Wei: + def time_based_gas_price_strategy(w3: Web3, transaction_params: TxParams) -> Wei: if weighted: avg_block_time = _get_weighted_avg_block_time(web3, sample_size=sample_size) else: diff --git a/web3/manager.py b/web3/manager.py index fce4cef45d..f5c628acd3 100644 --- a/web3/manager.py +++ b/web3/manager.py @@ -73,7 +73,7 @@ class RequestManager: def __init__( self, - web3: 'Web3', + w3: 'Web3', provider: Optional[BaseProvider] = None, middlewares: Optional[Sequence[Tuple[Middleware, str]]] = None ) -> None: @@ -90,7 +90,7 @@ def __init__( else: self.provider = provider - web3: 'Web3' = None + w3: 'Web3' = None _provider = None @property @@ -103,7 +103,7 @@ def provider(self, provider: BaseProvider) -> None: @staticmethod def default_middlewares( - web3: 'Web3' + w3: 'Web3' ) -> List[Tuple[Middleware, str]]: """ List the default middlewares for the request manager. diff --git a/web3/method.py b/web3/method.py index 087902e974..9675817a4a 100644 --- a/web3/method.py +++ b/web3/method.py @@ -120,7 +120,7 @@ def __init__( result_formatters: Optional[Callable[..., TReturn]] = None, error_formatters: Optional[Callable[..., TReturn]] = None, method_choice_depends_on_args: Optional[Callable[..., RPCEndpoint]] = None, - web3: Optional["Web3"] = None): + w3: Optional["Web3"] = None): self.json_rpc_method = json_rpc_method self.mungers = mungers or [default_munger] diff --git a/web3/middleware/__init__.py b/web3/middleware/__init__.py index 2e06da2d67..d860142de0 100644 --- a/web3/middleware/__init__.py +++ b/web3/middleware/__init__.py @@ -76,7 +76,7 @@ def combine_middlewares( middlewares: Sequence[Middleware], - web3: 'Web3', + w3: 'Web3', provider_request_fn: Callable[[RPCEndpoint, Any], Any] ) -> Callable[..., RPCResponse]: """ diff --git a/web3/middleware/attrdict.py b/web3/middleware/attrdict.py index 14f33e1bf1..16643ae4ac 100644 --- a/web3/middleware/attrdict.py +++ b/web3/middleware/attrdict.py @@ -24,7 +24,7 @@ def attrdict_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: """ Converts any result which is a dictionary into an a diff --git a/web3/middleware/cache.py b/web3/middleware/cache.py index f68f626b4c..9354050097 100644 --- a/web3/middleware/cache.py +++ b/web3/middleware/cache.py @@ -111,7 +111,7 @@ def construct_simple_cache_middleware( cached. """ def simple_cache_middleware( - make_request: Callable[[RPCEndpoint, Any], RPCResponse], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], RPCResponse], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: cache = cache_class() lock = threading.Lock() @@ -215,7 +215,7 @@ def construct_time_based_cache_middleware( cached. """ def time_based_cache_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: cache = cache_class() lock = threading.Lock() @@ -355,7 +355,7 @@ def construct_latest_block_based_cache_middleware( block time. """ def latest_block_based_cache_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: cache = cache_class() block_info: BlockInfoCache = {} diff --git a/web3/middleware/exception_handling.py b/web3/middleware/exception_handling.py index a74cc19694..c2781456a9 100644 --- a/web3/middleware/exception_handling.py +++ b/web3/middleware/exception_handling.py @@ -30,7 +30,7 @@ def construct_exception_handler_middleware( method_handlers = {} def exception_handler_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: if method in method_handlers: diff --git a/web3/middleware/exception_retry_request.py b/web3/middleware/exception_retry_request.py index 887b45c68d..4352026d8a 100644 --- a/web3/middleware/exception_retry_request.py +++ b/web3/middleware/exception_retry_request.py @@ -89,7 +89,7 @@ def check_if_retry_on_failure(method: RPCEndpoint) -> bool: def exception_retry_middleware( make_request: Callable[[RPCEndpoint, Any], RPCResponse], - web3: "Web3", + w3: "Web3", errors: Collection[Type[BaseException]], retries: int = 5, ) -> Callable[[RPCEndpoint, Any], RPCResponse]: @@ -115,7 +115,7 @@ def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: def http_retry_request_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], Any]: return exception_retry_middleware( make_request, diff --git a/web3/middleware/fixture.py b/web3/middleware/fixture.py index b54d0902a8..fa73aa3f1c 100644 --- a/web3/middleware/fixture.py +++ b/web3/middleware/fixture.py @@ -21,7 +21,7 @@ def construct_fixture_middleware(fixtures: Dict[RPCEndpoint, Any]) -> Middleware which is found in the provided fixtures. """ def fixture_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: if method in fixtures: @@ -43,7 +43,7 @@ def construct_result_generator_middleware( functions with the signature `fn(method, params)`. """ def result_generator_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: if method in result_generators: @@ -65,7 +65,7 @@ def construct_error_generator_middleware( functions with the signature `fn(method, params)`. """ def error_generator_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: if method in error_generators: diff --git a/web3/middleware/gas_price_strategy.py b/web3/middleware/gas_price_strategy.py index 6593356128..1b5b66f9fd 100644 --- a/web3/middleware/gas_price_strategy.py +++ b/web3/middleware/gas_price_strategy.py @@ -18,7 +18,7 @@ def gas_price_strategy_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: """ Includes a gas price using the gas price strategy diff --git a/web3/middleware/normalize_errors.py b/web3/middleware/normalize_errors.py index fce1032446..8ed82b8bcd 100644 --- a/web3/middleware/normalize_errors.py +++ b/web3/middleware/normalize_errors.py @@ -19,7 +19,7 @@ def normalize_errors_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: result = make_request(method, params) diff --git a/web3/middleware/simulate_unmined_transaction.py b/web3/middleware/simulate_unmined_transaction.py index e36300c9ff..9e74b20c06 100644 --- a/web3/middleware/simulate_unmined_transaction.py +++ b/web3/middleware/simulate_unmined_transaction.py @@ -22,7 +22,7 @@ def unmined_receipt_simulator_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: Web3 + make_request: Callable[[RPCEndpoint, Any], Any], w3: Web3 ) -> Callable[[RPCEndpoint, Any], RPCResponse]: receipt_counters: DefaultDict[Hash32, TxReceipt] = collections.defaultdict( # type: ignore # noqa: F821, E501 itertools.count diff --git a/web3/middleware/stalecheck.py b/web3/middleware/stalecheck.py index 86711ee67c..4148cb2ece 100644 --- a/web3/middleware/stalecheck.py +++ b/web3/middleware/stalecheck.py @@ -47,7 +47,7 @@ def make_stalecheck_middleware( raise ValueError("You must set a positive allowable_delay in seconds for this middleware") def stalecheck_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: cache: Dict[str, BlockData] = {'latest': None} diff --git a/web3/middleware/validation.py b/web3/middleware/validation.py index 4132172133..18267acdb6 100644 --- a/web3/middleware/validation.py +++ b/web3/middleware/validation.py @@ -50,7 +50,7 @@ @curry -def validate_chain_id(web3: "Web3", chain_id: int) -> int: +def validate_chain_id(w3: "Web3", chain_id: int) -> int: if to_integer_if_hex(chain_id) == web3.eth.chain_id: return chain_id else: @@ -84,7 +84,7 @@ def transaction_normalizer(transaction: TxParams) -> TxParams: return dissoc(transaction, 'chainId') -def transaction_param_validator(web3: "Web3") -> Callable[..., Any]: +def transaction_param_validator(w3: "Web3") -> Callable[..., Any]: transactions_params_validators = { "chainId": apply_formatter_if( # Bypass `validate_chain_id` if chainId can't be determined @@ -110,7 +110,7 @@ def transaction_param_validator(web3: "Web3") -> Callable[..., Any]: @curry -def chain_id_validator(web3: "Web3") -> Callable[..., Any]: +def chain_id_validator(w3: "Web3") -> Callable[..., Any]: return compose( apply_formatter_at_index(transaction_normalizer, 0), transaction_param_validator(web3) diff --git a/web3/module.py b/web3/module.py index 8d6c6b9817..f8de45eacc 100644 --- a/web3/module.py +++ b/web3/module.py @@ -78,7 +78,7 @@ async def caller(*args: Any, **kwargs: Any) -> RPCResponse: class Module: is_async = False - def __init__(self, web3: "Web3") -> None: + def __init__(self, w3: "Web3") -> None: if self.is_async: self.retrieve_caller_fn = retrieve_async_method_call_fn(web3, self) else: diff --git a/web3/providers/base.py b/web3/providers/base.py index 4f426934d5..cd5adef47e 100644 --- a/web3/providers/base.py +++ b/web3/providers/base.py @@ -47,7 +47,7 @@ def middlewares( self._middlewares = tuple(values) # type: ignore def request_func( - self, web3: "Web3", outer_middlewares: MiddlewareOnion + self, w3: "Web3", outer_middlewares: MiddlewareOnion ) -> Callable[..., RPCResponse]: """ @param outer_middlewares is an iterable of middlewares, ordered by first to execute @@ -65,7 +65,7 @@ def request_func( return self._request_func_cache[-1] def _generate_request_func( - self, web3: "Web3", middlewares: Sequence[Middleware] + self, w3: "Web3", middlewares: Sequence[Middleware] ) -> Callable[..., RPCResponse]: return combine_middlewares( middlewares=middlewares, diff --git a/web3/providers/eth_tester/middleware.py b/web3/providers/eth_tester/middleware.py index ab7950d96b..46ed988aa2 100644 --- a/web3/providers/eth_tester/middleware.py +++ b/web3/providers/eth_tester/middleware.py @@ -283,7 +283,7 @@ def is_hexstr(value: Any) -> bool: ) -def guess_from(web3: "Web3", transaction: TxParams) -> ChecksumAddress: +def guess_from(w3: "Web3", transaction: TxParams) -> ChecksumAddress: coinbase = web3.eth.coinbase if coinbase is not None: return coinbase @@ -297,13 +297,13 @@ def guess_from(web3: "Web3", transaction: TxParams) -> ChecksumAddress: return None -def guess_gas(web3: "Web3", transaction: TxParams) -> Wei: +def guess_gas(w3: "Web3", transaction: TxParams) -> Wei: return Wei(web3.eth.estimate_gas(transaction) * 2) @curry def fill_default( - field: str, guess_func: Callable[..., Any], web3: "Web3", transaction: TxParams + field: str, guess_func: Callable[..., Any], w3: "Web3", transaction: TxParams ) -> TxParams: # type ignored b/c TxParams keys must be string literal types if field in transaction and transaction[field] is not None: # type: ignore @@ -314,7 +314,7 @@ def fill_default( def default_transaction_fields_middleware( - make_request: Callable[[RPCEndpoint, Any], Any], web3: "Web3" + make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3" ) -> Callable[[RPCEndpoint, Any], RPCResponse]: fill_default_from = fill_default('from', guess_from, web3) fill_default_gas = fill_default('gas', guess_gas, web3) From d02f23544f9aa74bbc56fadb92c1e70b218e1df8 Mon Sep 17 00:00:00 2001 From: Harmouch101 Date: Fri, 30 Apr 2021 23:20:50 +0300 Subject: [PATCH 6/6] Audit .rst & .py files and convert all Web3 instance variables to use w3 name. Signed-off-by: Harmouch101 --- docs/examples.rst | 10 +- docs/web3.main.rst | 2 +- ens/main.py | 12 +-- ens/utils.py | 6 +- tests/core/pm-module/test_ens_integration.py | 2 +- tests/core/providers/test_auto_provider.py | 18 ++-- tests/core/providers/test_ipc_provider.py | 2 +- tests/core/web3-module/test_api.py | 2 +- tests/core/web3-module/test_clientVersion.py | 2 +- tests/ens/test_utils.py | 4 +- tests/ethpm/test_package.py | 6 +- tests/integration/go_ethereum/common.py | 2 +- .../go_ethereum/test_goethereum_http.py | 2 +- .../go_ethereum/test_goethereum_ipc.py | 2 +- .../go_ethereum/test_goethereum_ws.py | 2 +- tests/integration/parity/common.py | 2 +- tests/integration/parity/test_parity_http.py | 2 +- tests/integration/parity/test_parity_ipc.py | 2 +- tests/integration/parity/test_parity_ws.py | 2 +- tests/integration/test_ethereum_tester.py | 4 +- web3/_utils/module_testing/web3_module.py | 6 +- web3/contract.py | 102 +++++++++--------- web3/eth.py | 16 +-- web3/manager.py | 4 +- web3/middleware/formatting.py | 6 +- web3/middleware/validation.py | 6 +- web3/parity.py | 4 +- web3/pm.py | 16 +-- web3/testing.py | 10 +- 29 files changed, 128 insertions(+), 128 deletions(-) diff --git a/docs/examples.rst b/docs/examples.rst index 37bd79de1b..836fe50a0c 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -901,7 +901,7 @@ The script can be run with: ``python ./eventscanner.py `` def get_block_timestamp(self, block_num) -> datetime.datetime: """Get Ethereum block timestamp""" try: - block_info = self.w3.eth.getBlock(block_num) + block_info = self.web3.eth.getBlock(block_num) except BlockNotFound: # Block was not mined yet, # minor chain reorganisation? @@ -929,7 +929,7 @@ The script can be run with: ``python ./eventscanner.py `` # Do not scan all the way to the final block, as this # block might not be mined yet - return self.w3.eth.blockNumber - 1 + return self.web3.eth.blockNumber - 1 def get_last_scanned_block(self) -> int: return self.state.get_last_scanned_block() @@ -962,7 +962,7 @@ The script can be run with: ``python ./eventscanner.py `` # Callable that takes care of the underlying web3 call def _fetch_events(_start_block, _end_block): - return _fetch_events_for_all_contracts(self.w3, + return _fetch_events_for_all_contracts(self.web3, event_type, self.filters, from_block=_start_block, @@ -970,7 +970,7 @@ The script can be run with: ``python ./eventscanner.py `` # Do `n` retries on `eth_getLogs`, # throttle down block range if needed - end_block, events = _retry_w3_call( + end_block, events = _retry_web3_call( _fetch_events, start_block=start_block, end_block=end_block, @@ -1089,7 +1089,7 @@ The script can be run with: ``python ./eventscanner.py `` return all_processed, total_chunks_scanned - def _retry_w3_call(func, start_block, end_block, retries, delay) -> Tuple[int, list]: + def _retry_web3_call(func, start_block, end_block, retries, delay) -> Tuple[int, list]: """A custom retry loop to throttle down block range. If our JSON-RPC server cannot serve all incoming `eth_getLogs` in a single request, diff --git a/docs/web3.main.rst b/docs/web3.main.rst index d6720b5ad1..455c306801 100644 --- a/docs/web3.main.rst +++ b/docs/web3.main.rst @@ -1,4 +1,4 @@ -.. _w3_base: +.. _web3_base: Web3 API ======== diff --git a/ens/main.py b/ens/main.py index b175a88382..51b9f04602 100644 --- a/ens/main.py +++ b/ens/main.py @@ -37,7 +37,7 @@ address_to_reverse_domain, default, dict_copy, - init_w3, + init_web3, is_none_or_zero_address, is_valid_name, label_to_hash, @@ -84,11 +84,11 @@ def __init__( :param hex-string addr: the address of the ENS registry on-chain. If not provided, ENS.py will default to the mainnet ENS registry address. """ - self.w3 = init_w3(provider) + self.w3 = init_web3(provider) ens_addr = addr if addr else ENS_MAINNET_ADDR - self.ens = self.w3.eth.contract(abi=abis.ENS, address=ens_addr) - self._resolverContract = self.w3.eth.contract(abi=abis.RESOLVER) + self.ens = self.web3.eth.contract(abi=abis.ENS, address=ens_addr) + self._resolverContract = self.web3.eth.contract(abi=abis.RESOLVER) @classmethod def fromWeb3(cls, w3: 'Web3', addr: ChecksumAddress = None) -> 'ENS': @@ -294,7 +294,7 @@ def setup_owner( def _assert_control(self, account: ChecksumAddress, name: str, parent_owned: Optional[str] = None) -> None: - if not address_in(account, self.w3.eth.accounts): + if not address_in(account, self.web3.eth.accounts): raise UnauthorizedError( "in order to modify %r, you must control account %r, which owns %r" % ( name, account, parent_owned or name @@ -362,4 +362,4 @@ def _setup_reverse( def _reverse_registrar(self) -> 'Contract': addr = self.ens.caller.owner(normal_name_to_hash(REVERSE_REGISTRAR_DOMAIN)) - return self.w3.eth.contract(address=addr, abi=abis.REVERSE_REGISTRAR) + return self.web3.eth.contract(address=addr, abi=abis.REVERSE_REGISTRAR) diff --git a/ens/utils.py b/ens/utils.py index e71a56520c..c32afdb347 100644 --- a/ens/utils.py +++ b/ens/utils.py @@ -74,7 +74,7 @@ def ensure_hex(data: HexBytes) -> HexBytes: return data -def init_w3(provider: 'BaseProvider' = cast('BaseProvider', default)) -> '_Web3': +def init_web3(provider: 'BaseProvider' = cast('BaseProvider', default)) -> '_Web3': from web3 import Web3 as Web3Main if provider is default: @@ -82,10 +82,10 @@ def init_w3(provider: 'BaseProvider' = cast('BaseProvider', default)) -> '_Web3' else: w3 = Web3Main(provider, ens=None) - return customize_w3(w3) + return customize_web3(w3) -def customize_w3(w3: '_Web3') -> '_Web3': +def customize_web3(w3: '_Web3') -> '_Web3': from web3.middleware import make_stalecheck_middleware w3.middleware_onion.remove('name_to_address') diff --git a/tests/core/pm-module/test_ens_integration.py b/tests/core/pm-module/test_ens_integration.py index 428a3ec4ec..163dcae8ff 100644 --- a/tests/core/pm-module/test_ens_integration.py +++ b/tests/core/pm-module/test_ens_integration.py @@ -127,7 +127,7 @@ def test_ens_must_be_set_before_ens_methods_can_be_used(ens): w3.pm.set_registry("tester.eth") -def test_w3_ens(ens): +def test_web3_ens(ens): w3 = ens.web3 ns = ENS.fromWeb3(w3, ens.ens.address) w3.ens = ns diff --git a/tests/core/providers/test_auto_provider.py b/tests/core/providers/test_auto_provider.py index 753487fb6b..6fd773a90a 100644 --- a/tests/core/providers/test_auto_provider.py +++ b/tests/core/providers/test_auto_provider.py @@ -52,7 +52,7 @@ def test_load_provider_from_env(monkeypatch, uri, expected_type, expected_attrs) @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_w3_auto_infura_empty_key(monkeypatch, caplog, environ_name): +def test_web3_auto_infura_empty_key(monkeypatch, caplog, environ_name): monkeypatch.setenv('WEB3_INFURA_SCHEME', 'https') monkeypatch.setenv(environ_name, '') @@ -61,7 +61,7 @@ def test_w3_auto_infura_empty_key(monkeypatch, caplog, environ_name): @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_w3_auto_infura_deleted_key(monkeypatch, caplog, environ_name): +def test_web3_auto_infura_deleted_key(monkeypatch, caplog, environ_name): monkeypatch.setenv('WEB3_INFURA_SCHEME', 'https') monkeypatch.delenv(environ_name, raising=False) @@ -71,7 +71,7 @@ def test_w3_auto_infura_deleted_key(monkeypatch, caplog, environ_name): @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_w3_auto_infura_websocket_empty_key(monkeypatch, caplog, environ_name): +def test_web3_auto_infura_websocket_empty_key(monkeypatch, caplog, environ_name): monkeypatch.setenv(environ_name, '') with pytest.raises(InfuraKeyNotFound): @@ -79,7 +79,7 @@ def test_w3_auto_infura_websocket_empty_key(monkeypatch, caplog, environ_name): @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_w3_auto_infura_websocket_deleted_key(monkeypatch, caplog, environ_name): +def test_web3_auto_infura_websocket_deleted_key(monkeypatch, caplog, environ_name): monkeypatch.delenv(environ_name, raising=False) with pytest.raises(InfuraKeyNotFound): @@ -87,7 +87,7 @@ def test_w3_auto_infura_websocket_deleted_key(monkeypatch, caplog, environ_name) @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_w3_auto_infura(monkeypatch, caplog, environ_name): +def test_web3_auto_infura(monkeypatch, caplog, environ_name): monkeypatch.setenv('WEB3_INFURA_SCHEME', 'https') API_KEY = 'aoeuhtns' @@ -103,7 +103,7 @@ def test_w3_auto_infura(monkeypatch, caplog, environ_name): @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_w3_auto_infura_websocket_default(monkeypatch, caplog, environ_name): +def test_web3_auto_infura_websocket_default(monkeypatch, caplog, environ_name): monkeypatch.setenv('WEB3_INFURA_SCHEME', 'wss') API_KEY = 'aoeuhtns' monkeypatch.setenv(environ_name, API_KEY) @@ -117,7 +117,7 @@ def test_w3_auto_infura_websocket_default(monkeypatch, caplog, environ_name): assert getattr(w3.provider, 'endpoint_uri') == expected_url -def test_w3_auto_infura_raises_error_with_nonexistent_scheme(monkeypatch): +def test_web3_auto_infura_raises_error_with_nonexistent_scheme(monkeypatch): monkeypatch.setenv('WEB3_INFURA_API_KEY', 'test') monkeypatch.setenv('WEB3_INFURA_SCHEME', 'not-a-scheme') @@ -127,7 +127,7 @@ def test_w3_auto_infura_raises_error_with_nonexistent_scheme(monkeypatch): @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_w3_auto_infura_websocket_with_secret(monkeypatch, caplog, environ_name): +def test_web3_auto_infura_websocket_with_secret(monkeypatch, caplog, environ_name): monkeypatch.setenv(environ_name, 'test') monkeypatch.setenv('WEB3_INFURA_API_SECRET', 'secret') @@ -140,7 +140,7 @@ def test_w3_auto_infura_websocket_with_secret(monkeypatch, caplog, environ_name) @pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID']) -def test_w3_auto_infura_with_secret(monkeypatch, caplog, environ_name): +def test_web3_auto_infura_with_secret(monkeypatch, caplog, environ_name): monkeypatch.setenv('WEB3_INFURA_SCHEME', 'https') monkeypatch.setenv(environ_name, 'test') monkeypatch.setenv('WEB3_INFURA_API_SECRET', 'secret') diff --git a/tests/core/providers/test_ipc_provider.py b/tests/core/providers/test_ipc_provider.py index d1bd609db0..2b1042b007 100644 --- a/tests/core/providers/test_ipc_provider.py +++ b/tests/core/providers/test_ipc_provider.py @@ -86,7 +86,7 @@ def test_sync_waits_for_full_result(jsonrpc_ipc_pipe_path, serve_empty_result): provider._socket.sock.close() -def test_w3_auto_gethdev(): +def test_web3_auto_gethdev(): assert isinstance(w3.provider, IPCProvider) return_block_with_long_extra_data = construct_fixture_middleware({ 'eth_getBlockByNumber': {'extraData': '0x' + 'ff' * 33}, diff --git a/tests/core/web3-module/test_api.py b/tests/core/web3-module/test_api.py index 61ff832bb6..1f404e695e 100644 --- a/tests/core/web3-module/test_api.py +++ b/tests/core/web3-module/test_api.py @@ -1,2 +1,2 @@ -def test_w3_api(web3): +def test_web3_api(web3): assert web3.api.startswith("5") diff --git a/tests/core/web3-module/test_clientVersion.py b/tests/core/web3-module/test_clientVersion.py index b3102bdcc4..4f2783adcf 100644 --- a/tests/core/web3-module/test_clientVersion.py +++ b/tests/core/web3-module/test_clientVersion.py @@ -1,2 +1,2 @@ -def test_w3_clientVersion(web3): +def test_web3_clientVersion(web3): assert web3.clientVersion.startswith("EthereumTester/") diff --git a/tests/ens/test_utils.py b/tests/ens/test_utils.py index 6daf5a40e5..052670a533 100644 --- a/tests/ens/test_utils.py +++ b/tests/ens/test_utils.py @@ -1,10 +1,10 @@ from ens.utils import ( - init_w3, + init_web3, ) def test_init_adds_middlewares(): - w3 = init_w3() + w3 = init_web3() middlewares = map(str, w3.manager.middleware_onion) assert 'stalecheck_middleware' in next(middlewares) diff --git a/tests/ethpm/test_package.py b/tests/ethpm/test_package.py index 3f2fab0249..1202b54715 100644 --- a/tests/ethpm/test_package.py +++ b/tests/ethpm/test_package.py @@ -28,12 +28,12 @@ def deployed_safe_math(safe_math_package, w3): return safe_math_package, tx_receipt.contractAddress -def test_package_object_instantiates_with_a_w3_object(all_manifests, w3): +def test_package_object_instantiates_with_a_web3_object(all_manifests, w3): package = Package(all_manifests, w3) assert package.w3 is w3 -def test_update_w3(deployed_safe_math, w3): +def test_update_web3(deployed_safe_math, w3): new_w3 = Web3(Web3.EthereumTesterProvider()) original_package, _ = deployed_safe_math assert original_package.w3 is w3 @@ -45,7 +45,7 @@ def test_update_w3(deployed_safe_math, w3): new_package.deployments -def test_get_contract_factory_with_default_w3(safe_math_package, w3): +def test_get_contract_factory_with_default_web3(safe_math_package, w3): contract_factory = safe_math_package.get_contract_factory("SafeMathLib") assert hasattr(contract_factory, "address") assert hasattr(contract_factory, "abi") diff --git a/tests/integration/go_ethereum/common.py b/tests/integration/go_ethereum/common.py index a73d010046..ff747167dd 100644 --- a/tests/integration/go_ethereum/common.py +++ b/tests/integration/go_ethereum/common.py @@ -14,7 +14,7 @@ class GoEthereumTest(Web3ModuleTest): - def _check_w3_clientVersion(self, client_version): + def _check_web3_clientVersion(self, client_version): assert client_version.startswith('Geth/') diff --git a/tests/integration/go_ethereum/test_goethereum_http.py b/tests/integration/go_ethereum/test_goethereum_http.py index af7faa43c7..2aa1b9e6de 100644 --- a/tests/integration/go_ethereum/test_goethereum_http.py +++ b/tests/integration/go_ethereum/test_goethereum_http.py @@ -60,7 +60,7 @@ def geth_command_arguments(rpc_port, def web3(geth_process, endpoint_uri): wait_for_http(endpoint_uri) _w3 = Web3(Web3.HTTPProvider(endpoint_uri)) - return _w3 + return _web3 class TestGoEthereumTest(GoEthereumTest): diff --git a/tests/integration/go_ethereum/test_goethereum_ipc.py b/tests/integration/go_ethereum/test_goethereum_ipc.py index 3f29c1a294..9d9d2a70f2 100644 --- a/tests/integration/go_ethereum/test_goethereum_ipc.py +++ b/tests/integration/go_ethereum/test_goethereum_ipc.py @@ -55,7 +55,7 @@ def geth_ipc_path(datadir): def web3(geth_process, geth_ipc_path): wait_for_socket(geth_ipc_path) _w3 = Web3(Web3.IPCProvider(geth_ipc_path)) - return _w3 + return _web3 class TestGoEthereumTest(GoEthereumTest): diff --git a/tests/integration/go_ethereum/test_goethereum_ws.py b/tests/integration/go_ethereum/test_goethereum_ws.py index bcbe54ff4a..5041b81efa 100644 --- a/tests/integration/go_ethereum/test_goethereum_ws.py +++ b/tests/integration/go_ethereum/test_goethereum_ws.py @@ -66,7 +66,7 @@ def geth_command_arguments(geth_binary, def web3(geth_process, endpoint_uri, event_loop): event_loop.run_until_complete(wait_for_ws(endpoint_uri, event_loop)) _w3 = Web3(Web3.WebsocketProvider(endpoint_uri)) - return _w3 + return _web3 class TestGoEthereumTest(GoEthereumTest): diff --git a/tests/integration/parity/common.py b/tests/integration/parity/common.py index 23212cb38d..b38356f91b 100644 --- a/tests/integration/parity/common.py +++ b/tests/integration/parity/common.py @@ -21,7 +21,7 @@ class ParityWeb3ModuleTest(Web3ModuleTest): - def _check_w3_clientVersion(self, client_version): + def _check_web3_clientVersion(self, client_version): assert client_version.startswith('Parity-Ethereum/') diff --git a/tests/integration/parity/test_parity_http.py b/tests/integration/parity/test_parity_http.py index ae88cd8494..c6bf6b1d96 100644 --- a/tests/integration/parity/test_parity_http.py +++ b/tests/integration/parity/test_parity_http.py @@ -77,7 +77,7 @@ def parity_import_blocks_command(parity_binary, rpc_port, datadir, passwordfile) def web3(parity_process, endpoint_uri): wait_for_http(endpoint_uri) _w3 = Web3(Web3.HTTPProvider(endpoint_uri)) - return _w3 + return _web3 class TestParityWeb3ModuleTest(ParityWeb3ModuleTest): diff --git a/tests/integration/parity/test_parity_ipc.py b/tests/integration/parity/test_parity_ipc.py index 702b46d142..4be012054a 100644 --- a/tests/integration/parity/test_parity_ipc.py +++ b/tests/integration/parity/test_parity_ipc.py @@ -75,7 +75,7 @@ def parity_import_blocks_command(parity_binary, ipc_path, datadir, passwordfile) def web3(parity_process, ipc_path): wait_for_socket(ipc_path) _w3 = Web3(Web3.IPCProvider(ipc_path)) - return _w3 + return _web3 class TestParityWeb3ModuleTest(ParityWeb3ModuleTest): diff --git a/tests/integration/parity/test_parity_ws.py b/tests/integration/parity/test_parity_ws.py index 5479679969..4bc44f00e3 100644 --- a/tests/integration/parity/test_parity_ws.py +++ b/tests/integration/parity/test_parity_ws.py @@ -80,7 +80,7 @@ def parity_import_blocks_command(parity_binary, ws_port, datadir, passwordfile): def web3(parity_process, endpoint_uri, event_loop): event_loop.run_until_complete(wait_for_ws(endpoint_uri, event_loop)) _w3 = Web3(Web3.WebsocketProvider(endpoint_uri)) - return _w3 + return _web3 class TestParityWeb3ModuleTest(ParityWeb3ModuleTest): diff --git a/tests/integration/test_ethereum_tester.py b/tests/integration/test_ethereum_tester.py index 04ab807f01..6ef83c3bde 100644 --- a/tests/integration/test_ethereum_tester.py +++ b/tests/integration/test_ethereum_tester.py @@ -47,7 +47,7 @@ def eth_tester_provider(eth_tester): @pytest.fixture(scope="module") def web3(eth_tester_provider): _w3 = Web3(eth_tester_provider) - return _w3 + return _web3 # @@ -211,7 +211,7 @@ def funded_account_for_raw_txn(web3): class TestEthereumTesterWeb3Module(Web3ModuleTest): - def _check_w3_clientVersion(self, client_version): + def _check_web3_clientVersion(self, client_version): assert client_version.startswith('EthereumTester/') diff --git a/web3/_utils/module_testing/web3_module.py b/web3/_utils/module_testing/web3_module.py index 066d57053d..7b21a9b809 100644 --- a/web3/_utils/module_testing/web3_module.py +++ b/web3/_utils/module_testing/web3_module.py @@ -25,11 +25,11 @@ class Web3ModuleTest: - def test_w3_clientVersion(self, w3: Web3) -> None: + def test_web3_clientVersion(self, w3: Web3) -> None: client_version = web3.clientVersion - self._check_w3_clientVersion(client_version) + self._check_web3_clientVersion(client_version) - def _check_w3_clientVersion(self, client_version: str) -> NoReturn: + def _check_web3_clientVersion(self, client_version: str) -> NoReturn: raise NotImplementedError("Must be implemented by subclasses") # Contract that calculated test values can be found at diff --git a/web3/contract.py b/web3/contract.py index fcc64cfefe..f2785e6e44 100644 --- a/web3/contract.py +++ b/web3/contract.py @@ -167,7 +167,7 @@ def __init__(self, abi: ABI, w3: 'Web3', address: Optional[ChecksumAddress] = No func['name'], ContractFunction.factory( func['name'], - web3=self.w3, + web3=self.web3, contract_abi=self.abi, address=self.address, function_identifier=func['name'])) @@ -327,23 +327,23 @@ def __init__(self, address: Optional[ChecksumAddress] = None) -> None: :param address: Contract address as 0x hex string """ - if self.w3 is None: + if self.web3 is None: raise AttributeError( 'The `Contract` class has not been initialized. Please use the ' '`web3.contract` interface to create your contract class.' ) if address: - self.address = normalize_address(self.w3.ens, address) + self.address = normalize_address(self.web3.ens, address) if not self.address: raise TypeError("The address argument is required to instantiate a contract.") - self.functions = ContractFunctions(self.abi, self.w3, self.address) - self.caller = ContractCaller(self.abi, self.w3, self.address) - self.events = ContractEvents(self.abi, self.w3, self.address) - self.fallback = Contract.get_fallback_function(self.abi, self.w3, self.address) - self.receive = Contract.get_receive_function(self.abi, self.w3, self.address) + self.functions = ContractFunctions(self.abi, self.web3, self.address) + self.caller = ContractCaller(self.abi, self.web3, self.address) + self.events = ContractEvents(self.abi, self.web3, self.address) + self.fallback = Contract.get_fallback_function(self.abi, self.web3, self.address) + self.receive = Contract.get_receive_function(self.abi, self.web3, self.address) @classmethod def factory(cls, w3: 'Web3', class_name: Optional[str] = None, **kwargs: Any) -> 'Contract': @@ -416,7 +416,7 @@ def encodeABI(cls, fn_name: str, args: Optional[Any] = None, @combomethod def all_functions(self) -> List['ContractFunction']: return find_functions_by_identifier( - self.abi, self.w3, self.address, lambda _: True + self.abi, self.web3, self.address, lambda _: True ) @combomethod @@ -430,7 +430,7 @@ def get_function_by_signature(self, signature: str) -> 'ContractFunction': def callable_check(fn_abi: ABIFunction) -> bool: return abi_to_signature(fn_abi) == signature - fns = find_functions_by_identifier(self.abi, self.w3, self.address, callable_check) + fns = find_functions_by_identifier(self.abi, self.web3, self.address, callable_check) return get_function_by_identifier(fns, 'signature') @combomethod @@ -439,7 +439,7 @@ def callable_check(fn_abi: ABIFunction) -> bool: return fn_abi['name'] == fn_name return find_functions_by_identifier( - self.abi, self.w3, self.address, callable_check + self.abi, self.web3, self.address, callable_check ) @combomethod @@ -454,7 +454,7 @@ def callable_check(fn_abi: ABIFunction) -> bool: # https://github.com/python/mypy/issues/4976 return encode_hex(function_abi_to_4byte_selector(fn_abi)) == to_4byte_hex(selector) # type: ignore # noqa: E501 - fns = find_functions_by_identifier(self.abi, self.w3, self.address, callable_check) + fns = find_functions_by_identifier(self.abi, self.web3, self.address, callable_check) return get_function_by_identifier(fns, 'selector') @combomethod @@ -467,7 +467,7 @@ def decode_function_input(self, data: HexStr) -> Tuple['ContractFunction', Dict[ names = get_abi_input_names(func.abi) types = get_abi_input_types(func.abi) - decoded = self.w3.codec.decode_abi(types, cast(HexBytes, params)) + decoded = self.web3.codec.decode_abi(types, cast(HexBytes, params)) normalized = map_abi_data(BASE_RETURN_NORMALIZERS, types, decoded) return func, dict(zip(names, normalized)) @@ -475,10 +475,10 @@ def decode_function_input(self, data: HexStr) -> Tuple['ContractFunction', Dict[ @combomethod def find_functions_by_args(self, *args: Any) -> List['ContractFunction']: def callable_check(fn_abi: ABIFunction) -> bool: - return check_if_arguments_can_be_encoded(fn_abi, self.w3.codec, args=args, kwargs={}) + return check_if_arguments_can_be_encoded(fn_abi, self.web3.codec, args=args, kwargs={}) return find_functions_by_identifier( - self.abi, self.w3, self.address, callable_check + self.abi, self.web3, self.address, callable_check ) @combomethod @@ -614,7 +614,7 @@ def _encode_data_in_transaction(self, *args: Any, **kwargs: Any) -> HexStr: arguments = merge_args_and_kwargs(constructor_abi, args, kwargs) data = add_0x_prefix( - encode_abi(self.w3, constructor_abi, arguments, data=self.bytecode) + encode_abi(self.web3, constructor_abi, arguments, data=self.bytecode) ) else: data = to_hex(self.bytecode) @@ -633,13 +633,13 @@ def estimateGas( self.check_forbidden_keys_in_transaction(estimate_gas_transaction, ["data", "to"]) - if self.w3.eth.default_account is not empty: + if self.web3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - estimate_gas_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore # noqa: E501 + estimate_gas_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore # noqa: E501 estimate_gas_transaction['data'] = self.data_in_transaction - return self.w3.eth.estimate_gas( + return self.web3.eth.estimate_gas( estimate_gas_transaction, block_identifier=block_identifier ) @@ -652,14 +652,14 @@ def transact(self, transaction: Optional[TxParams] = None) -> HexBytes: self.check_forbidden_keys_in_transaction(transact_transaction, ["data", "to"]) - if self.w3.eth.default_account is not empty: + if self.web3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - transact_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore + transact_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore transact_transaction['data'] = self.data_in_transaction # TODO: handle asynchronous contract creation - return self.w3.eth.send_transaction(transact_transaction) + return self.web3.eth.send_transaction(transact_transaction) @combomethod def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams: @@ -674,13 +674,13 @@ def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams: self.check_forbidden_keys_in_transaction(built_transaction, ["data", "to"]) - if self.w3.eth.default_account is not empty: + if self.web3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - built_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore + built_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore built_transaction['data'] = self.data_in_transaction built_transaction['to'] = Address(b'') - return fill_transaction_defaults(self.w3, built_transaction) + return fill_transaction_defaults(self.web3, built_transaction) @staticmethod def check_forbidden_keys_in_transaction( @@ -879,7 +879,7 @@ def _set_function_info(self) -> None: if not self.abi: self.abi = find_matching_fn_abi( self.contract_abi, - self.w3.codec, + self.web3.codec, self.function_identifier, self.args, self.kwargs @@ -933,9 +933,9 @@ def call( if self.address: call_transaction.setdefault('to', self.address) - if self.w3.eth.default_account is not empty: + if self.web3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - call_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore + call_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore if 'to' not in call_transaction: if isinstance(self, type): @@ -949,10 +949,10 @@ def call( "Please ensure that this contract instance has an address." ) - block_id = parse_block_identifier(self.w3, block_identifier) + block_id = parse_block_identifier(self.web3, block_identifier) return call_contract_function( - self.w3, + self.web3, self.address, self._return_data_normalizers, self.function_identifier, @@ -975,9 +975,9 @@ def transact(self, transaction: Optional[TxParams] = None) -> HexBytes: if self.address is not None: transact_transaction.setdefault('to', self.address) - if self.w3.eth.default_account is not empty: + if self.web3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - transact_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore + transact_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore if 'to' not in transact_transaction: if isinstance(self, type): @@ -992,7 +992,7 @@ def transact(self, transaction: Optional[TxParams] = None) -> HexBytes: return transact_with_contract_function( self.address, - self.w3, + self.web3, self.function_identifier, transact_transaction, self.contract_abi, @@ -1017,9 +1017,9 @@ def estimateGas( if self.address: estimate_gas_transaction.setdefault('to', self.address) - if self.w3.eth.default_account is not empty: + if self.web3.eth.default_account is not empty: # type ignored b/c check prevents an empty default_account - estimate_gas_transaction.setdefault('from', self.w3.eth.default_account) # type: ignore # noqa: E501 + estimate_gas_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore # noqa: E501 if 'to' not in estimate_gas_transaction: if isinstance(self, type): @@ -1034,7 +1034,7 @@ def estimateGas( return estimate_gas_for_function( self.address, - self.w3, + self.web3, self.function_identifier, estimate_gas_transaction, self.contract_abi, @@ -1074,7 +1074,7 @@ def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams: return build_transaction_for_function( self.address, - self.w3, + self.web3, self.function_identifier, built_transaction, self.contract_abi, @@ -1147,7 +1147,7 @@ def _parse_logs( for log in txn_receipt['logs']: try: - rich_log = get_event_data(self.w3.codec, self.abi, log) + rich_log = get_event_data(self.web3.codec, self.abi, log) except (MismatchedABI, LogTopicError, InvalidEventABI, TypeError) as e: if errors == DISCARD: continue @@ -1169,7 +1169,7 @@ def _parse_logs( @combomethod def processLog(self, log: HexStr) -> EventData: - return get_event_data(self.w3.codec, self.abi, log) + return get_event_data(self.web3.codec, self.abi, log) @combomethod def createFilter( @@ -1197,7 +1197,7 @@ def createFilter( _, event_filter_params = construct_event_filter_params( self._get_event_abi(), - self.w3.codec, + self.web3.codec, contract_address=self.address, argument_filters=_filters, fromBlock=fromBlock, @@ -1206,7 +1206,7 @@ def createFilter( topics=topics, ) - filter_builder = EventFilterBuilder(event_abi, self.w3.codec) + filter_builder = EventFilterBuilder(event_abi, self.web3.codec) filter_builder.address = cast(ChecksumAddress, event_filter_params.get('address')) filter_builder.fromBlock = event_filter_params.get('fromBlock') filter_builder.toBlock = event_filter_params.get('toBlock') @@ -1224,8 +1224,8 @@ def createFilter( for arg, value in match_single_vals.items(): filter_builder.args[arg].match_single(value) - log_filter = filter_builder.deploy(self.w3) - log_filter.log_entry_formatter = get_event_data(self.w3.codec, self._get_event_abi()) + log_filter = filter_builder.deploy(self.web3) + log_filter.log_entry_formatter = get_event_data(self.web3.codec, self._get_event_abi()) log_filter.builder = filter_builder return log_filter @@ -1234,8 +1234,8 @@ def createFilter( def build_filter(self) -> EventFilterBuilder: builder = EventFilterBuilder( self._get_event_abi(), - self.w3.codec, - formatter=get_event_data(self.w3.codec, self._get_event_abi())) + self.web3.codec, + formatter=get_event_data(self.web3.codec, self._get_event_abi())) builder.address = self.address return builder @@ -1322,7 +1322,7 @@ def getLogs(self, # Namely, convert event names to their keccak signatures data_filter_set, event_filter_params = construct_event_filter_params( abi, - self.w3.codec, + self.web3.codec, contract_address=self.address, argument_filters=_filters, fromBlock=fromBlock, @@ -1334,10 +1334,10 @@ def getLogs(self, event_filter_params['blockHash'] = blockHash # Call JSON-RPC API - logs = self.w3.eth.get_logs(event_filter_params) + logs = self.web3.eth.get_logs(event_filter_params) # Convert raw binary data to Python proxy objects as described by ABI - return tuple(get_event_data(self.w3.codec, abi, entry) for entry in logs) + return tuple(get_event_data(self.web3.codec, abi, entry) for entry in logs) @classmethod def factory(cls, class_name: str, **kwargs: Any) -> PropertyCheckingFactory: @@ -1385,12 +1385,12 @@ def __init__(self, for func in self._functions: fn: ContractFunction = ContractFunction.factory( func['name'], - web3=self.w3, + web3=self.web3, contract_abi=self.abi, address=self.address, function_identifier=func['name']) - block_id = parse_block_identifier(self.w3, block_identifier) + block_id = parse_block_identifier(self.web3, block_identifier) caller_method = partial(self.call_function, fn, transaction=transaction, @@ -1431,7 +1431,7 @@ def __call__( if transaction is None: transaction = {} return type(self)(self.abi, - self.w3, + self.web3, self.address, transaction=transaction, block_identifier=block_identifier) diff --git a/web3/eth.py b/web3/eth.py index 6001dd17c6..af857e18b8 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -431,7 +431,7 @@ def wait_for_transaction_receipt( self, transaction_hash: _Hash32, timeout: int = 120, poll_latency: float = 0.1 ) -> TxReceipt: try: - return wait_for_transaction_receipt(self.w3, transaction_hash, timeout, poll_latency) + return wait_for_transaction_receipt(self.web3, transaction_hash, timeout, poll_latency) except Timeout: raise TimeExhausted( "Transaction {} is not in the chain, after {} seconds".format( @@ -455,8 +455,8 @@ def replaceTransaction(self, transaction_hash: _Hash32, new_transaction: TxParam return self.replace_transaction(transaction_hash, new_transaction) def replace_transaction(self, transaction_hash: _Hash32, new_transaction: TxParams) -> HexBytes: - current_transaction = get_required_transaction(self.w3, transaction_hash) - return replace_transaction(self.w3, current_transaction, new_transaction) + current_transaction = get_required_transaction(self.web3, transaction_hash) + return replace_transaction(self.web3, current_transaction, new_transaction) # todo: Update Any to stricter kwarg checking with TxParams # https://github.com/python/mypy/issues/4441 @@ -470,10 +470,10 @@ def modify_transaction( self, transaction_hash: _Hash32, **transaction_params: Any ) -> HexBytes: assert_valid_transaction_params(cast(TxParams, transaction_params)) - current_transaction = get_required_transaction(self.w3, transaction_hash) + current_transaction = get_required_transaction(self.web3, transaction_hash) current_transaction_params = extract_valid_transaction_params(current_transaction) new_transaction = merge(current_transaction_params, transaction_params) - return replace_transaction(self.w3, current_transaction, new_transaction) + return replace_transaction(self.web3, current_transaction, new_transaction) def send_transaction_munger(self, transaction: TxParams) -> Tuple[TxParams]: # TODO: move to middleware @@ -485,7 +485,7 @@ def send_transaction_munger(self, transaction: TxParams) -> Tuple[TxParams]: transaction = assoc( transaction, 'gas', - get_buffered_gas_estimate(self.w3, transaction), + get_buffered_gas_estimate(self.web3, transaction), ) return (transaction,) @@ -645,7 +645,7 @@ def contract( # noqa: F811 ) -> Union[Type[Contract], Contract]: ContractFactoryClass = kwargs.pop('ContractFactoryClass', self.defaultContractFactory) - ContractFactory = ContractFactoryClass.factory(self.w3, **kwargs) + ContractFactory = ContractFactoryClass.factory(self.web3, **kwargs) if address: return ContractFactory(address) @@ -677,7 +677,7 @@ def generateGasPrice(self, transaction_params: Optional[TxParams] = None) -> Opt def generate_gas_price(self, transaction_params: Optional[TxParams] = None) -> Optional[Wei]: if self.gasPriceStrategy: - return self.gasPriceStrategy(self.w3, transaction_params) + return self.gasPriceStrategy(self.web3, transaction_params) return None @deprecated_for("set_gas_price_strategy") diff --git a/web3/manager.py b/web3/manager.py index f5c628acd3..672e62731d 100644 --- a/web3/manager.py +++ b/web3/manager.py @@ -127,7 +127,7 @@ def _make_request( self, method: Union[RPCEndpoint, Callable[..., RPCEndpoint]], params: Any ) -> RPCResponse: request_func = self.provider.request_func( - self.w3, + self.web3, self.middleware_onion) self.logger.debug("Making request. Method: %s", method) return request_func(method, params) @@ -136,7 +136,7 @@ async def _coro_make_request( self, method: Union[RPCEndpoint, Callable[..., RPCEndpoint]], params: Any ) -> RPCResponse: request_func = self.provider.request_func( - self.w3, + self.web3, self.middleware_onion) self.logger.debug("Making request. Method: %s", method) # type ignored b/c request_func is an awaitable in async model diff --git a/web3/middleware/formatting.py b/web3/middleware/formatting.py index dd1199c87b..3542583a9a 100644 --- a/web3/middleware/formatting.py +++ b/web3/middleware/formatting.py @@ -28,7 +28,7 @@ def construct_formatting_middleware( result_formatters: Optional[Formatters] = None, error_formatters: Optional[Formatters] = None ) -> Middleware: - def ignore_w3_in_standard_formatters( + def ignore_web3_in_standard_formatters( w3: "Web3", ) -> FormattersDict: return dict( @@ -37,10 +37,10 @@ def ignore_w3_in_standard_formatters( error_formatters=error_formatters or {}, ) - return construct_w3_formatting_middleware(ignore_w3_in_standard_formatters) + return construct_web3_formatting_middleware(ignore_web3_in_standard_formatters) -def construct_w3_formatting_middleware( +def construct_web3_formatting_middleware( web3_formatters_builder: Callable[["Web3"], FormattersDict] ) -> Middleware: def formatter_middleware( diff --git a/web3/middleware/validation.py b/web3/middleware/validation.py index 18267acdb6..22b3306542 100644 --- a/web3/middleware/validation.py +++ b/web3/middleware/validation.py @@ -32,7 +32,7 @@ ValidationError, ) from web3.middleware.formatting import ( - construct_w3_formatting_middleware, + construct_web3_formatting_middleware, ) from web3.types import ( FormattersDict, @@ -117,7 +117,7 @@ def chain_id_validator(w3: "Web3") -> Callable[..., Any]: ) -def build_validators_with_w3(w3: "Web3") -> FormattersDict: +def build_validators_with_web3(w3: "Web3") -> FormattersDict: return dict( request_formatters={ RPC.eth_sendTransaction: chain_id_validator(w3), @@ -131,4 +131,4 @@ def build_validators_with_w3(w3: "Web3") -> FormattersDict: ) -validation_middleware = construct_w3_formatting_middleware(build_validators_with_w3) +validation_middleware = construct_web3_formatting_middleware(build_validators_with_web3) diff --git a/web3/parity.py b/web3/parity.py index 84bcaa5c44..2c32c3b96f 100644 --- a/web3/parity.py +++ b/web3/parity.py @@ -186,8 +186,8 @@ def trace_call_munger( block_identifier: Optional[BlockIdentifier] = None ) -> Tuple[TxParams, ParityTraceMode, BlockIdentifier]: # TODO: move to middleware - if 'from' not in transaction and is_checksum_address(self.w3.eth.default_account): - transaction = assoc(transaction, 'from', self.w3.eth.default_account) + if 'from' not in transaction and is_checksum_address(self.web3.eth.default_account): + transaction = assoc(transaction, 'from', self.web3.eth.default_account) # TODO: move to middleware if block_identifier is None: diff --git a/web3/pm.py b/web3/pm.py index 24c658f6c9..2a897bd335 100644 --- a/web3/pm.py +++ b/web3/pm.py @@ -327,7 +327,7 @@ def get_package_from_manifest(self, manifest: Manifest) -> Package: * Parameters: * ``manifest``: A dict representing a valid manifest """ - return Package(manifest, self.w3) + return Package(manifest, self.web3) def get_package_from_uri(self, manifest_uri: URI) -> Package: """ @@ -339,7 +339,7 @@ def get_package_from_uri(self, manifest_uri: URI) -> Package: * Parameters: * ``uri``: Must be a valid content-addressed URI """ - return Package.from_uri(manifest_uri, self.w3) + return Package.from_uri(manifest_uri, self.web3) def get_local_package(self, package_name: str, ethpm_dir: Path = None) -> Package: """ @@ -381,17 +381,17 @@ def set_registry(self, address: Union[Address, ChecksumAddress, ENS]) -> None: """ if is_canonical_address(address): addr_string = to_text(address) - self.registry = SimpleRegistry(to_checksum_address(addr_string), self.w3) + self.registry = SimpleRegistry(to_checksum_address(addr_string), self.web3) elif is_checksum_address(address): - self.registry = SimpleRegistry(cast(ChecksumAddress, address), self.w3) + self.registry = SimpleRegistry(cast(ChecksumAddress, address), self.web3) elif is_ens_name(address): self._validate_set_ens() - addr_lookup = self.w3.ens.address(str(address)) + addr_lookup = self.web3.ens.address(str(address)) if not addr_lookup: raise NameNotFound( "No address found after ENS lookup for name: {0}.".format(address) ) - self.registry = SimpleRegistry(addr_lookup, self.w3) + self.registry = SimpleRegistry(addr_lookup, self.web3) else: raise PMError( "Expected a canonical/checksummed address or ENS name for the address, " @@ -409,7 +409,7 @@ def deploy_and_set_registry(self) -> ChecksumAddress: w3.ens.setup_address(ens_name, w3.pm.registry.address) """ - self.registry = SimpleRegistry.deploy_new_instance(self.w3) + self.registry = SimpleRegistry.deploy_new_instance(self.web3) return to_checksum_address(self.registry.address) def release_package( @@ -558,7 +558,7 @@ def _validate_set_ens(self) -> None: raise InvalidAddress( "Could not look up ENS address because no web3 " "connection available" ) - elif not self.w3.ens: + elif not self.web3.ens: raise InvalidAddress( "Could not look up ENS address because web3.ens is " "set to None" ) diff --git a/web3/testing.py b/web3/testing.py index f421c83a22..4537df8c80 100644 --- a/web3/testing.py +++ b/web3/testing.py @@ -12,21 +12,21 @@ class Testing(Module): def timeTravel(self, timestamp: int) -> None: - return self.w3.manager.request_blocking(RPC.testing_timeTravel, [timestamp]) + return self.web3.manager.request_blocking(RPC.testing_timeTravel, [timestamp]) def mine(self, num_blocks: int = 1) -> None: - return self.w3.manager.request_blocking(RPC.evm_mine, [num_blocks]) + return self.web3.manager.request_blocking(RPC.evm_mine, [num_blocks]) def snapshot(self) -> int: - self.last_snapshot_idx = self.w3.manager.request_blocking(RPC.evm_snapshot, []) + self.last_snapshot_idx = self.web3.manager.request_blocking(RPC.evm_snapshot, []) return self.last_snapshot_idx def reset(self) -> None: - return self.w3.manager.request_blocking(RPC.evm_reset, []) + return self.web3.manager.request_blocking(RPC.evm_reset, []) def revert(self, snapshot_idx: Optional[int] = None) -> None: if snapshot_idx is None: revert_target = self.last_snapshot_idx else: revert_target = snapshot_idx - return self.w3.manager.request_blocking(RPC.evm_revert, [revert_target]) + return self.web3.manager.request_blocking(RPC.evm_revert, [revert_target])