From 1372323bf00ac7cbc9185a0a8938dca1aaaff2e6 Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Fri, 20 Jul 2018 13:41:45 -0700 Subject: [PATCH] Handle UnknownContract at Agent init-time --- nucypher/blockchain/eth/agents.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/nucypher/blockchain/eth/agents.py b/nucypher/blockchain/eth/agents.py index 3aaabfe5f..af6146bda 100644 --- a/nucypher/blockchain/eth/agents.py +++ b/nucypher/blockchain/eth/agents.py @@ -6,6 +6,7 @@ from constant_sorrow import constants from nucypher.blockchain.eth import constants from nucypher.blockchain.eth.chains import Blockchain +from nucypher.blockchain.eth.interfaces import EthereumContractRegistry class EthereumContractAgent(ABC): @@ -33,9 +34,13 @@ class EthereumContractAgent(ABC): blockchain = Blockchain.connect() self.blockchain = blockchain - # Fetch the contract by reading address and abi from the registry and blockchain - contract = self.blockchain.interface.get_contract_by_name(name=self.principal_contract_name, - upgradeable=self._upgradeable) + try: + # Fetch the contract by reading address and abi from the registry and blockchain + contract = self.blockchain.interface.get_contract_by_name(name=self.principal_contract_name, + upgradeable=self._upgradeable) + except EthereumContractRegistry.UnknownContract: + raise self.ContractNotDeployed("There is no registry entry for {}".format(self.principal_contract_name)) + self.__contract = contract super().__init__()