diff --git a/nucypher/blockchain/eth/interfaces.py b/nucypher/blockchain/eth/interfaces.py index 3c8ff079e..0784353e2 100644 --- a/nucypher/blockchain/eth/interfaces.py +++ b/nucypher/blockchain/eth/interfaces.py @@ -14,6 +14,7 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with nucypher. If not, see . """ +from pathlib import Path import math import os @@ -805,31 +806,20 @@ class BlockchainDeployerInterface(BlockchainInterface): class DeploymentFailed(RuntimeError): pass - def __init__(self, - ignore_solidity_check: bool = False, - dry_run: bool = False, - *args, **kwargs): - - super().__init__(*args, **kwargs) - self.dry_run = dry_run - self.ignore_solidity_check = ignore_solidity_check - - def connect(self, test_contracts: bool = False) -> bool: + def connect(self, + compile_now: bool = True, + test_contracts: bool = False, + ignore_solidity_check: bool = False + ) -> bool: super().connect() - self._setup_solidity(compile_now=True, test_contracts=test_contracts) - return self.is_connected - - def _setup_solidity(self, compile_now: bool, test_contracts: bool) -> None: - if self.dry_run: - self.log.info("Dry run is active, skipping solidity compile steps.") - return if compile_now: # Execute the compilation if we're recompiling # Otherwise read compiled contract data from the registry. - _raw_contract_cache = compile_nucypher(ignore_version_check=self.ignore_solidity_check, test_contracts=test_contracts) + self._raw_contract_cache = compile_nucypher(ignore_version_check=ignore_solidity_check, + test_contracts=test_contracts) else: - _raw_contract_cache = NO_COMPILATION_PERFORMED - self._raw_contract_cache = _raw_contract_cache + self._raw_contract_cache = NO_COMPILATION_PERFORMED + return self.is_connected @validate_checksum_address def deploy_contract(self, @@ -916,9 +906,9 @@ class BlockchainDeployerInterface(BlockchainInterface): return requested_version, contract_data[requested_version] except KeyError: if requested_version != 'latest' and requested_version != 'earliest': - raise self.UnknownContract('Version {} of contract {} is not a locally compiled. ' - 'Available versions: {}' - .format(requested_version, contract_name, contract_data.keys())) + available = ', '.join(contract_data.keys()) + raise self.UnknownContract(f'Version {contract_name} of contract {contract_name} is not a locally compiled. ' + f'Available versions: {available}') if len(contract_data.keys()) == 1: return next(iter(contract_data.items())) diff --git a/tests/acceptance/blockchain/interfaces/test_chains.py b/tests/acceptance/blockchain/interfaces/test_chains.py index 0475577bd..17d7bc3c4 100644 --- a/tests/acceptance/blockchain/interfaces/test_chains.py +++ b/tests/acceptance/blockchain/interfaces/test_chains.py @@ -22,7 +22,7 @@ import pytest from nucypher.blockchain.eth.clients import EthereumClient from nucypher.blockchain.eth.interfaces import BlockchainDeployerInterface from nucypher.blockchain.eth.registry import InMemoryContractRegistry -from nucypher.blockchain.eth.sol.compile import _compile +from nucypher.blockchain.eth.sol.compile import compile_nucypher from nucypher.crypto.powers import TransactingPower from tests.constants import ( DEVELOPMENT_ETH_AIRDROP_AMOUNT, @@ -97,12 +97,14 @@ def test_multiversion_contract(): # Prepare compiler base_dir = Path(__file__).parent / 'contracts' / 'multiversion' v1_dir, v2_dir = base_dir / 'v1', base_dir / 'v2' - _compile(source_dirs=(v1_dir, v2_dir)) + compiled_contracts = compile_nucypher(source_dirs=(v1_dir, v2_dir)) # Prepare chain blockchain_interface = BlockchainDeployerInterface(provider_uri='tester://pyevm/2', gas_strategy=free_gas_price_strategy) - blockchain_interface.connect() + blockchain_interface.connect(compile_now=False) + blockchain_interface._raw_contract_cache = compiled_contracts + origin = blockchain_interface.client.accounts[0] blockchain_interface.transacting_power = TransactingPower(password=INSECURE_DEVELOPMENT_PASSWORD, account=origin) blockchain_interface.transacting_power.activate()