From 60af300dc2af9a926e66873944c10f22967093f2 Mon Sep 17 00:00:00 2001 From: Keri Date: Wed, 13 Feb 2019 11:15:02 -0700 Subject: [PATCH] Use new NoABIFound error --- .../contracts/test_contract_call_interface.py | 3 ++- web3/contract.py | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/core/contracts/test_contract_call_interface.py b/tests/core/contracts/test_contract_call_interface.py index b65b59ad66..203324275d 100644 --- a/tests/core/contracts/test_contract_call_interface.py +++ b/tests/core/contracts/test_contract_call_interface.py @@ -24,6 +24,7 @@ BlockNumberOutofRange, InvalidAddress, MismatchedABI, + NoABIFound, NoABIFunctionsFound, ValidationError, ) @@ -527,7 +528,7 @@ def test_function_multiple_possible_encodings(web3): def test_function_no_abi(web3): contract = web3.eth.contract() - with pytest.raises(NoABIFunctionsFound): + with pytest.raises(NoABIFound): contract.functions.thisFunctionDoesNotExist().call() diff --git a/web3/contract.py b/web3/contract.py index 8298916471..40a5e332ad 100644 --- a/web3/contract.py +++ b/web3/contract.py @@ -106,8 +106,11 @@ class ContractFunctions: """ def __init__(self, abi, web3, address=None): - if abi: - self.abi = abi + self.abi = abi + self.web3 = web3 + self.address = address + + if self.abi: self._functions = filter_by_type('function', self.abi) for func in self._functions: setattr( @@ -115,9 +118,9 @@ def __init__(self, abi, web3, address=None): func['name'], ContractFunction.factory( func['name'], - web3=web3, + web3=self.web3, contract_abi=self.abi, - address=address, + address=self.address, function_identifier=func['name'])) def __iter__(self): @@ -128,6 +131,10 @@ def __iter__(self): yield func['name'] def __getattr__(self, function_name): + if self.abi is None: + raise NoABIFound( + "There is no ABI found for this contract.", + ) if '_functions' not in self.__dict__: raise NoABIFunctionsFound( "The abi for this contract contains no function definitions. ", @@ -1180,7 +1187,7 @@ def __init__(self, self.abi = abi self._functions = None - if abi: + if self.abi: if transaction is None: transaction = {}