mirror of https://github.com/nucypher/nucypher.git
Improve error types raised by Return Values
parent
0e185438aa
commit
656ff8071c
|
@ -133,7 +133,7 @@ def evaluate_conditions(
|
|||
except ReturnValueEvaluationError as e:
|
||||
error = (
|
||||
f"Unable to evaluate return value: {e}",
|
||||
HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
)
|
||||
except InvalidCondition as e:
|
||||
error = (
|
||||
|
|
|
@ -55,7 +55,7 @@ def _resolve_abi(
|
|||
"""Resolves the contract an/or function ABI from a standard contract name"""
|
||||
|
||||
if not (function_abi or standard_contract_type):
|
||||
raise ReencryptionCondition.InvalidCondition(
|
||||
raise InvalidCondition(
|
||||
f"Ambiguous ABI - Supply either an ABI or a standard contract type ({STANDARD_ABI_CONTRACT_TYPES})."
|
||||
)
|
||||
|
||||
|
@ -73,7 +73,7 @@ def _resolve_abi(
|
|||
# Will raise a ValueError if there is not exactly one match.
|
||||
function_abi = w3.eth.contract(abi=contract_abi).get_function_by_name(method).abi
|
||||
except ValueError as e:
|
||||
raise ReencryptionCondition.InvalidCondition(str(e))
|
||||
raise InvalidCondition(str(e))
|
||||
|
||||
if not function_abi:
|
||||
raise InvalidCondition(f"No function ABI supplied for '{method}'")
|
||||
|
|
|
@ -100,7 +100,7 @@ def test_invalid_contract_condition():
|
|||
)
|
||||
|
||||
# method not in ABI
|
||||
with pytest.raises(ReencryptionCondition.InvalidCondition):
|
||||
with pytest.raises(InvalidCondition):
|
||||
_ = ContractCondition(
|
||||
contract_address="0xaDD9D957170dF6F33982001E4c22eCCdd5539118",
|
||||
method="getPolicy",
|
||||
|
|
|
@ -20,6 +20,7 @@ import random
|
|||
|
||||
import pytest
|
||||
|
||||
from nucypher.policy.conditions.exceptions import ReturnValueEvaluationError
|
||||
from nucypher.policy.conditions.lingo import ReturnValueTest
|
||||
|
||||
|
||||
|
@ -28,14 +29,14 @@ def test_return_value_key():
|
|||
assert test.eval({"james": 1})
|
||||
assert not test.eval({"james": -1})
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
with pytest.raises(ReturnValueEvaluationError):
|
||||
test.eval({"bond": 1})
|
||||
|
||||
test = ReturnValueTest(comparator=">", value="0", key=4)
|
||||
assert test.eval({4: 1})
|
||||
assert not test.eval({4: -1})
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
with pytest.raises(ReturnValueEvaluationError):
|
||||
test.eval({5: 1})
|
||||
|
||||
|
||||
|
@ -47,7 +48,7 @@ def test_return_value_index():
|
|||
test = ReturnValueTest(comparator="==", value='"james"', key=3)
|
||||
assert test.eval([0, 1, 2, '"james"'])
|
||||
|
||||
with pytest.raises(IndexError):
|
||||
with pytest.raises(ReturnValueEvaluationError):
|
||||
test.eval([0, 1, 2])
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue