def __execute(compiler_version: VersionString, input_config: Dict, allow_paths: Optional[List[str]]): """Executes the solcx command and underlying solc wrapper""" # Lazy import to allow for optional installation of solcx try: from solcx.install import get_executable from solcx.main import compile_standard except ImportError: raise DevelopmentInstallationRequired(importable_name='solcx') # Prepare Solc Command solc_binary_path: Path = get_executable(version=compiler_version) _allow_paths = ',' + ','.join(str(p) for p in allow_paths) # Execute Compilation try: compiler_output = compile_standard(input_data=input_config, allow_paths=_allow_paths, solc_binary=solc_binary_path) except FileNotFoundError: raise CompilationError("The solidity compiler is not at the specified path. " "Check that the file exists and is executable.") except PermissionError: raise CompilationError(f"The solidity compiler binary at {solc_binary_path} is not executable. " "Check the file's permissions.") errors = compiler_output.get('errors') if errors: formatted = '\n'.join([error['formattedMessage'] for error in errors]) SOLC_LOGGER.warn(f"Errors during compilation: \n{formatted}") SOLC_LOGGER.info(f"Successfully compiled {len(compiler_output)} sources with {OPTIMIZER_RUNS} optimization runs") return compiler_output
def test_client(self): try: from tests.utils.controllers import JSONRPCTestClient except ImportError: raise DevelopmentInstallationRequired(importable_name='tests.utils.controllers.JSONRPCTestClient') test_client = JSONRPCTestClient(rpc_controller=self) return test_client
def _get_pyevm_test_backend() -> PyEVMBackend: try: # TODO: Consider packaged support of --dev mode with testerchain from tests.constants import PYEVM_GAS_LIMIT, NUMBER_OF_ETH_TEST_ACCOUNTS except ImportError: raise DevelopmentInstallationRequired(importable_name='tests.constants') # Initialize genesis_params = PyEVMBackend._generate_genesis_params(overrides={'gas_limit': PYEVM_GAS_LIMIT}) pyevm_backend = PyEVMBackend(genesis_parameters=genesis_params) pyevm_backend.reset_to_genesis(genesis_params=genesis_params, num_accounts=NUMBER_OF_ETH_TEST_ACCOUNTS) return pyevm_backend
def from_target_ursula(cls, target_ursula: Ursula, claim_signing_key: bool = False, attach_transacting_key: bool = True) -> 'Vladimir': """ Sometimes Vladimir seeks to attack or imitate a *specific* target Ursula. TODO: This is probably a more instructive method if it takes a bytes representation instead of the entire Ursula. """ try: from tests.utils.middleware import EvilMiddleWare except ImportError: raise DevelopmentInstallationRequired( importable_name='tests.utils.middleware.EvilMiddleWare') cls.network_middleware = EvilMiddleWare() crypto_power = CryptoPower( power_ups=target_ursula._default_crypto_powerups) if claim_signing_key: crypto_power.consume_power_up( SigningPower( public_key=target_ursula.stamp.as_umbral_pubkey())) if attach_transacting_key: cls.attach_transacting_key( blockchain=target_ursula.policy_agent.blockchain) db_filepath = tempfile.mkdtemp(prefix='Vladimir') vladimir = cls( is_me=True, crypto_power=crypto_power, db_filepath=db_filepath, domain=TEMPORARY_DOMAIN, block_until_ready=False, start_working_now=False, rest_host=target_ursula.rest_interface.host, rest_port=target_ursula.rest_interface.port, certificate=target_ursula.rest_server_certificate(), network_middleware=cls.network_middleware, checksum_address=cls.fraud_address, worker_address=cls.fraud_address, ######### Asshole. timestamp=target_ursula._timestamp, interface_signature=target_ursula._interface_signature, ######### ) return vladimir
along with nucypher. If not, see <https://www.gnu.org/licenses/>. """ from nucypher.blockchain.eth.networks import NetworksInventory from nucypher.exceptions import DevelopmentInstallationRequired try: from prometheus_client import Gauge, Enum, Counter, Info, Histogram, Summary except ImportError: raise ImportError('"prometheus_client" must be installed - run "pip install nucypher[ursula]" and try again.') try: from prometheus_client.core import Timestamp from prometheus_client.registry import CollectorRegistry, REGISTRY from prometheus_client.utils import floatToGoString except ImportError: raise DevelopmentInstallationRequired(importable_name='prometheus_client') import json from nucypher.utilities.prometheus.collector import ( MetricsCollector, UrsulaInfoMetricsCollector, BlockchainMetricsCollector, StakerMetricsCollector, WorkerMetricsCollector, WorkLockMetricsCollector, EventMetricsCollector, ReStakeEventMetricsCollector, WindDownEventMetricsCollector, WorkerBondedEventMetricsCollector, CommitmentMadeEventMetricsCollector,
# WARNING This is not a mining script! # you will not perform any re-encryptions, and you will not get paid. # It might be (but might not be) useful for determining whether you have # the proper dependencies and configuration to run an actual mining node. from click.testing import CliRunner from nucypher.cli.main import nucypher_cli from nucypher.exceptions import DevelopmentInstallationRequired from nucypher.utilities.networking import LOOPBACK_ADDRESS try: from tests.utils.ursula import select_test_port except ImportError: raise DevelopmentInstallationRequired(importable_name='tests.utils.ursula.select_test_port') click_runner = CliRunner() DEMO_NODE_PORT = select_test_port() DEMO_FLEET_STARTING_PORT = 11500 args = ['ursula', 'run', '--debug', '--federated-only', '--teacher', f'https://{LOOPBACK_ADDRESS}:{DEMO_FLEET_STARTING_PORT}', '--rest-port', DEMO_NODE_PORT, '--dev' ] nucypher_cli.main(args=args, prog_name="nucypher-cli")
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 <https://www.gnu.org/licenses/>. """ from nucypher.blockchain.eth.sol.compile.types import SourceBundle from nucypher.exceptions import DevelopmentInstallationRequired try: import tests except ImportError: raise DevelopmentInstallationRequired(importable_name='tests') from nucypher.blockchain.eth.sol.compile.constants import IGNORE_CONTRACT_PREFIXES, SOLC_LOGGER import os from pathlib import Path from typing import Dict, Iterator def source_filter(filename: str) -> bool: """Helper function for filtering out contracts not intended for compilation""" contains_ignored_prefix: bool = any(prefix in filename for prefix in IGNORE_CONTRACT_PREFIXES) is_solidity_file: bool = filename.endswith('.sol') return is_solidity_file and not contains_ignored_prefix def collect_sources(source_bundle: SourceBundle) -> Dict[str, Path]:
def from_target_ursula( cls, target_ursula: Ursula, substitute_verifying_key: bool = False, sign_metadata: bool = False, ) -> 'Vladimir': """ Sometimes Vladimir seeks to attack or imitate a *specific* target Ursula. TODO: This is probably a more instructive method if it takes a bytes representation instead of the entire Ursula. """ try: from tests.utils.middleware import EvilMiddleWare except ImportError: raise DevelopmentInstallationRequired( importable_name='tests.utils.middleware.EvilMiddleWare') cls.network_middleware = EvilMiddleWare() crypto_power = CryptoPower( power_ups=target_ursula._default_crypto_powerups) blockchain = target_ursula.policy_agent.blockchain cls.attach_transacting_key(blockchain=blockchain) db_filepath = tempfile.mkdtemp(prefix='Vladimir') vladimir = cls( is_me=True, crypto_power=crypto_power, db_filepath=db_filepath, domain=TEMPORARY_DOMAIN, rest_host=target_ursula.rest_interface.host, rest_port=target_ursula.rest_interface.port, certificate=target_ursula.certificate, network_middleware=cls.network_middleware, checksum_address=cls.fraud_address, worker_address=cls.fraud_address, signer=Web3Signer(blockchain.client), provider_uri=blockchain.provider_uri, ) # Let's use the target's public info, and try to make some changes. metadata = target_ursula.metadata() metadata_bytes = bytes(metadata) # Since it is an object from a Rust extension, we cannot directly modify it, # so we have to replace stuff in the byte representation and then deserialize. # We are replacinig objects with constant size, # so it should work regardless of the binary format. # Our basic replacement. We want to impersonate the target Ursula. metadata_bytes = metadata_bytes.replace( metadata.payload.canonical_address, vladimir.canonical_address) # Use our own verifying key if substitute_verifying_key: metadata_bytes = metadata_bytes.replace( bytes(metadata.payload.verifying_key), bytes(vladimir.stamp.as_umbral_pubkey())) fake_metadata = NodeMetadata.from_bytes(metadata_bytes) # Re-generate metadata signature using our signing key if sign_metadata: fake_metadata = NodeMetadata(vladimir.stamp.as_umbral_signer(), fake_metadata.payload) # Put metadata back vladimir._metadata = fake_metadata return vladimir