Skip to content

Commit

Permalink
Fix the smoketests
Browse files Browse the repository at this point in the history
  • Loading branch information
pirapira committed Jul 2, 2019
1 parent 7836a4f commit 2c9378c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 70 deletions.
4 changes: 2 additions & 2 deletions raiden/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ class DuplicatedChannelError(RaidenRecoverableError):
"""Raised if someone tries to create a channel that already exists."""


class ContractVersionMismatch(RaidenError):
"""Raised if deployed version of the contract differs."""
class ContractCodeMismatch(RaidenError):
"""Raised if the onchain code of the contract differs."""


class TransactionThrew(RaidenError):
Expand Down
10 changes: 3 additions & 7 deletions raiden/network/proxies/secret_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
RaidenRecoverableError,
RaidenUnrecoverableError,
)
from raiden.network.proxies.utils import compare_contract_versions, log_transaction
from raiden.network.proxies.utils import log_transaction
from raiden.network.rpc.client import StatelessFilter, check_address_has_code
from raiden.utils import safe_gas_limit
from raiden.utils.typing import (
Expand Down Expand Up @@ -58,12 +58,8 @@ def __init__(self, jsonrpc_client, secret_registry_address, contract_manager: Co

# There should be only one smart contract deployed, to avoid race
# conditions for on-chain unlocks.
compare_contract_versions(
proxy=proxy,
expected_version=contract_manager.contracts_version,
contract_name=CONTRACT_SECRET_REGISTRY,
address=secret_registry_address,
)

# TODO: check what's onchain

self.address = secret_registry_address
self.proxy = proxy
Expand Down
9 changes: 2 additions & 7 deletions raiden/network/proxies/service_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from eth_utils import is_binary_address, to_canonical_address, to_checksum_address

from raiden.exceptions import BrokenPreconditionError, InvalidAddress, RaidenUnrecoverableError
from raiden.network.proxies.utils import compare_contract_versions, log_transaction
from raiden.network.proxies.utils import log_transaction
from raiden.network.rpc.client import JSONRPCClient, check_address_has_code
from raiden.network.rpc.transactions import check_transaction_threw
from raiden.utils.typing import Address, AddressHex, BlockSpecification, Optional
Expand Down Expand Up @@ -33,12 +33,7 @@ def __init__(
to_canonical_address(service_registry_address),
)

compare_contract_versions(
proxy=proxy,
expected_version=contract_manager.contracts_version,
contract_name=CONTRACT_SERVICE_REGISTRY,
address=service_registry_address,
)
# TODO: check what's onchain

self.address = service_registry_address
self.proxy = proxy
Expand Down
9 changes: 2 additions & 7 deletions raiden/network/proxies/token_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
WithdrawMismatch,
)
from raiden.network.proxies.token import Token
from raiden.network.proxies.utils import compare_contract_versions, log_transaction
from raiden.network.proxies.utils import log_transaction
from raiden.network.rpc.client import StatelessFilter, check_address_has_code
from raiden.network.rpc.transactions import check_transaction_threw
from raiden.transfer.channel import compute_locksroot
Expand Down Expand Up @@ -163,12 +163,7 @@ def __init__(
to_normalized_address(token_network_address),
)

compare_contract_versions(
proxy=proxy,
expected_version=contract_manager.contracts_version,
contract_name=CONTRACT_TOKEN_NETWORK,
address=Address(token_network_address),
)
# TODO: check what's onchain

self.gas_measurements = gas_measurements(self.contract_manager.contracts_version)

Expand Down
9 changes: 2 additions & 7 deletions raiden/network/proxies/token_network_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
RaidenRecoverableError,
RaidenUnrecoverableError,
)
from raiden.network.proxies.utils import compare_contract_versions, log_transaction
from raiden.network.proxies.utils import log_transaction
from raiden.network.rpc.client import StatelessFilter, check_address_has_code
from raiden.network.rpc.transactions import check_transaction_threw
from raiden.utils import safe_gas_limit
Expand Down Expand Up @@ -67,12 +67,7 @@ def __init__(
to_normalized_address(registry_address),
)

compare_contract_versions(
proxy=proxy,
expected_version=contract_manager.contracts_version,
contract_name=CONTRACT_TOKEN_NETWORK_REGISTRY,
address=Address(registry_address),
)
# TODO: check what's onchain

self.gas_measurements = gas_measurements(self.contract_manager.contracts_version)

Expand Down
30 changes: 0 additions & 30 deletions raiden/network/proxies/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from contextlib import contextmanager
from typing import TYPE_CHECKING

from eth_utils import to_normalized_address
from structlog import BoundLoggerBase
from web3.exceptions import BadFunctionCallOutput

from raiden.exceptions import AddressWrongContract, ContractVersionMismatch
from raiden.network.rpc.smartcontract_proxy import ContractProxy
from raiden.transfer.identifiers import CanonicalIdentifier
from raiden.utils.typing import Address, Any, BlockSpecification, Dict, Generator, Locksroot, Tuple

Expand All @@ -15,32 +11,6 @@
from raiden.network.blockchain_service import BlockChainService


def compare_contract_versions(
proxy: ContractProxy, expected_version: str, contract_name: str, address: Address
) -> None:
"""Compare version strings of a contract.
If not matching raise ContractVersionMismatch. Also may raise AddressWrongContract
if the contract contains no code."""
assert isinstance(expected_version, str)
try:
deployed_version = proxy.contract.functions.contract_version().call()
except BadFunctionCallOutput:
raise AddressWrongContract("")

deployed_version = deployed_version.replace("_", "0")
expected_version = expected_version.replace("_", "0")

deployed = [int(x) for x in deployed_version.split(".")]
expected = [int(x) for x in expected_version.split(".")]

if deployed != expected:
raise ContractVersionMismatch(
f"Provided {contract_name} contract ({to_normalized_address(address)}) "
f"version mismatch. Expected: {expected_version} Got: {deployed_version}"
)


def get_onchain_locksroots(
chain: "BlockChainService",
canonical_identifier: CanonicalIdentifier,
Expand Down
20 changes: 10 additions & 10 deletions raiden/ui/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from eth_utils import to_canonical_address, to_checksum_address

from raiden.constants import Environment, RoutingMode
from raiden.exceptions import AddressWithoutCode, AddressWrongContract, ContractVersionMismatch
from raiden.exceptions import AddressWithoutCode, AddressWrongContract, ContractCodeMismatch
from raiden.network.blockchain_service import BlockChainService
from raiden.network.pathfinding import PFSConfig, configure_pfs_or_exit
from raiden.network.proxies.secret_registry import SecretRegistry
Expand Down Expand Up @@ -80,7 +80,7 @@ def setup_contracts_or_exit(config: Dict[str, Any], network_id: ChainID) -> Dict
return contracts


def handle_contract_version_mismatch(mismatch_exception: ContractVersionMismatch) -> None:
def handle_contract_code_mismatch(mismatch_exception: ContractCodeMismatch) -> None:
click.secho(f"{str(mismatch_exception)}. Please update your Raiden installation.", fg="red")
sys.exit(1)

Expand Down Expand Up @@ -147,8 +147,8 @@ def setup_proxies_or_exit(
contracts[CONTRACT_TOKEN_NETWORK_REGISTRY]["address"]
)
token_network_registry = blockchain_service.token_network_registry(registered_address)
except ContractVersionMismatch as e:
handle_contract_version_mismatch(e)
except ContractCodeMismatch as e:
handle_contract_code_mismatch(e)
except AddressWithoutCode:
handle_contract_no_code("token network registry", tokennetwork_registry_contract_address)
except AddressWrongContract:
Expand All @@ -161,8 +161,8 @@ def setup_proxies_or_exit(
secret_registry_contract_address
or to_canonical_address(contracts[CONTRACT_SECRET_REGISTRY]["address"])
)
except ContractVersionMismatch as e:
handle_contract_version_mismatch(e)
except ContractCodeMismatch as e:
handle_contract_code_mismatch(e)
except AddressWithoutCode:
handle_contract_no_code("secret registry", secret_registry_contract_address)
except AddressWrongContract:
Expand All @@ -186,8 +186,8 @@ def setup_proxies_or_exit(
user_deposit_contract_address
or to_canonical_address(contracts[CONTRACT_USER_DEPOSIT]["address"])
)
except ContractVersionMismatch as e:
handle_contract_version_mismatch(e)
except ContractCodeMismatch as e:
handle_contract_code_mismatch(e)
except AddressWithoutCode:
handle_contract_no_code("user deposit", user_deposit_contract_address)
except AddressWrongContract:
Expand All @@ -200,8 +200,8 @@ def setup_proxies_or_exit(
service_registry_contract_address
or to_canonical_address(contracts[CONTRACT_SERVICE_REGISTRY]["address"])
)
except ContractVersionMismatch as e:
handle_contract_version_mismatch(e)
except ContractCodeMismatch as e:
handle_contract_code_mismatch(e)
except AddressWithoutCode:
handle_contract_no_code("service registry", service_registry_contract_address)
except AddressWrongContract:
Expand Down

0 comments on commit 2c9378c

Please sign in to comment.