From efcbb7ae435bfc0d059341063011ed52cbd81d0b Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Mon, 23 Sep 2019 16:34:14 +0200 Subject: [PATCH] Raise BrokenPreconditionError on invalid inputs because the caller of the proxy should have checked these inputs. The documentation for BrokenPreconditionError clearly says ``` class BrokenPreconditionError(RaidenError): """ Raised while checking transaction preconditions which should be satisfied before sending the transaction. This exception when: 1. An assert or a revert in the smart contract would be hit for triggering block. 2. If provided values are invalid (i.e ValueError) """ ``` So, when the provided values are invalid, BrokenPreconditionError should be raised. --- raiden/exceptions.py | 12 ------------ raiden/network/proxies/token_network_registry.py | 9 +++------ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/raiden/exceptions.py b/raiden/exceptions.py index bc007d4935..dc33fe25b4 100644 --- a/raiden/exceptions.py +++ b/raiden/exceptions.py @@ -161,18 +161,6 @@ class InvalidTokenAddress(RaidenError): """ Raised if the token address is invalid """ -class InvalidTokenNetworkDepositLimit(RaidenError): - """ Raised when an invalid token network deposit - limit is passed to the token network registry proxy. - """ - - -class InvalidChannelParticipantDepositLimit(RaidenError): - """ Raised when an invalid channel participant - deposit limit is passed to the token network registry proxy. - """ - - class STUNUnavailableException(RaidenError): pass diff --git a/raiden/network/proxies/token_network_registry.py b/raiden/network/proxies/token_network_registry.py index 5922c6eb03..b89770ec8f 100644 --- a/raiden/network/proxies/token_network_registry.py +++ b/raiden/network/proxies/token_network_registry.py @@ -14,10 +14,7 @@ from raiden.constants import NULL_ADDRESS, NULL_ADDRESS_BYTES from raiden.exceptions import ( BrokenPreconditionError, - InvalidChannelParticipantDepositLimit, InvalidToken, - InvalidTokenAddress, - InvalidTokenNetworkDepositLimit, RaidenRecoverableError, RaidenUnrecoverableError, ) @@ -113,15 +110,15 @@ def add_token( ) if token_address == NULL_ADDRESS_BYTES: - raise InvalidTokenAddress("The call to register a token at 0x00..00 will fail.") + raise BrokenPreconditionError("The call to register a token at 0x00..00 will fail.") if token_network_deposit_limit <= 0: - raise InvalidTokenNetworkDepositLimit( + raise BrokenPreconditionError( f"Token network deposit limit of {token_network_deposit_limit} is invalid" ) if channel_participant_deposit_limit > token_network_deposit_limit: - raise InvalidChannelParticipantDepositLimit( + raise BrokenPreconditionError( f"Channel participant deposit limit of " f"{channel_participant_deposit_limit} is invalid" )