From cd0f9c7b3572a802466242ab284773af7fb03a44 Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Fri, 11 Dec 2020 10:25:09 -0800 Subject: [PATCH] Deprecates embedded geth integration tests. --- nucypher/blockchain/eth/processes.py | 107 ------------------ nucypher/blockchain/eth/providers.py | 13 --- .../clients/test_geth_integration.py | 74 ------------ tests/fixtures.py | 30 ++--- 4 files changed, 15 insertions(+), 209 deletions(-) delete mode 100644 nucypher/blockchain/eth/processes.py delete mode 100644 tests/acceptance/blockchain/clients/test_geth_integration.py diff --git a/nucypher/blockchain/eth/processes.py b/nucypher/blockchain/eth/processes.py deleted file mode 100644 index 77ebe6896..000000000 --- a/nucypher/blockchain/eth/processes.py +++ /dev/null @@ -1,107 +0,0 @@ -""" - This file is part of nucypher. - - nucypher is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - nucypher is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - 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 . -""" - -import os -import time -from eth_utils.address import to_checksum_address -from geth.accounts import get_accounts, create_new_account -from geth.chain import get_chain_data_dir -from geth.mixins import LoggingMixin -from geth.process import BaseGethProcess - -from nucypher.config.constants import USER_LOG_DIR, DEFAULT_CONFIG_ROOT -from nucypher.utilities.logging import Logger - - -class NuCypherGethProcess(LoggingMixin, BaseGethProcess): - - IPC_PROTOCOL = 'http' - IPC_FILENAME = 'geth.ipc' - VERBOSITY = 5 - CHAIN_ID = NotImplemented - _CHAIN_NAME = NotImplemented - - _LOG_NAME = 'nucypher-geth' - LOG = Logger(_LOG_NAME) - LOG_PATH = os.path.join(USER_LOG_DIR, f'{LOG}.log') - - def __init__(self, - geth_kwargs: dict, - stdout_logfile_path: str = LOG_PATH, - stderr_logfile_path: str = LOG_PATH, - *args, **kwargs): - - super().__init__(geth_kwargs=geth_kwargs, - stdout_logfile_path=stdout_logfile_path, - stderr_logfile_path=stderr_logfile_path, - *args, **kwargs) - - def provider_uri(self, scheme: str = None) -> str: - if not scheme: - scheme = self.IPC_PROTOCOL - if scheme in ('file', 'ipc'): - location = self.ipc_path - elif scheme in ('http', 'ws'): - location = f'{self.rpc_host}:{self.rpc_port}' - else: - raise ValueError(f'{scheme} is an unknown ethereum node IPC protocol.') - - uri = f"{scheme}://{location}" - return uri - - def start(self, timeout: int = 30, extra_delay: int = 1): - self.LOG.info(f"STARTING GETH NOW | CHAIN ID {self.CHAIN_ID} | {self.IPC_PROTOCOL}://{self.ipc_path}") - super().start() - self.wait_for_ipc(timeout=timeout) # on for all nodes by default - if self.IPC_PROTOCOL in ('rpc', 'http'): - self.wait_for_rpc(timeout=timeout) - time.sleep(extra_delay) - - def ensure_account_exists(self, password: str) -> str: - accounts = get_accounts(**self.geth_kwargs) - if not accounts: - account = create_new_account(password=password.encode(), **self.geth_kwargs) - else: - account = accounts[0] # etherbase by default - checksum_address = to_checksum_address(account.decode()) - return checksum_address - - -class NuCypherGethDevProcess(NuCypherGethProcess): - _CHAIN_NAME = 'poa-development' - - def __init__(self, config_root: str = None, *args, **kwargs): - - base_dir = config_root if config_root else DEFAULT_CONFIG_ROOT - base_dir = os.path.join(base_dir, '.ethereum') - self.data_dir = get_chain_data_dir(base_dir=base_dir, name=self._CHAIN_NAME) - - ipc_path = os.path.join(self.data_dir, 'geth.ipc') - self.geth_kwargs = {'ipc_path': ipc_path, - 'data_dir': self.data_dir} - - super().__init__(geth_kwargs=self.geth_kwargs, *args, **kwargs) - self.command = [*self.command, '--dev'] - - def start(self, timeout: int = 30, extra_delay: int = 1): - if not self.is_running: - self.LOG.info("STARTING GETH DEV PROCESS NOW") - BaseGethProcess.start(self) # <--- START GETH - time.sleep(extra_delay) # give it a second - self.wait_for_ipc(timeout=timeout) - else: - self.LOG.info("RECONNECTING TO GETH DEV PROCESS") diff --git a/nucypher/blockchain/eth/providers.py b/nucypher/blockchain/eth/providers.py index ca7e8119e..0044ac292 100644 --- a/nucypher/blockchain/eth/providers.py +++ b/nucypher/blockchain/eth/providers.py @@ -95,19 +95,6 @@ def _get_mock_test_provider(provider_uri) -> BaseProvider: return provider -def _get_test_geth_parity_provider(provider_uri) -> BaseProvider: - from nucypher.blockchain.eth.interfaces import BlockchainInterface - - # geth --dev - geth_process = NuCypherGethDevProcess() - geth_process.start() - geth_process.wait_for_ipc(timeout=30) - provider = IPCProvider(ipc_path=geth_process.ipc_path, timeout=BlockchainInterface.TIMEOUT) - - BlockchainInterface.process = geth_process - return provider - - def _get_tester_ganache(provider_uri=None) -> BaseProvider: endpoint_uri = provider_uri or 'http://localhost:7545' return HTTPProvider(endpoint_uri=endpoint_uri) diff --git a/tests/acceptance/blockchain/clients/test_geth_integration.py b/tests/acceptance/blockchain/clients/test_geth_integration.py deleted file mode 100644 index 3817e2589..000000000 --- a/tests/acceptance/blockchain/clients/test_geth_integration.py +++ /dev/null @@ -1,74 +0,0 @@ -""" - This file is part of nucypher. - - nucypher is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - nucypher is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - 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 . -""" - -import os - -import pytest -from eth_utils import is_checksum_address, to_checksum_address - -from nucypher.blockchain.eth.actors import ContractAdministrator -from nucypher.blockchain.eth.interfaces import ( - BlockchainDeployerInterface, - BlockchainInterface, - BlockchainInterfaceFactory -) -from nucypher.crypto.api import verify_eip_191 -from tests.constants import INSECURE_DEVELOPMENT_PASSWORD -from tests.markers import skip_on_circleci - - -@skip_on_circleci -def test_geth_EIP_191_client_signature_integration(instant_geth_dev_node): - - # Start a geth process - blockchain = BlockchainInterface(provider_uri=instant_geth_dev_node.provider_uri(), poa=True) - blockchain.connect() - - # Sign a message (RPC) and verify it. - etherbase = blockchain.client.accounts[0] - stamp = b'STAMP-' + os.urandom(64) - signature = blockchain.client.sign_message(account=etherbase, message=stamp) - is_valid = verify_eip_191(address=etherbase, - signature=signature, - message=stamp) - assert is_valid - - -@skip_on_circleci -def test_geth_create_new_account(instant_geth_dev_node): - blockchain = BlockchainInterface(provider_uri=instant_geth_dev_node.provider_uri(), poa=True) - blockchain.connect() - new_account = blockchain.client.new_account(password=INSECURE_DEVELOPMENT_PASSWORD) - assert is_checksum_address(new_account) - - -@pytest.mark.skip('See PR #2074') -@skip_on_circleci -def test_geth_deployment_integration(instant_geth_dev_node, test_registry): - blockchain = BlockchainInterface(provider_uri=instant_geth_dev_node.provider_uri(), poa=True) - BlockchainInterfaceFactory.register_interface(interface=blockchain) - - # Make Deployer - etherbase = to_checksum_address(instant_geth_dev_node.accounts[0].decode()) # TODO: Make property on nucypher geth node instances? - administrator = ContractAdministrator(registry=test_registry, - deployer_address=etherbase, - client_password=None) # dev accounts have no password. - - assert int(blockchain.client.chain_id) == 1337 - - # Deploy - administrator.deploy_network_contracts(interactive=False) # just do it diff --git a/tests/fixtures.py b/tests/fixtures.py index cf9cdcff6..36f3ca195 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -15,25 +15,21 @@ You should have received a copy of the GNU Affero General Public License along with nucypher. If not, see . """ -import contextlib + import json + +import contextlib +import maya import os +import pytest import random import shutil import tempfile -from datetime import datetime, timedelta -from functools import partial -from typing import Tuple - -import maya -import pytest from click.testing import CliRunner +from datetime import datetime, timedelta from eth_utils import to_checksum_address +from functools import partial from typing import Tuple, Callable -from umbral import pre -from umbral.curvebn import CurveBN -from umbral.keys import UmbralPrivateKey -from umbral.signing import Signer from web3 import Web3 from web3.contract import Contract from web3.types import TxReceipt @@ -41,7 +37,6 @@ from web3.types import TxReceipt from nucypher.blockchain.economics import BaseEconomics, StandardTokenEconomics from nucypher.blockchain.eth.actors import StakeHolder, Staker from nucypher.blockchain.eth.agents import NucypherTokenAgent, PolicyManagerAgent, StakingEscrowAgent -from nucypher.blockchain.eth.processes import NuCypherGethDevProcess from nucypher.blockchain.eth.deployers import ( AdjudicatorDeployer, NucypherTokenDeployer, @@ -51,6 +46,7 @@ from nucypher.blockchain.eth.deployers import ( WorklockDeployer ) from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory +from nucypher.blockchain.eth.processes import NuCypherGethDevProcess from nucypher.blockchain.eth.registry import InMemoryContractRegistry, LocalContractRegistry from nucypher.blockchain.eth.signers.software import Web3Signer from nucypher.blockchain.eth.token import NU @@ -66,7 +62,6 @@ from nucypher.config.constants import TEMPORARY_DOMAIN from nucypher.crypto.powers import TransactingPower from nucypher.datastore import datastore from nucypher.utilities.logging import GlobalLoggerSettings, Logger - from tests.constants import ( BASE_TEMP_DIR, BASE_TEMP_PREFIX, @@ -107,8 +102,13 @@ from tests.utils.config import ( ) from tests.utils.middleware import MockRestMiddleware, MockRestMiddlewareForLargeFleetTests from tests.utils.policy import generate_random_label -from tests.utils.ursula import MOCK_URSULA_STARTING_PORT, make_decentralized_ursulas, make_federated_ursulas, \ - MOCK_KNOWN_URSULAS_CACHE, _mock_ursula_reencrypts +from tests.utils.ursula import ( + MOCK_URSULA_STARTING_PORT, + make_decentralized_ursulas, + make_federated_ursulas, + MOCK_KNOWN_URSULAS_CACHE, + _mock_ursula_reencrypts +) test_logger = Logger("test-logger")