Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new NoABIFound error #1243

Merged
merged 1 commit into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/core/contracts/test_contract_call_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
BlockNumberOutofRange,
InvalidAddress,
MismatchedABI,
NoABIFound,
NoABIFunctionsFound,
ValidationError,
)
Expand Down Expand Up @@ -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()


Expand Down
17 changes: 12 additions & 5 deletions web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,21 @@ 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(
self,
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):
Expand All @@ -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. ",
Expand Down Expand Up @@ -1180,7 +1187,7 @@ def __init__(self,
self.abi = abi
self._functions = None

if abi:
if self.abi:
if transaction is None:
transaction = {}

Expand Down