diff --git a/raiden/network/proxies/secret_registry.py b/raiden/network/proxies/secret_registry.py index 52aa56c2265..dbdae614d8e 100644 --- a/raiden/network/proxies/secret_registry.py +++ b/raiden/network/proxies/secret_registry.py @@ -7,6 +7,7 @@ encode_hex, event_abi_to_log_topic, is_binary_address, + to_bytes, to_checksum_address, to_normalized_address, ) @@ -53,7 +54,9 @@ def __init__(self, jsonrpc_client, secret_registry_address, contract_manager: Co jsonrpc_client, secret_registry_address, CONTRACT_SECRET_REGISTRY, - expected_code=contract_manager.get_runtime_hexcode(CONTRACT_SECRET_REGISTRY), + expected_code=to_bytes( + hexstr=contract_manager.get_runtime_hexcode(CONTRACT_SECRET_REGISTRY) + ), ) proxy = jsonrpc_client.new_contract_proxy( diff --git a/raiden/network/proxies/service_registry.py b/raiden/network/proxies/service_registry.py index 9cf122d9e5e..77eba5387dc 100644 --- a/raiden/network/proxies/service_registry.py +++ b/raiden/network/proxies/service_registry.py @@ -2,7 +2,7 @@ import structlog import web3 -from eth_utils import is_binary_address, to_canonical_address, to_checksum_address +from eth_utils import is_binary_address, to_bytes, to_canonical_address, to_checksum_address from raiden.exceptions import BrokenPreconditionError, InvalidAddress, RaidenUnrecoverableError from raiden.network.proxies.utils import log_transaction @@ -30,7 +30,9 @@ def __init__( jsonrpc_client, service_registry_address, CONTRACT_SERVICE_REGISTRY, - expected_code=contract_manager.get_runtime_hexcode(CONTRACT_SERVICE_REGISTRY), + expected_code=to_bytes( + hexstr=contract_manager.get_runtime_hexcode(CONTRACT_SERVICE_REGISTRY) + ), ) proxy = jsonrpc_client.new_contract_proxy( diff --git a/raiden/network/proxies/token_network.py b/raiden/network/proxies/token_network.py index 024cb50fa58..73c66d45984 100644 --- a/raiden/network/proxies/token_network.py +++ b/raiden/network/proxies/token_network.py @@ -4,6 +4,7 @@ from eth_utils import ( encode_hex, is_binary_address, + to_bytes, to_canonical_address, to_checksum_address, to_hex, @@ -157,7 +158,9 @@ def __init__( jsonrpc_client, Address(token_network_address), CONTRACT_TOKEN_NETWORK, - expected_code=contract_manager.get_runtime_hexcode(CONTRACT_TOKEN_NETWORK), + expected_code=to_bytes( + hexstr=contract_manager.get_runtime_hexcode(CONTRACT_TOKEN_NETWORK) + ), ) self.contract_manager = contract_manager diff --git a/raiden/network/proxies/token_network_registry.py b/raiden/network/proxies/token_network_registry.py index 492db097292..fd39dbf8236 100644 --- a/raiden/network/proxies/token_network_registry.py +++ b/raiden/network/proxies/token_network_registry.py @@ -6,6 +6,7 @@ event_abi_to_log_topic, is_binary_address, is_same_address, + to_bytes, to_canonical_address, to_checksum_address, to_normalized_address, @@ -59,7 +60,9 @@ def __init__( client=jsonrpc_client, address=Address(registry_address), contract_name=CONTRACT_TOKEN_NETWORK_REGISTRY, - expected_code=contract_manager.get_runtime_hexcode(CONTRACT_TOKEN_NETWORK_REGISTRY), + expected_code=to_bytes( + hexstr=contract_manager.get_runtime_hexcode(CONTRACT_TOKEN_NETWORK_REGISTRY) + ), ) self.contract_manager = contract_manager diff --git a/raiden/network/proxies/user_deposit.py b/raiden/network/proxies/user_deposit.py index 31235bdf937..b42c2155253 100644 --- a/raiden/network/proxies/user_deposit.py +++ b/raiden/network/proxies/user_deposit.py @@ -1,6 +1,7 @@ import structlog from eth_utils import ( is_binary_address, + to_bytes, to_canonical_address, to_checksum_address, to_normalized_address, @@ -50,7 +51,9 @@ def __init__( jsonrpc_client, Address(user_deposit_address), CONTRACT_USER_DEPOSIT, - expected_code=contract_manager.get_runtime_hexcode(CONTRACT_USER_DEPOSIT), + expected_code=to_bytes( + hexstr=contract_manager.get_runtime_hexcode(CONTRACT_USER_DEPOSIT) + ), ) self.client = jsonrpc_client diff --git a/raiden/network/rpc/client.py b/raiden/network/rpc/client.py index dc87b6e9c9a..d66d9a94c3b 100644 --- a/raiden/network/rpc/client.py +++ b/raiden/network/rpc/client.py @@ -168,26 +168,27 @@ def geth_discover_next_available_nonce(web3: Web3, address: AddressHex) -> Nonce def check_address_has_code( - client: "JSONRPCClient", address: Address, contract_name: str = "", expected_code: str = None + client: "JSONRPCClient", address: Address, contract_name: str = "", expected_code: bytes = None ): """ Checks that the given address contains code. """ result = client.web3.eth.getCode(to_checksum_address(address), "latest") - if not result: + def formatted_contract_name(): if contract_name: - formated_contract_name = f"[{contract_name}]: " + return f"[{contract_name}]: " else: - formated_contract_name = "" + return "" + if not result: raise AddressWithoutCode( "{}Address {} does not contain code".format( - formated_contract_name, to_checksum_address(address) + formatted_contract_name(), to_checksum_address(address) ) ) if expected_code is not None and result != expected_code: raise ContractCodeMismatch( - f"{formated_contract_name}Address {to_checksum_address(address)} has wrong code." + f"{formatted_contract_name()}Address {to_checksum_address(address)} has wrong code." )