Skip to content

Commit

Permalink
Fix a whole bunch of deprecation warnings
Browse files Browse the repository at this point in the history
We had accrued a big bunch of deprecation warnings (which usually
showed up when running the tests) which would cause breakage in future
Python versions.

This upgrades packages as necessary and fixes most warnings.
The remaining ones are being tracked here:

- raiden-network/raiden-api-client#1
- matrix-org/synapse#9641
- matrix-org/synapse#9642
- slezica/python-frozendict#25

This also temporarily removes the docs requirements from the dev set
since there's a conflict between `releases` and `py-solc-x` pinned
versions of `semantic-version`. See: bitprophet/releases#94
  • Loading branch information
ulope committed Mar 23, 2021
1 parent b56e7a3 commit a7a401a
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 302 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Expand Up @@ -343,6 +343,9 @@ jobs:
- conditional-skip
- config-path

- run:
name: Install docs requirements
command: pip-sync requirements/requirements-docs.txt
- run:
name: Build documentation
command: make docs
Expand Down
36 changes: 18 additions & 18 deletions raiden/network/rpc/client.py
Expand Up @@ -236,7 +236,7 @@ def geth_assert_rpc_interfaces(web3: Web3) -> None:
)

try:
web3.eth.blockNumber
web3.eth.block_number
except ValueError:
raise EthNodeInterfaceError(
"The underlying geth node does not have the eth rpc interface "
Expand All @@ -262,7 +262,7 @@ def parity_assert_rpc_interfaces(web3: Web3) -> None:
)

try:
web3.eth.blockNumber
web3.eth.block_number
except ValueError:
raise EthNodeInterfaceError(
"The underlying parity node does not have the eth rpc interface "
Expand Down Expand Up @@ -296,7 +296,7 @@ def parity_discover_next_available_nonce(web3: Web3, address: Address) -> Nonce:

def geth_discover_next_available_nonce(web3: Web3, address: Address) -> Nonce:
"""Returns the next available nonce for `address`."""
return web3.eth.getTransactionCount(address, BLOCK_ID_PENDING)
return web3.eth.get_transaction_count(address, BLOCK_ID_PENDING)


def discover_next_available_nonce(web3: Web3, eth_node: EthClient, address: Address) -> Nonce:
Expand Down Expand Up @@ -361,7 +361,7 @@ def check_address_has_code(
block_hash = encode_hex(given_block_identifier)
given_block_identifier = client.web3.eth.getBlock(block_hash)["number"]

result = client.web3.eth.getCode(address, given_block_identifier)
result = client.web3.eth.get_code(address, given_block_identifier)

if not result:
# The error message is printed to the user from ui/cli.py. Make sure it
Expand Down Expand Up @@ -584,8 +584,8 @@ def patched_web3_eth_estimate_gas(
Current master of web3.py has this implementation already:
https://github.com/ethereum/web3.py/blob/2a67ea9f0ab40bb80af2b803dce742d6cad5943e/web3/eth.py#L311
"""
if "from" not in transaction and is_checksum_address(self.defaultAccount):
transaction = assoc(transaction, "from", self.defaultAccount)
if "from" not in transaction and is_checksum_address(self.default_account):
transaction = assoc(transaction, "from", self.default_account)

if block_identifier is None:
params: List[Any] = [transaction]
Expand All @@ -609,8 +609,8 @@ def patched_web3_eth_estimate_gas(
def patched_web3_eth_call(
self: Any, transaction: Dict[str, Any], block_identifier: BlockIdentifier = None
) -> HexBytes:
if "from" not in transaction and is_checksum_address(self.defaultAccount):
transaction = assoc(transaction, "from", self.defaultAccount)
if "from" not in transaction and is_checksum_address(self.default_account):
transaction = assoc(transaction, "from", self.default_account)

if block_identifier is None:
block_identifier = self.defaultBlock
Expand Down Expand Up @@ -680,8 +680,8 @@ def patched_contractfunction_estimateGas(

if self.address:
estimate_gas_transaction.setdefault("to", self.address)
if self.web3.eth.defaultAccount is not empty:
estimate_gas_transaction.setdefault("from", self.web3.eth.defaultAccount)
if self.web3.eth.default_account is not empty:
estimate_gas_transaction.setdefault("from", self.web3.eth.default_account)

if "to" not in estimate_gas_transaction:
if isinstance(self, type):
Expand Down Expand Up @@ -1043,7 +1043,7 @@ def __init__(
if eth_node is None or supported is VersionSupport.UNSUPPORTED:
raise EthNodeInterfaceError(f'Unsupported Ethereum client "{version}"')
if supported is VersionSupport.WARN:
log.warn(f'Unsupported Ethereum client version "{version}"')
log.warning(f'Unsupported Ethereum client version "{version}"')

address = privatekey_to_address(privkey)
available_nonce = discover_next_available_nonce(web3, eth_node, address)
Expand All @@ -1055,7 +1055,7 @@ def __init__(
self.default_block_num_confirmations = block_num_confirmations

# Ask for the chain id only once and store it here
self.chain_id = ChainID(self.web3.eth.chainId)
self.chain_id = ChainID(self.web3.eth.chain_id)

self._available_nonce = available_nonce
self._nonce_lock = Semaphore()
Expand All @@ -1076,7 +1076,7 @@ def __repr__(self) -> str:

def block_number(self) -> BlockNumber:
""" Return the most recent block. """
return self.web3.eth.blockNumber
return self.web3.eth.block_number

def get_block(self, block_identifier: BlockIdentifier) -> BlockData:
"""Given a block number, query the chain to get its corresponding block hash"""
Expand All @@ -1085,7 +1085,7 @@ def get_block(self, block_identifier: BlockIdentifier) -> BlockData:
def get_confirmed_blockhash(self) -> BlockHash:
""" Gets the block CONFIRMATION_BLOCKS in the past and returns its block hash """
confirmed_block_number = BlockNumber(
self.web3.eth.blockNumber - self.default_block_num_confirmations
self.web3.eth.block_number - self.default_block_num_confirmations
)
if confirmed_block_number < 0:
confirmed_block_number = BlockNumber(0)
Expand Down Expand Up @@ -1113,7 +1113,7 @@ def can_query_state_for_block(self, block_identifier: BlockIdentifier) -> bool:
# FIXME: shouldn't return `TokenAmount`
def balance(self, account: Address) -> TokenAmount:
""" Return the balance of the account of the given address. """
return TokenAmount(self.web3.eth.getBalance(account, BLOCK_ID_PENDING))
return TokenAmount(self.web3.eth.get_balance(account, BLOCK_ID_PENDING))

def parity_get_pending_transaction_hash_by_nonce(
self, address: AddressHex, nonce: Nonce
Expand Down Expand Up @@ -1328,7 +1328,7 @@ def to_log_details(self) -> Dict[str, Any]:
signed_txn = client.web3.eth.account.sign_transaction(
transaction_data, client.privkey
)
tx_hash = client.web3.eth.sendRawTransaction(signed_txn.rawTransaction)
tx_hash = client.web3.eth.send_raw_transaction(signed_txn.rawTransaction)

# Increase the `nonce` only after sending the transaction. This
# is necessary because the send itself can fail, e.g. because
Expand Down Expand Up @@ -1454,7 +1454,7 @@ def deploy_single_contract(
f"compiler bug."
)

deployed_code = self.web3.eth.getCode(contract_address)
deployed_code = self.web3.eth.get_code(contract_address)

if not deployed_code:
raise RaidenUnrecoverableError(
Expand Down Expand Up @@ -1582,7 +1582,7 @@ def check_for_insufficient_eth(
return

our_address = to_checksum_address(self.address)
balance = self.web3.eth.getBalance(our_address, block_identifier)
balance = self.web3.eth.get_balance(our_address, block_identifier)
required_balance = required_gas * gas_price_for_fast_transaction(self.web3)
if balance < required_balance:
msg = f"Failed to execute {transaction_name} due to insufficient ETH"
Expand Down
2 changes: 1 addition & 1 deletion raiden/tasks.py
Expand Up @@ -125,7 +125,7 @@ def check_rdn_deposits(
def check_chain_id(chain_id: ChainID, web3: Web3) -> None: # pragma: no unittest
""" Check periodically if the underlying ethereum client's network id has changed"""
while True:
current_id = web3.eth.chainId
current_id = web3.eth.chain_id
if chain_id != current_id:
raise RuntimeError(
f"Raiden was running on network with id {chain_id} and it detected "
Expand Down
2 changes: 1 addition & 1 deletion raiden/tests/conftest.py
Expand Up @@ -75,7 +75,7 @@ def pytest_addoption(parser):
"--base-port",
action="store",
default=8500,
type="int",
type=int,
help="Base port number to use for tests.",
)

Expand Down
2 changes: 1 addition & 1 deletion raiden/tests/integration/api/rest/test_api_wrapper.py
Expand Up @@ -43,7 +43,7 @@ def test_api_wrapper(raiden_network, unregistered_custom_token, retry_timeout):
resp = wrapper.register_token(token=token)
# The token network address will be needed for a later test
token_network_address = resp.token_network_address
assert app0.rpc_client.web3.eth.getCode(resp.token_network_address)
assert app0.rpc_client.web3.eth.get_code(resp.token_network_address)

# Test channel opening
resp = wrapper.open_channel(partner=address2, token=token, deposit=2)
Expand Down
2 changes: 1 addition & 1 deletion raiden/tests/integration/api/test_pythonapi.py
Expand Up @@ -566,7 +566,7 @@ def test_token_addresses(raiden_network: List[RaidenService], token_addresses):
last_number = app0.rpc_client.block_number()

for block_number in range(last_number, 0, -1):
code = app0.rpc_client.web3.eth.getCode(
code = app0.rpc_client.web3.eth.get_code(
account=Address(token_network_address), block_identifier=block_number
)
if code == b"":
Expand Down
2 changes: 1 addition & 1 deletion raiden/tests/integration/fixtures/smartcontracts.py
Expand Up @@ -133,7 +133,7 @@ def register_token(
token_address=TokenAddress(to_canonical_address(token_contract.address)),
channel_participant_deposit_limit=RED_EYES_PER_CHANNEL_PARTICIPANT_LIMIT,
token_network_deposit_limit=RED_EYES_PER_TOKEN_NETWORK_LIMIT,
given_block_identifier=token_contract.web3.eth.blockNumber,
given_block_identifier=token_contract.web3.eth.block_number,
)
return token_network_address

Expand Down
10 changes: 5 additions & 5 deletions raiden/tests/integration/network/proxies/test_payment_channel.py
Expand Up @@ -71,7 +71,7 @@ def test_payment_channel_proxy_basics(
token_network_proxy = proxy_manager.token_network(
address=token_network_address, block_identifier=BLOCK_ID_LATEST
)
start_block = web3.eth.blockNumber
start_block = web3.eth.block_number

channel_details = token_network_proxy.new_netting_channel(
partner=partner,
Expand Down Expand Up @@ -121,12 +121,12 @@ def test_payment_channel_proxy_basics(
netting_channel_identifier=channel_proxy_1.channel_identifier,
contract_manager=contract_manager,
from_block=start_block,
to_block=web3.eth.blockNumber,
to_block=web3.eth.block_number,
)

assert len(channel_events) == 2

block_before_close = web3.eth.blockNumber
block_before_close = web3.eth.block_number
empty_balance_proof = BalanceProof(
channel_identifier=channel_proxy_1.channel_identifier,
token_network_address=token_network_address,
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_payment_channel_proxy_basics(
netting_channel_identifier=channel_proxy_1.channel_identifier,
contract_manager=contract_manager,
from_block=start_block,
to_block=web3.eth.blockNumber,
to_block=web3.eth.block_number,
)
assert len(channel_events) == 3

Expand Down Expand Up @@ -186,7 +186,7 @@ def test_payment_channel_proxy_basics(
netting_channel_identifier=channel_proxy_1.channel_identifier,
contract_manager=contract_manager,
from_block=start_block,
to_block=web3.eth.blockNumber,
to_block=web3.eth.block_number,
)
assert len(channel_events) == 4

Expand Down
Expand Up @@ -760,7 +760,7 @@ def test_query_pruned_state(token_network_proxy, private_keys, web3, contract_ma
partner=c2_client.address, settle_timeout=10, given_block_identifier=BLOCK_ID_LATEST
)
channel_identifier = channel_details.channel_identifier
block = c1_client.web3.eth.getBlock(BLOCK_ID_LATEST)
block = c1_client.web3.eth.get_block(BLOCK_ID_LATEST)
block_number = int(block["number"])
block_hash = bytes(block["hash"])
channel_id = c1_token_network_proxy.get_channel_identifier(
Expand Down
Expand Up @@ -36,7 +36,7 @@ def send_transaction() -> TransactionMined:
first_receipt = send_transaction().receipt
mined_block_number = first_receipt["blockNumber"]

while mined_block_number + 127 > web3.eth.blockNumber:
while mined_block_number + 127 > web3.eth.block_number:
gevent.sleep(0.5)

# geth keeps the latest 128 blocks before pruning. Unfortunately, this can
Expand Down Expand Up @@ -86,7 +86,7 @@ def send_transaction() -> TransactionMined:
first_receipt = send_transaction().receipt
mined_block_number = first_receipt["blockNumber"]

while mined_block_number + 127 > web3.eth.blockNumber:
while mined_block_number + 127 > web3.eth.block_number:
gevent.sleep(0.5)

# geth keeps the latest 128 blocks before pruning. Unfortunately, this can
Expand All @@ -103,7 +103,7 @@ def send_transaction() -> TransactionMined:
with pytest.raises(ValueError):
contract_proxy.functions.const().call(block_identifier=pruned_block_number)

latest_confirmed_block = deploy_client.web3.eth.getBlock(pruned_block_number)
latest_confirmed_block = deploy_client.web3.eth.get_block(pruned_block_number)

msg = (
"getBlock did not return the expected metadata for a pruned block "
Expand Down
Expand Up @@ -84,7 +84,7 @@ def send_transaction() -> TransactionMined:
with pytest.raises(ValueError):
contract_proxy.functions.const().call(block_identifier=pruned_block_number)

latest_confirmed_block = deploy_client.web3.eth.getBlock(pruned_block_number)
latest_confirmed_block = deploy_client.web3.eth.get_block(pruned_block_number)

msg = (
"getBlock did not return the expected metadata for a pruned block "
Expand Down
Expand Up @@ -12,7 +12,7 @@ def test_call_invalid_selector(deploy_client: JSONRPCClient) -> None:
"""
contract_proxy, _ = deploy_rpc_test_contract(deploy_client, "RpcTest")
address = contract_proxy.address
assert len(deploy_client.web3.eth.getCode(address)) > 0
assert len(deploy_client.web3.eth.get_code(address)) > 0

data = decode_hex(get_transaction_data(deploy_client.web3, contract_proxy.abi, "ret", None))
next_byte = chr(data[0] + 1).encode()
Expand All @@ -27,7 +27,7 @@ def test_call_inexisting_address(deploy_client: JSONRPCClient) -> None:

inexisting_address = b"\x01\x02\x03\x04\x05" * 4

assert len(deploy_client.web3.eth.getCode(inexisting_address)) == 0
assert len(deploy_client.web3.eth.get_code(inexisting_address)) == 0
transaction = {
"from": deploy_client.address,
"to": inexisting_address,
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_call_throws(deploy_client: JSONRPCClient) -> None:
contract_proxy, _ = deploy_rpc_test_contract(deploy_client, "RpcTest")

address = contract_proxy.address
assert len(deploy_client.web3.eth.getCode(address)) > 0
assert len(deploy_client.web3.eth.get_code(address)) > 0

call = contract_proxy.functions.fail_assert().call
assert call() == []
Expand Down
Expand Up @@ -49,8 +49,8 @@ def test_events_can_happen_in_the_deployment_block(web3: Web3, deploy_key: bytes
deploy_signed_txn = web3.eth.account.sign_transaction(deploy_transaction_data, deploy_key)
call_signed_txn = web3.eth.account.sign_transaction(call_transaction_data, deploy_key)

deploy_tx_hash = web3.eth.sendRawTransaction(deploy_signed_txn.rawTransaction)
call_tx_hash = web3.eth.sendRawTransaction(call_signed_txn.rawTransaction)
deploy_tx_hash = web3.eth.send_raw_transaction(deploy_signed_txn.rawTransaction)
call_tx_hash = web3.eth.send_raw_transaction(call_signed_txn.rawTransaction)

while True:
try:
Expand Down
Expand Up @@ -12,7 +12,7 @@ def test_estimate_gas_fail(deploy_client: JSONRPCClient) -> None:
contract_proxy, _ = deploy_rpc_test_contract(deploy_client, "RpcTest")

address = contract_proxy.address
assert len(deploy_client.web3.eth.getCode(address)) > 0
assert len(deploy_client.web3.eth.get_code(address)) > 0

msg = "Estimate gas should return None if the transaction hit an assert"
assert deploy_client.estimate_gas(contract_proxy, "fail_assert", {}) is None, msg
Expand Down
Expand Up @@ -44,7 +44,7 @@ def test_resending_pending_transaction_raises(deploy_client: JSONRPCClient) -> N
contract_proxy, _ = deploy_rpc_test_contract(deploy_client, "RpcTest")

address = contract_proxy.address
assert len(deploy_client.web3.eth.getCode(address)) > 0
assert len(deploy_client.web3.eth.get_code(address)) > 0

# Create a new instance of the JSONRPCClient, this will store the current available nonce
client_invalid_nonce = JSONRPCClient(web3=deploy_client.web3, privkey=deploy_client.privkey)
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_resending_mined_transaction_raises(deploy_client: JSONRPCClient) -> Non
contract_proxy, _ = deploy_rpc_test_contract(deploy_client, "RpcTest")

address = contract_proxy.address
assert len(deploy_client.web3.eth.getCode(address)) > 0
assert len(deploy_client.web3.eth.get_code(address)) > 0

# Create a new instance of the JSONRPCClient, this will store the current available nonce
client_invalid_nonce = JSONRPCClient(deploy_client.web3, deploy_client.privkey)
Expand Down Expand Up @@ -150,7 +150,7 @@ def test_local_transaction_with_zero_gasprice_is_mined(deploy_client: JSONRPCCli
)

address = normal_gas_proxy.address
assert len(deploy_client.web3.eth.getCode(address)) > 0
assert len(deploy_client.web3.eth.get_code(address)) > 0

estimated_transaction = deploy_client.estimate_gas(zero_gas_proxy, "ret", {})
assert estimated_transaction, "Gas estimation should not fail here"
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_remote_transaction_with_zero_gasprice_is_not_mined(
)

address = normal_gas_proxy.address
assert len(client.web3.eth.getCode(address)) > 0
assert len(client.web3.eth.get_code(address)) > 0

estimated_transaction = client.estimate_gas(zero_gas_proxy, "ret", {})
assert estimated_transaction, "Gas estimation should not fail here"
Expand Down Expand Up @@ -258,7 +258,7 @@ def test_resending_pending_transaction_with_lower_gas_raises(deploy_client: JSON
contract_proxy, _ = deploy_rpc_test_contract(deploy_client, "RpcTest")

address = contract_proxy.address
assert len(deploy_client.web3.eth.getCode(address)) > 0
assert len(deploy_client.web3.eth.get_code(address)) > 0

client_invalid_nonce = JSONRPCClient(web3=deploy_client.web3, privkey=deploy_client.privkey)

Expand Down Expand Up @@ -293,7 +293,7 @@ def test_reusing_nonce_with_lower_gas_raises(deploy_client: JSONRPCClient) -> No
contract_proxy, _ = deploy_rpc_test_contract(deploy_client, "RpcTest")

address = contract_proxy.address
assert len(deploy_client.web3.eth.getCode(address)) > 0
assert len(deploy_client.web3.eth.get_code(address)) > 0

client_invalid_nonce = JSONRPCClient(web3=deploy_client.web3, privkey=deploy_client.privkey)

Expand Down

0 comments on commit a7a401a

Please sign in to comment.