Accomodate deprecation of Alice, Bob, and Card CLI in internal APIs and tests.

pull/2985/head
Kieran Prasch 2022-10-18 20:06:02 +02:00
parent ec07eee6d2
commit 8f015aa690
5 changed files with 6 additions and 231 deletions

View File

@ -39,11 +39,9 @@ from nucypher.cli.literature import (
IGNORE_OLD_CONFIGURATION,
DEFAULT_TO_LONE_CONFIG_FILE
)
from nucypher.cli.painting.policies import paint_cards
from nucypher.config.base import CharacterConfiguration
from nucypher.config.constants import NUCYPHER_ENVVAR_OPERATOR_ADDRESS, DEFAULT_CONFIG_ROOT
from nucypher.control.emitters import StdoutEmitter
from nucypher.policy.identity import Card
def select_client_account(emitter,
@ -240,18 +238,3 @@ def select_config_file(emitter: StdoutEmitter,
config_file=config_file))
return config_file
def select_card(emitter, card_identifier: str) -> Card:
if not card_identifier:
cards = []
for filename in Card.CARD_DIR.iterdir():
filepath = Card.CARD_DIR / filename
card = Card.load(filepath=filepath)
cards.append(card)
paint_cards(emitter=emitter, cards=cards, as_table=True)
selection = click.prompt('Select card', type=click.IntRange(0, len(cards)))
card = cards[selection]
else:
card = Card.load(identifier=card_identifier)
return card

View File

@ -18,12 +18,9 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
import click
from nucypher.cli.commands import (
alice,
bob,
enrico,
status,
ursula,
contacts,
porter,
bond,
)
@ -42,27 +39,7 @@ def nucypher_cli():
#
# Character CLI Entry Points (Fan Out Input)
#
#
# ursula
# |
# | bond
# | /
# | /
# stdin --> cli.main --- alice
# | \
# | \
# | bob
# |
# enrico
#
#
#
# New character CLI modules must be added here
# for the entry point to be attached to the nucypher base command.
#
# Inversely, commenting out an entry point here will disable it.
# Character CLI Entry Points
#
ENTRY_POINTS = (
@ -79,11 +56,6 @@ ENTRY_POINTS = (
status.status, # Network status explorer
porter.porter, # Network support services
# Demos
alice.alice, # Author of Policies
bob.bob, # Builder of Capsules
contacts.contacts, # "character card" management
)
for entry_point in ENTRY_POINTS:

View File

@ -35,7 +35,7 @@ from tests.constants import (
YES
)
CONFIG_CLASSES = (AliceConfiguration, BobConfiguration, UrsulaConfiguration)
CONFIG_CLASSES = (UrsulaConfiguration, )
ENV = {NUCYPHER_ENVVAR_KEYSTORE_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD}

View File

@ -15,28 +15,23 @@
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import os
import shutil
from pathlib import Path
import pytest
from nucypher.blockchain.eth.actors import Operator
from nucypher.cli.main import nucypher_cli
from nucypher.config.characters import AliceConfiguration, UrsulaConfiguration
from nucypher.config.characters import UrsulaConfiguration
from nucypher.config.constants import (
NUCYPHER_ENVVAR_KEYSTORE_PASSWORD,
TEMPORARY_DOMAIN,
NUCYPHER_ENVVAR_ALICE_ETH_PASSWORD,
NUCYPHER_ENVVAR_BOB_ETH_PASSWORD
TEMPORARY_DOMAIN
)
from nucypher.crypto.keystore import Keystore, InvalidPassword
from nucypher.network.nodes import Teacher
from nucypher.crypto.keystore import InvalidPassword
from tests.constants import (
INSECURE_DEVELOPMENT_PASSWORD,
MOCK_CUSTOM_INSTALLATION_PATH,
MOCK_IP_ADDRESS,
MOCK_IP_ADDRESS_2,
TEST_ETH_PROVIDER_URI,
TEST_POLYGON_PROVIDER_URI
)
@ -63,163 +58,6 @@ def test_destroy_with_no_configurations(click_runner, custom_filepath):
assert not custom_filepath.exists()
def test_coexisting_configurations(click_runner,
custom_filepath,
testerchain,
agency_local_registry,
mocker):
#
# Setup
#
if custom_filepath.exists():
shutil.rmtree(str(custom_filepath), ignore_errors=True)
assert not custom_filepath.exists()
# Parse node addresses
# TODO: Is testerchain & Full contract deployment needed here (causes massive slowdown)?
alice, ursula, another_ursula, staking_provider, *all_yall = testerchain.unassigned_accounts
envvars = {NUCYPHER_ENVVAR_KEYSTORE_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD,
NUCYPHER_ENVVAR_ALICE_ETH_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD,
NUCYPHER_ENVVAR_BOB_ETH_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD}
# Future configuration filepaths for assertions...
public_keys_dir = custom_filepath / 'keystore' / 'public'
known_nodes_dir = custom_filepath / 'known_nodes'
# ... Ensure they do not exist to begin with.
# No keys have been generated...
assert not public_keys_dir.exists()
# No known nodes exist...
assert not known_nodes_dir.exists()
# Not the configuration root...
assert not custom_filepath.is_dir()
# ... nothing
None
#
# Create
#
# Expected config files
alice_file_location = custom_filepath / AliceConfiguration.generate_filename()
ursula_file_location = custom_filepath / UrsulaConfiguration.generate_filename()
# Use a custom local filepath to init a persistent Alice
alice_init_args = ('alice', 'init',
'--network', TEMPORARY_DOMAIN,
'--payment-network', TEMPORARY_DOMAIN,
'--eth-provider', TEST_ETH_PROVIDER_URI,
'--pay-with', alice,
'--registry-filepath', str(agency_local_registry.filepath.absolute()),
'--config-root', str(custom_filepath.absolute()))
result = click_runner.invoke(nucypher_cli, alice_init_args, catch_exceptions=False, env=envvars)
assert result.exit_code == 0
# All configuration files still exist.
assert alice_file_location.is_file()
# Use the same local filepath to init a persistent Ursula
init_args = ('ursula', 'init',
'--network', TEMPORARY_DOMAIN,
'--payment-network', TEMPORARY_DOMAIN,
'--eth-provider', TEST_ETH_PROVIDER_URI,
'--payment-provider', TEST_POLYGON_PROVIDER_URI,
'--operator-address', ursula,
'--rest-host', MOCK_IP_ADDRESS,
'--registry-filepath', str(agency_local_registry.filepath.absolute()),
'--config-root', str(custom_filepath.absolute()))
result = click_runner.invoke(nucypher_cli, init_args, catch_exceptions=False, env=envvars)
assert result.exit_code == 0, result.output
# All configuration files still exist.
assert alice_file_location.is_file()
assert ursula_file_location.is_file()
key_spy = mocker.spy(Keystore, 'generate')
# keystore signing key
# Use the same local filepath to init another persistent Ursula
init_args = ('ursula', 'init',
'--network', TEMPORARY_DOMAIN,
'--payment-network', TEMPORARY_DOMAIN,
'--operator-address', another_ursula,
'--rest-host', MOCK_IP_ADDRESS_2,
'--registry-filepath', str(agency_local_registry.filepath.absolute()),
'--eth-provider', TEST_ETH_PROVIDER_URI,
'--payment-provider', TEST_POLYGON_PROVIDER_URI,
'--config-root', str(custom_filepath.absolute()))
result = click_runner.invoke(nucypher_cli, init_args, catch_exceptions=False, env=envvars)
assert result.exit_code == 0
# All configuration files still exist.
assert alice_file_location.is_file()
kid = key_spy.spy_return.id[:8]
another_ursula_configuration_file_location = custom_filepath / UrsulaConfiguration.generate_filename(modifier=kid)
assert another_ursula_configuration_file_location.is_file()
assert ursula_file_location.is_file()
#
# Run
#
# Run an Ursula amidst the other configuration files
run_args = ('ursula', 'run',
'--dry-run',
'--no-ip-checkup',
'--config-file', str(another_ursula_configuration_file_location.absolute()))
user_input = f'{INSECURE_DEVELOPMENT_PASSWORD}\n' * 2
Operator.READY_POLL_RATE = 1
Operator.READY_TIMEOUT = 1
with pytest.raises(Operator.ActorError):
# Operator init success, but not bonded.
result = click_runner.invoke(nucypher_cli, run_args, input=user_input, catch_exceptions=False)
assert result.exit_code == 0
Operator.READY_TIMEOUT = None
# All configuration files still exist.
assert alice_file_location.is_file()
assert another_ursula_configuration_file_location.is_file()
assert ursula_file_location.is_file()
# Check that the proper Ursula console is attached
assert another_ursula in result.output
#
# Destroy
#
another_ursula_destruction_args = ('ursula', 'destroy',
'--force',
'--config-file', str(another_ursula_configuration_file_location.absolute()))
result = click_runner.invoke(nucypher_cli, another_ursula_destruction_args, catch_exceptions=False, env=envvars)
assert result.exit_code == 0
assert not another_ursula_configuration_file_location.is_file()
ursula_destruction_args = ('ursula', 'destroy', '--config-file', str(ursula_file_location.absolute()))
result = click_runner.invoke(nucypher_cli, ursula_destruction_args, input='Y', catch_exceptions=False, env=envvars)
assert result.exit_code == 0
assert 'y/N' in result.output
assert not ursula_file_location.is_file()
alice_destruction_args = ('alice', 'destroy', '--force', '--config-file', str(alice_file_location.absolute()))
result = click_runner.invoke(nucypher_cli, alice_destruction_args, catch_exceptions=False, env=envvars)
assert result.exit_code == 0
assert not alice_file_location.is_file()
def test_corrupted_configuration(click_runner,
custom_filepath,
testerchain,

View File

@ -21,7 +21,6 @@ import pytest
import nucypher
from nucypher.blockchain.eth.sol.__conf__ import SOLIDITY_COMPILER_VERSION
from nucypher.cli.commands.contacts import contacts, show
from nucypher.cli.commands.deploy import deploy
from nucypher.cli.main import ENTRY_POINTS, nucypher_cli
from nucypher.config.constants import USER_LOG_DIR, DEFAULT_CONFIG_ROOT
@ -95,20 +94,3 @@ def test_echo_logging_root(click_runner):
result = click_runner.invoke(nucypher_cli, version_args, catch_exceptions=False)
assert result.exit_code == 0
assert str(USER_LOG_DIR.absolute()) in result.output, 'Log path text was not produced.'
def test_contacts_help(click_runner):
command = ('contacts', '--help')
result = click_runner.invoke(nucypher_cli, command, catch_exceptions=False)
assert result.exit_code == 0, result.output
normalized_help_text = ' '.join(result.output.split())
assert contacts.__doc__ in normalized_help_text
def test_contacts_show_help(click_runner):
command = ('contacts', 'show', '--help')
result = click_runner.invoke(nucypher_cli, command, catch_exceptions=False)
assert result.exit_code == 0, result.output
normalized_help_text = ' '.join(result.output.split())
normalized_docstring = ' '.join(show.__doc__.split())
assert normalized_docstring in normalized_help_text