Skip to content

Commit bdf0d93

Browse files
wiseaidevfselmo
andauthored
replace all instances of Web3 with w3 (#2357)
* 📝 replace all instances of Web3 with w3 Signed-off-by: Harmouch101 <[email protected]> * Remove unnecessary w3 arguments to tests while reviewing PR #2357 Co-authored-by: Felipe Selmo <[email protected]>
1 parent 32f5379 commit bdf0d93

File tree

139 files changed

+2150
-2160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+2150
-2160
lines changed

conftest.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,43 +47,43 @@ def is_testrpc_provider(provider):
4747
@pytest.fixture()
4848
def skip_if_testrpc():
4949

50-
def _skip_if_testrpc(web3):
51-
if is_testrpc_provider(web3.provider):
50+
def _skip_if_testrpc(w3):
51+
if is_testrpc_provider(w3.provider):
5252
pytest.skip()
5353
return _skip_if_testrpc
5454

5555

5656
@pytest.fixture()
5757
def wait_for_miner_start():
58-
def _wait_for_miner_start(web3, timeout=60):
58+
def _wait_for_miner_start(w3, timeout=60):
5959
poll_delay_counter = PollDelayCounter()
6060
with Timeout(timeout) as timeout:
61-
while not web3.eth.mining or not web3.eth.hashrate:
61+
while not w3.eth.mining or not w3.eth.hashrate:
6262
time.sleep(poll_delay_counter())
6363
timeout.check()
6464
return _wait_for_miner_start
6565

6666

6767
@pytest.fixture(scope="module")
6868
def wait_for_block():
69-
def _wait_for_block(web3, block_number=1, timeout=None):
69+
def _wait_for_block(w3, block_number=1, timeout=None):
7070
if not timeout:
71-
timeout = (block_number - web3.eth.block_number) * 3
71+
timeout = (block_number - w3.eth.block_number) * 3
7272
poll_delay_counter = PollDelayCounter()
7373
with Timeout(timeout) as timeout:
74-
while web3.eth.block_number < block_number:
75-
web3.manager.request_blocking("evm_mine", [])
74+
while w3.eth.block_number < block_number:
75+
w3.manager.request_blocking("evm_mine", [])
7676
timeout.sleep(poll_delay_counter())
7777
return _wait_for_block
7878

7979

8080
@pytest.fixture(scope="module")
8181
def wait_for_transaction():
82-
def _wait_for_transaction(web3, txn_hash, timeout=120):
82+
def _wait_for_transaction(w3, txn_hash, timeout=120):
8383
poll_delay_counter = PollDelayCounter()
8484
with Timeout(timeout) as timeout:
8585
while True:
86-
txn_receipt = web3.eth.get_transaction_receipt(txn_hash)
86+
txn_receipt = w3.eth.get_transaction_receipt(txn_hash)
8787
if txn_receipt is not None:
8888
break
8989
time.sleep(poll_delay_counter())
@@ -94,7 +94,7 @@ def _wait_for_transaction(web3, txn_hash, timeout=120):
9494

9595

9696
@pytest.fixture()
97-
def web3():
97+
def w3():
9898
provider = EthereumTesterProvider()
9999
return Web3(provider)
100100

docs/examples.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
865865
because it cannot correctly throttle and decrease the `eth_getLogs` block number range.
866866
"""
867867
868-
def __init__(self, web3: Web3, contract: Contract, state: EventScannerState, events: List, filters: {},
868+
def __init__(self, w3: Web3, contract: Contract, state: EventScannerState, events: List, filters: {},
869869
max_chunk_scan_size: int = 10000, max_request_retries: int = 30, request_retry_seconds: float = 3.0):
870870
"""
871871
:param contract: Contract
@@ -878,7 +878,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
878878
879879
self.logger = logger
880880
self.contract = contract
881-
self.web3 = web3
881+
self.w3 = w3
882882
self.state = state
883883
self.events = events
884884
self.filters = filters
@@ -903,7 +903,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
903903
def get_block_timestamp(self, block_num) -> datetime.datetime:
904904
"""Get Ethereum block timestamp"""
905905
try:
906-
block_info = self.web3.eth.getBlock(block_num)
906+
block_info = self.w3.eth.getBlock(block_num)
907907
except BlockNotFound:
908908
# Block was not mined yet,
909909
# minor chain reorganisation?
@@ -931,7 +931,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
931931
932932
# Do not scan all the way to the final block, as this
933933
# block might not be mined yet
934-
return self.web3.eth.blockNumber - 1
934+
return self.w3.eth.blockNumber - 1
935935
936936
def get_last_scanned_block(self) -> int:
937937
return self.state.get_last_scanned_block()
@@ -964,7 +964,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
964964
965965
# Callable that takes care of the underlying web3 call
966966
def _fetch_events(_start_block, _end_block):
967-
return _fetch_events_for_all_contracts(self.web3,
967+
return _fetch_events_for_all_contracts(self.w3,
968968
event_type,
969969
self.filters,
970970
from_block=_start_block,
@@ -1133,7 +1133,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
11331133
11341134
11351135
def _fetch_events_for_all_contracts(
1136-
web3,
1136+
w3,
11371137
event,
11381138
argument_filters: dict,
11391139
from_block: int,
@@ -1158,7 +1158,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
11581158
# it might have Solidity ABI encoding v1 or v2.
11591159
# We just assume the default that you set on Web3 object here.
11601160
# More information here https://eth-abi.readthedocs.io/en/latest/index.html
1161-
codec: ABICodec = web3.codec
1161+
codec: ABICodec = w3.codec
11621162
11631163
# Here we need to poke a bit into Web3 internals, as this
11641164
# functionality is not exposed by default.
@@ -1179,7 +1179,7 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
11791179
11801180
# Call JSON-RPC API on your Ethereum node.
11811181
# get_logs() returns raw AttributedDict entries
1182-
logs = web3.eth.get_logs(event_filter_params)
1182+
logs = w3.eth.get_logs(event_filter_params)
11831183
11841184
# Convert raw binary data to Python proxy objects as described by ABI
11851185
all_events = []
@@ -1358,19 +1358,19 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
13581358
# throttle down.
13591359
provider.middlewares.clear()
13601360
1361-
web3 = Web3(provider)
1361+
w3 = Web3(provider)
13621362
13631363
# Prepare stub ERC-20 contract object
13641364
abi = json.loads(ABI)
1365-
ERC20 = web3.eth.contract(abi=abi)
1365+
ERC20 = w3.eth.contract(abi=abi)
13661366
13671367
# Restore/create our persistent state
13681368
state = JSONifiedState()
13691369
state.restore()
13701370
1371-
# chain_id: int, web3: Web3, abi: dict, state: EventScannerState, events: List, filters: {}, max_chunk_scan_size: int=10000
1371+
# chain_id: int, w3: Web3, abi: dict, state: EventScannerState, events: List, filters: {}, max_chunk_scan_size: int=10000
13721372
scanner = EventScanner(
1373-
web3=web3,
1373+
w3=w3,
13741374
contract=ERC20,
13751375
state=state,
13761376
events=[ERC20.events.Transfer],

ens/main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,23 @@ def __init__(
112112
:param hex-string addr: the address of the ENS registry on-chain. If not provided,
113113
ENS.py will default to the mainnet ENS registry address.
114114
"""
115-
self.web3 = init_web3(provider, middlewares)
115+
self.w3 = init_web3(provider, middlewares)
116116

117117
ens_addr = addr if addr else ENS_MAINNET_ADDR
118-
self.ens = self.web3.eth.contract(abi=abis.ENS, address=ens_addr)
119-
self._resolverContract = self.web3.eth.contract(abi=abis.RESOLVER)
118+
self.ens = self.w3.eth.contract(abi=abis.ENS, address=ens_addr)
119+
self._resolverContract = self.w3.eth.contract(abi=abis.RESOLVER)
120120

121121
@classmethod
122-
def fromWeb3(cls, web3: 'Web3', addr: ChecksumAddress = None) -> 'ENS':
122+
def fromWeb3(cls, w3: 'Web3', addr: ChecksumAddress = None) -> 'ENS':
123123
"""
124124
Generate an ENS instance with web3
125125
126-
:param `web3.Web3` web3: to infer connection information
126+
:param `web3.Web3` w3: to infer connection information
127127
:param hex-string addr: the address of the ENS registry on-chain. If not provided,
128128
ENS.py will default to the mainnet ENS registry address.
129129
"""
130-
provider = web3.manager.provider
131-
middlewares = web3.middleware_onion.middlewares
130+
provider = w3.manager.provider
131+
middlewares = w3.middleware_onion.middlewares
132132
return cls(provider, addr=addr, middlewares=middlewares)
133133

134134
def address(self, name: str) -> Optional[ChecksumAddress]:
@@ -333,7 +333,7 @@ def setup_owner(
333333

334334
def _assert_control(self, account: ChecksumAddress, name: str,
335335
parent_owned: Optional[str] = None) -> None:
336-
if not address_in(account, self.web3.eth.accounts):
336+
if not address_in(account, self.w3.eth.accounts):
337337
raise UnauthorizedError(
338338
"in order to modify %r, you must control account %r, which owns %r" % (
339339
name, account, parent_owned or name
@@ -410,4 +410,4 @@ def _setup_reverse(
410410

411411
def _reverse_registrar(self) -> 'Contract':
412412
addr = self.ens.caller.owner(normal_name_to_hash(REVERSE_REGISTRAR_DOMAIN))
413-
return self.web3.eth.contract(address=addr, abi=abis.REVERSE_REGISTRAR)
413+
return self.w3.eth.contract(address=addr, abi=abis.REVERSE_REGISTRAR)

ethpm/_utils/chains.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
from web3 import Web3 # noqa: F401
3131

3232

33-
def get_genesis_block_hash(web3: "Web3") -> HexBytes:
34-
return web3.eth.get_block(BlockNumber(0))["hash"]
33+
def get_genesis_block_hash(w3: "Web3") -> HexBytes:
34+
return w3.eth.get_block(BlockNumber(0))["hash"]
3535

3636

3737
BLOCK = "block"

ethpm/contract.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(self, address: bytes, **kwargs: Any) -> None:
6060

6161
@classmethod
6262
def factory(
63-
cls, web3: "Web3", class_name: str = None, **kwargs: Any
63+
cls, w3: "Web3", class_name: str = None, **kwargs: Any
6464
) -> Contract:
6565
dep_link_refs = kwargs.get("unlinked_references")
6666
bytecode = kwargs.get("bytecode")
@@ -69,7 +69,7 @@ def factory(
6969
if not is_prelinked_bytecode(to_bytes(hexstr=bytecode), dep_link_refs):
7070
needs_bytecode_linking = True
7171
kwargs = assoc(kwargs, "needs_bytecode_linking", needs_bytecode_linking)
72-
return super(LinkableContract, cls).factory(web3, class_name, **kwargs)
72+
return super(LinkableContract, cls).factory(w3, class_name, **kwargs)
7373

7474
@classmethod
7575
def constructor(cls, *args: Any, **kwargs: Any) -> ContractConstructor:
@@ -98,7 +98,7 @@ def link_bytecode(cls, attr_dict: Dict[str, str]) -> Type["LinkableContract"]:
9898
cls.bytecode_runtime, cls.linked_references, attr_dict
9999
)
100100
linked_class = cls.factory(
101-
cls.web3, bytecode_runtime=runtime, bytecode=bytecode
101+
cls.w3, bytecode_runtime=runtime, bytecode=bytecode
102102
)
103103
if linked_class.needs_bytecode_linking:
104104
raise BytecodeLinkingError(

ethpm/uri.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ def create_latest_block_uri(w3: "Web3", from_blocks_ago: int = 3) -> URI:
120120

121121

122122
@curry
123-
def check_if_chain_matches_chain_uri(web3: "Web3", blockchain_uri: URI) -> bool:
123+
def check_if_chain_matches_chain_uri(w3: "Web3", blockchain_uri: URI) -> bool:
124124
chain_id, resource_type, resource_hash = parse_BIP122_uri(blockchain_uri)
125-
genesis_block = web3.eth.get_block("earliest")
125+
genesis_block = w3.eth.get_block("earliest")
126126

127127
if encode_hex(genesis_block["hash"]) != chain_id:
128128
return False
129129

130130
if resource_type == BLOCK:
131-
resource = web3.eth.get_block(resource_hash)
131+
resource = w3.eth.get_block(resource_hash)
132132
else:
133133
raise ValueError(f"Unsupported resource type: {resource_type}")
134134

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Audit ``.rst`` and ``.py`` files and convert all Web3 instance variable names to ``w3`` to avoid confusion with the ``web3`` module.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import pytest
22

33

4-
def test_admin_addPeer(web3, skip_if_testrpc):
5-
skip_if_testrpc(web3)
4+
def test_admin_addPeer(w3, skip_if_testrpc):
5+
skip_if_testrpc(w3)
66

77
with pytest.warns(DeprecationWarning):
8-
result = web3.geth.admin.addPeer(
8+
result = w3.geth.admin.addPeer(
99
'enode://44826a5d6a55f88a18298bca4773fca5749cdc3a5c9f308aa7d810e9b31123f3e7c5fba0b1d70aac5308426f47df2a128a6747040a3815cc7dd7167d03be320d@127.0.0.1:30304', # noqa: E501
1010
)
1111
assert result is True
1212

1313

14-
def test_admin_add_peer(web3, skip_if_testrpc):
15-
skip_if_testrpc(web3)
14+
def test_admin_add_peer(w3, skip_if_testrpc):
15+
skip_if_testrpc(w3)
1616

17-
result = web3.geth.admin.add_peer(
17+
result = w3.geth.admin.add_peer(
1818
'enode://44826a5d6a55f88a18298bca4773fca5749cdc3a5c9f308aa7d810e9b31123f3e7c5fba0b1d70aac5308426f47df2a128a6747040a3815cc7dd7167d03be320d@127.0.0.1:30304', # noqa: E501
1919
)
2020
assert result is True
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import pytest
22

33

4-
def test_admin_nodeInfo(web3, skip_if_testrpc):
5-
skip_if_testrpc(web3)
4+
def test_admin_nodeInfo(w3, skip_if_testrpc):
5+
skip_if_testrpc(w3)
66

77
with pytest.warns(DeprecationWarning):
8-
node_info = web3.geth.admin.nodeInfo
8+
node_info = w3.geth.admin.nodeInfo
99

1010
assert 'enode' in node_info
1111
assert 'id' in node_info
1212

1313

14-
def test_admin_node_info(web3, skip_if_testrpc):
15-
skip_if_testrpc(web3)
14+
def test_admin_node_info(w3, skip_if_testrpc):
15+
skip_if_testrpc(w3)
1616

17-
node_info = web3.geth.admin.node_info
17+
node_info = w3.geth.admin.node_info
1818

1919
assert 'enode' in node_info
2020
assert 'id' in node_info
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def test_admin_peers(web3, skip_if_testrpc):
2-
skip_if_testrpc(web3)
1+
def test_admin_peers(w3, skip_if_testrpc):
2+
skip_if_testrpc(w3)
33

4-
assert web3.geth.admin.peers == []
4+
assert w3.geth.admin.peers == []

0 commit comments

Comments
 (0)