Skip to content

Audit .rst & .py files and convert all Web3 instance variables to use… #1970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ virtualenv for smoke testing:
>>> ...


Verify the latest documentation
Verify the latest documentation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To preview the documentation that will get published:
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
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
Expand All @@ -876,7 +876,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``

self.logger = logger
self.contract = contract
self.web3 = web3
self.w3 = web3
self.state = state
self.events = events
self.filters = filters
Expand Down Expand Up @@ -1356,7 +1356,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
# throttle down.
provider.middlewares.clear()

web3 = Web3(provider)
w3 = Web3(provider)

# Prepare stub ERC-20 contract object
abi = json.loads(ABI)
Expand All @@ -1366,7 +1366,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
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,
Expand Down
6 changes: 3 additions & 3 deletions docs/v4_migration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ 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.

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
Expand Down
2 changes: 1 addition & 1 deletion docs/web3.beacon.rst
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Methods
'signature': '0x967dd2946358db7e426ed19d4576bc75123520ef6a489ca50002222070ee4611f9cef394e5e3071236a93b825f18a4ad07f1d5a1405e6c984f1d71e03f535d13a2156d6ba22cb0c2b148df23a7b8a7293315d6e74b9a26b64283e8393f2ad4c5'
}
],
'deposits': [],
'deposits': [],
'voluntary_exits': []
}
},
Expand Down
2 changes: 1 addition & 1 deletion docs/web3.main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Attributes
Returns the current Web3 version.

.. code-block:: python

>>> web3.api
"4.7.0"

Expand Down
2 changes: 1 addition & 1 deletion docs/web3.pm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/ethereum/EIPs/issues/1319>`_ 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

Expand Down
6 changes: 3 additions & 3 deletions ens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ 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)
self._resolverContract = self.web3.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.
"""
Expand Down
2 changes: 1 addition & 1 deletion ethpm/_utils/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]


Expand Down
2 changes: 1 addition & 1 deletion ethpm/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion ethpm/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
8 changes: 4 additions & 4 deletions tests/core/contracts/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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({
Expand Down Expand Up @@ -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)


Expand All @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion tests/core/contracts/test_concise_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/core/contracts/test_contract_class_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/core/contracts/test_contract_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/core/eth-module/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 = []
Expand Down
4 changes: 2 additions & 2 deletions tests/core/filtering/test_filter_against_transaction_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({})

Expand All @@ -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({})
Expand Down
4 changes: 2 additions & 2 deletions tests/core/middleware/test_gas_price_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions tests/core/middleware/test_http_request_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions tests/core/middleware/test_stalecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/core/mining-module/test_miner_hashrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/core/mining-module/test_miner_setExtra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand All @@ -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'])

Expand Down
4 changes: 2 additions & 2 deletions tests/core/mining-module/test_miner_setGasPrice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/core/mining-module/test_miner_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/core/mining-module/test_miner_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/core/mining-module/test_setEtherBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@


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)
assert web3.eth.coinbase == new_account


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):
Expand Down
Loading