mirror of https://github.com/nucypher/nucypher.git
Repond to RFCs in PR #3030
parent
67619c7ee1
commit
e7417e8a7f
|
@ -37,11 +37,8 @@ def paint_node_status(emitter, ursula, start_time):
|
|||
'Known Nodes ......... {}'.format(len(ursula.known_nodes)),
|
||||
teacher]
|
||||
|
||||
operator_address = "Operator Address ...... {}".format(ursula.operator_address)
|
||||
current_period = (
|
||||
f"Current Period ...... {ursula.application_agent.get_current_period()}"
|
||||
)
|
||||
stats.extend([current_period, operator_address])
|
||||
operator_address = 'Operator Address ...... {}'.format(ursula.operator_address)
|
||||
stats.extend([operator_address])
|
||||
|
||||
if ursula._availability_tracker:
|
||||
if ursula._availability_tracker.running:
|
||||
|
|
|
@ -12,7 +12,7 @@ def make_staking_provider_reservoir(
|
|||
application_agent: PREApplicationAgent,
|
||||
exclude_addresses: Optional[Iterable[ChecksumAddress]] = None,
|
||||
include_addresses: Optional[Iterable[ChecksumAddress]] = None,
|
||||
pagination_size: int = None,
|
||||
pagination_size: Optional[int] = None,
|
||||
):
|
||||
"""Get a sampler object containing the currently registered staking providers."""
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import datetime
|
||||
|
||||
import maya
|
||||
|
@ -17,14 +16,14 @@ from tests.utils.ursula import make_ursulas
|
|||
def test_stakers_bond_to_ursulas(
|
||||
testerchain, test_registry, staking_providers, ursula_test_config
|
||||
):
|
||||
ursulas = make_ursulas(
|
||||
nodes = make_ursulas(
|
||||
ursula_config=ursula_test_config,
|
||||
staking_provider_addresses=testerchain.stake_providers_accounts,
|
||||
operator_addresses=testerchain.ursulas_accounts,
|
||||
)
|
||||
|
||||
assert len(ursulas) == len(staking_providers)
|
||||
for ursula in ursulas:
|
||||
assert len(nodes) == len(staking_providers)
|
||||
for ursula in nodes:
|
||||
ursula.validate_operator(registry=test_registry)
|
||||
assert ursula.verified_operator
|
||||
|
||||
|
|
|
@ -34,41 +34,24 @@ from tests.constants import (
|
|||
from tests.utils.ursula import select_test_port
|
||||
|
||||
|
||||
def test_interactive_initialize_ursula(
|
||||
click_runner, mocker, tmpdir, test_registry_source_manager
|
||||
):
|
||||
def test_interactive_initialize_ursula(click_runner, mocker, tmpdir, test_registry_source_manager):
|
||||
|
||||
# Mock out filesystem writes
|
||||
mocker.patch.object(UrsulaConfiguration, "initialize", autospec=True)
|
||||
mocker.patch.object(UrsulaConfiguration, "to_configuration_file", autospec=True)
|
||||
mocker.patch.object(UrsulaConfiguration, 'initialize', autospec=True)
|
||||
mocker.patch.object(UrsulaConfiguration, 'to_configuration_file', autospec=True)
|
||||
|
||||
# Mock Keystore init
|
||||
keystore = Keystore.generate(
|
||||
keystore_dir=tmpdir, password=INSECURE_DEVELOPMENT_PASSWORD
|
||||
)
|
||||
mocker.patch.object(
|
||||
CharacterConfiguration,
|
||||
"keystore",
|
||||
return_value=keystore,
|
||||
new_callable=PropertyMock,
|
||||
)
|
||||
keystore = Keystore.generate(keystore_dir=tmpdir, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
mocker.patch.object(CharacterConfiguration, 'keystore', return_value=keystore, new_callable=PropertyMock)
|
||||
|
||||
# Use default ursula init args
|
||||
init_args = (
|
||||
"ursula",
|
||||
"init",
|
||||
"--network",
|
||||
TEMPORARY_DOMAIN,
|
||||
"--eth-provider",
|
||||
TEST_ETH_PROVIDER_URI,
|
||||
"--payment-provider",
|
||||
TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
init_args = ('ursula', 'init',
|
||||
'--network', TEMPORARY_DOMAIN,
|
||||
'--eth-provider', TEST_ETH_PROVIDER_URI,
|
||||
'--payment-provider', TEST_ETH_PROVIDER_URI)
|
||||
|
||||
user_input = "0\n" + "0\n" + YES_ENTER + FAKE_PASSWORD_CONFIRMED
|
||||
result = click_runner.invoke(
|
||||
nucypher_cli, init_args, input=user_input, catch_exceptions=False
|
||||
)
|
||||
user_input = '0\n' + '0\n' + YES_ENTER + FAKE_PASSWORD_CONFIRMED
|
||||
result = click_runner.invoke(nucypher_cli, init_args, input=user_input, catch_exceptions=False)
|
||||
assert result.exit_code == 0, result.output
|
||||
|
||||
# Select network
|
||||
|
@ -81,129 +64,84 @@ def test_interactive_initialize_ursula(
|
|||
assert CONFIRM_IPV4_ADDRESS_QUESTION in result.output
|
||||
|
||||
# Auth
|
||||
assert (
|
||||
COLLECT_NUCYPHER_PASSWORD in result.output
|
||||
), "WARNING: User was not prompted for password"
|
||||
assert (
|
||||
REPEAT_FOR_CONFIRMATION in result.output
|
||||
), "User was not prompted to confirm password"
|
||||
assert COLLECT_NUCYPHER_PASSWORD in result.output, 'WARNING: User was not prompted for password'
|
||||
assert REPEAT_FOR_CONFIRMATION in result.output, 'User was not prompted to confirm password'
|
||||
|
||||
|
||||
def test_initialize_custom_configuration_root(
|
||||
click_runner, custom_filepath: Path, test_registry_source_manager, testerchain
|
||||
):
|
||||
def test_initialize_custom_configuration_root(click_runner, custom_filepath: Path, test_registry_source_manager, testerchain):
|
||||
|
||||
deploy_port = select_test_port()
|
||||
# Use a custom local filepath for configuration
|
||||
init_args = (
|
||||
"ursula",
|
||||
"init",
|
||||
"--network",
|
||||
TEMPORARY_DOMAIN,
|
||||
"--config-root",
|
||||
str(custom_filepath.absolute()),
|
||||
"--rest-host",
|
||||
MOCK_IP_ADDRESS,
|
||||
"--rest-port",
|
||||
deploy_port,
|
||||
"--eth-provider",
|
||||
TEST_ETH_PROVIDER_URI,
|
||||
"--payment-provider",
|
||||
TEST_ETH_PROVIDER_URI,
|
||||
"--payment-network",
|
||||
TEMPORARY_DOMAIN,
|
||||
"--operator-address",
|
||||
testerchain.ursulas_accounts[0],
|
||||
)
|
||||
result = click_runner.invoke(
|
||||
nucypher_cli, init_args, input=FAKE_PASSWORD_CONFIRMED, catch_exceptions=False
|
||||
)
|
||||
init_args = ('ursula', 'init',
|
||||
'--network', TEMPORARY_DOMAIN,
|
||||
'--config-root', str(custom_filepath.absolute()),
|
||||
'--rest-host', MOCK_IP_ADDRESS,
|
||||
'--rest-port', deploy_port,
|
||||
'--eth-provider', TEST_ETH_PROVIDER_URI,
|
||||
'--payment-provider', TEST_ETH_PROVIDER_URI,
|
||||
'--payment-network', TEMPORARY_DOMAIN,
|
||||
'--operator-address', testerchain.ursulas_accounts[0])
|
||||
result = click_runner.invoke(nucypher_cli, init_args, input=FAKE_PASSWORD_CONFIRMED, catch_exceptions=False)
|
||||
assert result.exit_code == 0, result.output
|
||||
|
||||
# CLI Output
|
||||
assert (
|
||||
str(MOCK_CUSTOM_INSTALLATION_PATH) in result.output
|
||||
), "Configuration not in system temporary directory"
|
||||
assert (
|
||||
"nucypher ursula run" in result.output
|
||||
), "Help message is missing suggested command"
|
||||
assert "IPv4" not in result.output
|
||||
assert str(MOCK_CUSTOM_INSTALLATION_PATH) in result.output, "Configuration not in system temporary directory"
|
||||
assert "nucypher ursula run" in result.output, 'Help message is missing suggested command'
|
||||
assert 'IPv4' not in result.output
|
||||
|
||||
# Files and Directories
|
||||
assert custom_filepath.is_dir(), "Configuration file does not exist"
|
||||
assert (custom_filepath / "keystore").is_dir(), "KEYSTORE does not exist"
|
||||
assert custom_filepath.is_dir(), 'Configuration file does not exist'
|
||||
assert (custom_filepath / 'keystore').is_dir(), 'KEYSTORE does not exist'
|
||||
|
||||
# TODO: Only using in-memory node storage for now
|
||||
# assert (custom_filepath / 'known_nodes').is_dir(), 'known_nodes directory does not exist'
|
||||
assert not (
|
||||
custom_filepath / "known_nodes"
|
||||
).is_dir(), "known_nodes directory does not exist"
|
||||
assert not (custom_filepath / 'known_nodes').is_dir(), 'known_nodes directory does not exist'
|
||||
|
||||
custom_config_filepath = custom_filepath / UrsulaConfiguration.generate_filename()
|
||||
assert custom_config_filepath.is_file(), "Configuration file does not exist"
|
||||
assert custom_config_filepath.is_file(), 'Configuration file does not exist'
|
||||
|
||||
# Auth
|
||||
assert (
|
||||
COLLECT_NUCYPHER_PASSWORD in result.output
|
||||
), "WARNING: User was not prompted for password"
|
||||
assert (
|
||||
REPEAT_FOR_CONFIRMATION in result.output
|
||||
), "User was not prompted to confirm password"
|
||||
assert COLLECT_NUCYPHER_PASSWORD in result.output, 'WARNING: User was not prompted for password'
|
||||
assert REPEAT_FOR_CONFIRMATION in result.output, 'User was not prompted to confirm password'
|
||||
|
||||
|
||||
def test_configuration_file_contents(
|
||||
custom_filepath: Path, nominal_configuration_fields, test_registry_source_manager
|
||||
):
|
||||
def test_configuration_file_contents(custom_filepath: Path, nominal_configuration_fields, test_registry_source_manager):
|
||||
|
||||
custom_config_filepath = custom_filepath / UrsulaConfiguration.generate_filename()
|
||||
assert custom_config_filepath.is_file(), "Configuration file does not exist"
|
||||
assert custom_config_filepath.is_file(), 'Configuration file does not exist'
|
||||
|
||||
# Check the contents of the configuration file
|
||||
with open(custom_config_filepath, "r") as config_file:
|
||||
with open(custom_config_filepath, 'r') as config_file:
|
||||
raw_contents = config_file.read()
|
||||
|
||||
try:
|
||||
data = json.loads(raw_contents)
|
||||
except JSONDecodeError:
|
||||
raise pytest.fail(
|
||||
msg="Invalid JSON configuration file {}".format(custom_config_filepath)
|
||||
)
|
||||
raise pytest.fail(msg="Invalid JSON configuration file {}".format(custom_config_filepath))
|
||||
|
||||
for field in nominal_configuration_fields:
|
||||
assert field in data, "Missing field '{}' from configuration file."
|
||||
if any(keyword in field for keyword in ("path", "dir")):
|
||||
if any(keyword in field for keyword in ('path', 'dir')):
|
||||
path = data[field]
|
||||
user_data_dir = APP_DIR.user_data_dir
|
||||
# assert os.path.exists(path), '{} does not exist'.format(path)
|
||||
assert (
|
||||
user_data_dir not in path
|
||||
), "{} includes default appdir path {}".format(field, user_data_dir)
|
||||
assert user_data_dir not in path, '{} includes default appdir path {}'.format(field, user_data_dir)
|
||||
|
||||
assert custom_config_filepath.is_file(), "Configuration file does not exist"
|
||||
assert custom_config_filepath.is_file(), 'Configuration file does not exist'
|
||||
|
||||
|
||||
def test_ursula_view_configuration(
|
||||
custom_filepath: Path, click_runner, nominal_configuration_fields
|
||||
):
|
||||
def test_ursula_view_configuration(custom_filepath: Path, click_runner, nominal_configuration_fields):
|
||||
|
||||
# Ensure the configuration file still exists
|
||||
custom_config_filepath = custom_filepath / UrsulaConfiguration.generate_filename()
|
||||
assert custom_config_filepath.is_file(), "Configuration file does not exist"
|
||||
assert custom_config_filepath.is_file(), 'Configuration file does not exist'
|
||||
|
||||
view_args = (
|
||||
"ursula",
|
||||
"config",
|
||||
"--config-file",
|
||||
str(custom_config_filepath.absolute()),
|
||||
)
|
||||
view_args = ('ursula', 'config', '--config-file', str(custom_config_filepath.absolute()))
|
||||
|
||||
# View the configuration
|
||||
result = click_runner.invoke(
|
||||
nucypher_cli,
|
||||
view_args,
|
||||
input="{}\n".format(INSECURE_DEVELOPMENT_PASSWORD),
|
||||
catch_exceptions=False,
|
||||
)
|
||||
result = click_runner.invoke(nucypher_cli, view_args,
|
||||
input='{}\n'.format(INSECURE_DEVELOPMENT_PASSWORD),
|
||||
catch_exceptions=False)
|
||||
|
||||
# CLI Output
|
||||
assert str(MOCK_CUSTOM_INSTALLATION_PATH) in result.output
|
||||
|
@ -211,105 +149,68 @@ def test_ursula_view_configuration(
|
|||
assert field in result.output, "Missing field '{}' from configuration file."
|
||||
|
||||
# Make sure nothing crazy is happening...
|
||||
assert custom_config_filepath.is_file(), "Configuration file does not exist"
|
||||
assert custom_config_filepath.is_file(), 'Configuration file does not exist'
|
||||
|
||||
|
||||
def test_run_ursula_from_config_file(
|
||||
custom_filepath: Path, click_runner, agency, mock_funding_and_bonding
|
||||
):
|
||||
def test_run_ursula_from_config_file(custom_filepath: Path, click_runner, agency, mock_funding_and_bonding):
|
||||
|
||||
# Ensure the configuration file still exists
|
||||
custom_config_filepath = custom_filepath / UrsulaConfiguration.generate_filename()
|
||||
assert custom_config_filepath.is_file(), "Configuration file does not exist"
|
||||
assert custom_config_filepath.is_file(), 'Configuration file does not exist'
|
||||
|
||||
# Run Ursula
|
||||
run_args = (
|
||||
"ursula",
|
||||
"run",
|
||||
"--dry-run",
|
||||
"--lonely",
|
||||
"--config-file",
|
||||
str(custom_config_filepath.absolute()),
|
||||
)
|
||||
run_args = ('ursula', 'run',
|
||||
'--dry-run',
|
||||
'--lonely',
|
||||
'--config-file', str(custom_config_filepath.absolute()))
|
||||
|
||||
result = click_runner.invoke(
|
||||
nucypher_cli,
|
||||
run_args,
|
||||
input="{0}\n{0}\nY\n".format(INSECURE_DEVELOPMENT_PASSWORD),
|
||||
catch_exceptions=False,
|
||||
)
|
||||
result = click_runner.invoke(nucypher_cli, run_args,
|
||||
input='{0}\n{0}\nY\n'.format(INSECURE_DEVELOPMENT_PASSWORD),
|
||||
catch_exceptions=False)
|
||||
|
||||
# CLI Output
|
||||
assert result.exit_code == 0, result.output
|
||||
assert "Rest Server https://192.0.2.100" in result.output
|
||||
assert f"Rest Server https://{MOCK_IP_ADDRESS}" in result.output
|
||||
|
||||
|
||||
def test_ursula_save_metadata(click_runner, custom_filepath, mocker, testerchain):
|
||||
mocker.patch.object(
|
||||
CharacterConfiguration, "DEFAULT_PAYMENT_NETWORK", TEMPORARY_DOMAIN
|
||||
)
|
||||
save_metadata_args = (
|
||||
"ursula",
|
||||
"save-metadata",
|
||||
"--dev",
|
||||
"--operator-address",
|
||||
testerchain.ursulas_accounts[0],
|
||||
"--eth-provider",
|
||||
TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
result = click_runner.invoke(
|
||||
nucypher_cli, save_metadata_args, catch_exceptions=False
|
||||
)
|
||||
mocker.patch.object(CharacterConfiguration, 'DEFAULT_PAYMENT_NETWORK', TEMPORARY_DOMAIN)
|
||||
save_metadata_args = ('ursula', 'save-metadata', '--dev',
|
||||
'--operator-address', testerchain.ursulas_accounts[0],
|
||||
'--eth-provider', TEST_ETH_PROVIDER_URI)
|
||||
result = click_runner.invoke(nucypher_cli, save_metadata_args, catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
assert (
|
||||
"Successfully saved node metadata" in result.output
|
||||
), "Node metadata successfully saved"
|
||||
assert "Successfully saved node metadata" in result.output, "Node metadata successfully saved"
|
||||
|
||||
|
||||
# Should be the last test since it deletes the configuration file
|
||||
def test_ursula_destroy_configuration(custom_filepath, click_runner):
|
||||
|
||||
preexisting_live_configuration = DEFAULT_CONFIG_ROOT.is_dir()
|
||||
preexisting_live_configuration_file = (
|
||||
DEFAULT_CONFIG_ROOT / UrsulaConfiguration.generate_filename()
|
||||
).is_file()
|
||||
preexisting_live_configuration_file = (DEFAULT_CONFIG_ROOT / UrsulaConfiguration.generate_filename()).is_file()
|
||||
|
||||
# Ensure the configuration file still exists
|
||||
custom_config_filepath = custom_filepath / UrsulaConfiguration.generate_filename()
|
||||
assert custom_config_filepath.is_file(), "Configuration file does not exist"
|
||||
assert custom_config_filepath.is_file(), 'Configuration file does not exist'
|
||||
|
||||
# Run the destroy command
|
||||
destruction_args = (
|
||||
"ursula",
|
||||
"destroy",
|
||||
"--config-file",
|
||||
str(custom_config_filepath.absolute()),
|
||||
)
|
||||
result = click_runner.invoke(
|
||||
nucypher_cli,
|
||||
destruction_args,
|
||||
input="Y\n".format(INSECURE_DEVELOPMENT_PASSWORD),
|
||||
catch_exceptions=False,
|
||||
env={NUCYPHER_ENVVAR_KEYSTORE_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD},
|
||||
)
|
||||
destruction_args = ('ursula', 'destroy', '--config-file', str(custom_config_filepath.absolute()))
|
||||
result = click_runner.invoke(nucypher_cli, destruction_args,
|
||||
input='Y\n'.format(INSECURE_DEVELOPMENT_PASSWORD),
|
||||
catch_exceptions=False,
|
||||
env={NUCYPHER_ENVVAR_KEYSTORE_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD})
|
||||
|
||||
# CLI Output
|
||||
assert not custom_config_filepath.is_file(), "Configuration file still exists"
|
||||
assert "? [y/N]:" in result.output, "WARNING: User was not asked to destroy files"
|
||||
assert (
|
||||
str(custom_filepath) in result.output
|
||||
), "WARNING: Configuration path not in output. Deleting the wrong path?"
|
||||
assert not custom_config_filepath.is_file(), 'Configuration file still exists'
|
||||
assert '? [y/N]:' in result.output, 'WARNING: User was not asked to destroy files'
|
||||
assert str(custom_filepath) in result.output, 'WARNING: Configuration path not in output. Deleting the wrong path?'
|
||||
assert SUCCESSFUL_DESTRUCTION in result.output, '"Destroyed" not in output'
|
||||
assert str(custom_filepath) in result.output
|
||||
assert result.exit_code == 0, "Destruction did not succeed"
|
||||
assert result.exit_code == 0, 'Destruction did not succeed'
|
||||
|
||||
# Ensure the files are deleted from the filesystem
|
||||
assert (
|
||||
not custom_config_filepath.is_file()
|
||||
), "Files still exist" # ... shes's gone...
|
||||
assert (
|
||||
custom_filepath.is_dir()
|
||||
), "Nucypher files no longer exist" # ... but not NuCypher ...
|
||||
assert not custom_config_filepath.is_file(), 'Files still exist' # ... shes's gone...
|
||||
assert custom_filepath.is_dir(), 'Nucypher files no longer exist' # ... but not NuCypher ...
|
||||
|
||||
# If this test started off with a live configuration, ensure it still exists
|
||||
if preexisting_live_configuration:
|
||||
|
@ -317,7 +218,5 @@ def test_ursula_destroy_configuration(custom_filepath, click_runner):
|
|||
assert configuration_still_exists
|
||||
|
||||
if preexisting_live_configuration_file:
|
||||
file_still_exists = (
|
||||
DEFAULT_CONFIG_ROOT / UrsulaConfiguration.generate_filename()
|
||||
).is_file()
|
||||
assert file_still_exists, "WARNING: Test command deleted live non-test files"
|
||||
file_still_exists = (DEFAULT_CONFIG_ROOT / UrsulaConfiguration.generate_filename()).is_file()
|
||||
assert file_still_exists, 'WARNING: Test command deleted live non-test files'
|
||||
|
|
Loading…
Reference in New Issue