mirror of https://github.com/nucypher/nucypher.git
tests use the refactored ContractRegistry and RegistrySource interfaces
parent
e1f81d9a5e
commit
1858f49a99
|
@ -32,9 +32,7 @@ print("--------- Threshold Encryption ---------")
|
|||
|
||||
coordinator_agent = CoordinatorAgent(
|
||||
provider_uri=coordinator_provider_uri,
|
||||
registry=ContractRegistry.from_latest_publication(
|
||||
domain=coordinator_network
|
||||
),
|
||||
registry=ContractRegistry.from_latest_publication(domain=coordinator_network),
|
||||
)
|
||||
ritual_id = 1 # got this from a side channel
|
||||
ritual = coordinator_agent.get_ritual(ritual_id)
|
||||
|
|
|
@ -32,9 +32,7 @@ print("--------- Threshold Encryption ---------")
|
|||
|
||||
coordinator_agent = CoordinatorAgent(
|
||||
provider_uri=coordinator_provider_uri,
|
||||
registry=ContractRegistry.from_latest_publication(
|
||||
domain=coordinator_network
|
||||
),
|
||||
registry=ContractRegistry.from_latest_publication(domain=coordinator_network),
|
||||
)
|
||||
ritual_id = 1 # got this from a side channel
|
||||
ritual = coordinator_agent.get_ritual(ritual_id)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import pytest
|
||||
|
||||
from nucypher.blockchain.eth.constants import NULL_ADDRESS
|
||||
from nucypher.blockchain.eth.signers.software import Web3Signer
|
||||
|
@ -14,7 +13,6 @@ def log(message):
|
|||
print(message)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("test_registry_source_manager")
|
||||
def test_ursula_operator_confirmation(
|
||||
ursula_test_config,
|
||||
testerchain,
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
|
||||
|
||||
from nucypher.blockchain.eth.agents import ContractAgency, TACoApplicationAgent
|
||||
from tests.constants import TEST_ETH_PROVIDER_URI
|
||||
|
||||
|
||||
def test_get_agent_with_different_registries(test_registry, agency_local_registry):
|
||||
def test_get_agent_with_different_registries(test_registry):
|
||||
# Get agents using same registry instance
|
||||
application_agent_1 = ContractAgency.get_agent(
|
||||
TACoApplicationAgent,
|
||||
|
@ -18,12 +16,3 @@ def test_get_agent_with_different_registries(test_registry, agency_local_registr
|
|||
)
|
||||
assert application_agent_2.registry == application_agent_1.registry == test_registry
|
||||
assert application_agent_2 is application_agent_1
|
||||
|
||||
# Same content but different classes of registries
|
||||
application_agent_2 = ContractAgency.get_agent(
|
||||
TACoApplicationAgent,
|
||||
registry=agency_local_registry,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
assert application_agent_2.registry == test_registry
|
||||
assert application_agent_2 is application_agent_1
|
||||
|
|
|
@ -28,7 +28,7 @@ def check(policy, bob, ursulas):
|
|||
# TODO: try to decrypt?
|
||||
|
||||
|
||||
def test_grant_subscription_manager(alice, bob, ursulas, test_registry_source_manager):
|
||||
def test_grant_subscription_manager(alice, bob, ursulas):
|
||||
pre_payment_method = SubscriptionManagerPayment(
|
||||
eth_provider=TEST_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN
|
||||
)
|
||||
|
|
|
@ -49,7 +49,7 @@ def remote_vladimir(**kwds):
|
|||
|
||||
|
||||
def test_vladimir_cannot_verify_interface_with_ursulas_signing_key(
|
||||
testerchain, ursulas, test_registry_source_manager
|
||||
testerchain, ursulas
|
||||
):
|
||||
his_target = list(ursulas)[4]
|
||||
|
||||
|
|
|
@ -92,7 +92,6 @@ def test_ursula_and_local_keystore_signer_integration(
|
|||
mocker,
|
||||
mock_funded_account_password_keystore,
|
||||
testerchain,
|
||||
test_registry_source_manager,
|
||||
):
|
||||
config_root_path = tmp_path
|
||||
ursula_config_path = config_root_path / UrsulaConfiguration.generate_filename()
|
||||
|
|
|
@ -61,7 +61,6 @@ def test_ursula_run_with_prometheus_but_no_metrics_port(click_runner):
|
|||
|
||||
|
||||
@pt.inlineCallbacks
|
||||
@pytest.mark.usefixtures("test_registry_source_manager")
|
||||
def test_run_lone_default_development_ursula(click_runner, ursulas, testerchain):
|
||||
deploy_port = select_test_port()
|
||||
args = (
|
||||
|
|
|
@ -3,6 +3,7 @@ import random
|
|||
import pytest
|
||||
from web3 import Web3
|
||||
|
||||
import tests
|
||||
from nucypher.blockchain.eth.actors import Operator
|
||||
from nucypher.blockchain.eth.agents import (
|
||||
ContractAgency,
|
||||
|
@ -12,7 +13,9 @@ from nucypher.blockchain.eth.agents import (
|
|||
)
|
||||
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
|
||||
from nucypher.blockchain.eth.networks import NetworksInventory
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry, RegistrySourceManager
|
||||
from nucypher.blockchain.eth.signers.software import Web3Signer
|
||||
from nucypher.config.constants import TEMPORARY_DOMAIN
|
||||
from nucypher.crypto.powers import TransactingPower
|
||||
from nucypher.policy.conditions.evm import RPCCondition
|
||||
from nucypher.utilities.logging import Logger
|
||||
|
@ -23,8 +26,8 @@ from tests.constants import (
|
|||
TEST_ETH_PROVIDER_URI,
|
||||
TESTERCHAIN_CHAIN_ID,
|
||||
)
|
||||
from tests.utils.ape import registry_from_ape_deployments
|
||||
from tests.utils.blockchain import TesterBlockchain
|
||||
from tests.utils.registry import ApeRegistrySource
|
||||
from tests.utils.ursula import (
|
||||
mock_permitted_multichain_connections,
|
||||
setup_multichain_ursulas,
|
||||
|
@ -291,13 +294,17 @@ def deployed_contracts(
|
|||
global_allow_list,
|
||||
subscription_manager,
|
||||
]
|
||||
ApeRegistrySource.set_deployments(deployments)
|
||||
return deployments
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def test_registry(deployed_contracts):
|
||||
registry = registry_from_ape_deployments(deployments=deployed_contracts)
|
||||
return registry
|
||||
with tests.utils.registry.mock_registry_sources():
|
||||
RegistrySourceManager._FALLBACK_CHAIN = (ApeRegistrySource,)
|
||||
source = ApeRegistrySource(domain=TEMPORARY_DOMAIN)
|
||||
registry = ContractRegistry(source=source)
|
||||
yield registry
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("test_registry")
|
||||
|
@ -315,7 +322,6 @@ def testerchain(project) -> TesterBlockchain:
|
|||
#
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("test_registry")
|
||||
@pytest.fixture(scope="module")
|
||||
def staking_providers(
|
||||
deployer_account,
|
||||
|
|
|
@ -20,7 +20,6 @@ from web3 import Web3
|
|||
import tests
|
||||
from nucypher.blockchain.eth.actors import Operator
|
||||
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
|
||||
from nucypher.blockchain.eth.registry import LocalContractRegistry
|
||||
from nucypher.blockchain.eth.signers.software import KeystoreSigner
|
||||
from nucypher.blockchain.eth.trackers.dkg import EventScannerTask
|
||||
from nucypher.characters.lawful import Enrico, Ursula
|
||||
|
@ -47,11 +46,10 @@ from tests.constants import (
|
|||
MOCK_CUSTOM_INSTALLATION_PATH,
|
||||
MOCK_CUSTOM_INSTALLATION_PATH_2,
|
||||
MOCK_ETH_PROVIDER_URI,
|
||||
MOCK_REGISTRY_FILEPATH,
|
||||
TEST_ETH_PROVIDER_URI,
|
||||
TESTERCHAIN_CHAIN_ID,
|
||||
)
|
||||
from tests.mock.interfaces import MockBlockchain, mock_registry_source_manager
|
||||
from tests.mock.interfaces import MockBlockchain
|
||||
from tests.mock.performance_mocks import (
|
||||
mock_cert_generation,
|
||||
mock_cert_loading,
|
||||
|
@ -79,6 +77,7 @@ test_logger = Logger("test-logger")
|
|||
|
||||
# defer.setDebugging(True)
|
||||
|
||||
|
||||
#
|
||||
# Temporary
|
||||
#
|
||||
|
@ -304,6 +303,12 @@ def lonely_ursula_maker(ursula_test_config, testerchain):
|
|||
#
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def mock_registry_sources():
|
||||
with tests.utils.registry.mock_registry_sources():
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def mock_testerchain() -> MockBlockchain:
|
||||
BlockchainInterfaceFactory._interfaces = dict()
|
||||
|
@ -312,28 +317,14 @@ def mock_testerchain() -> MockBlockchain:
|
|||
yield testerchain
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def test_registry_source_manager(test_registry):
|
||||
with mock_registry_source_manager(test_registry=test_registry):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def agency_local_registry(testerchain, test_registry):
|
||||
registry = LocalContractRegistry(filepath=MOCK_REGISTRY_FILEPATH)
|
||||
registry.write(test_registry.read())
|
||||
yield registry
|
||||
if MOCK_REGISTRY_FILEPATH.exists():
|
||||
MOCK_REGISTRY_FILEPATH.unlink()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def light_ursula(temp_dir_path, test_registry_source_manager, random_account, mocker):
|
||||
def light_ursula(temp_dir_path, random_account, mocker):
|
||||
mocker.patch.object(
|
||||
KeystoreSigner, "_KeystoreSigner__get_signer", return_value=random_account
|
||||
)
|
||||
pre_payment_method = SubscriptionManagerPayment(
|
||||
eth_provider=MOCK_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN
|
||||
eth_provider=MOCK_ETH_PROVIDER_URI,
|
||||
network=TEMPORARY_DOMAIN,
|
||||
)
|
||||
|
||||
mocker.patch.object(
|
||||
|
@ -391,9 +382,7 @@ def get_random_checksum_address():
|
|||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def fleet_of_highperf_mocked_ursulas(
|
||||
ursula_test_config, request, testerchain, test_registry_source_manager
|
||||
):
|
||||
def fleet_of_highperf_mocked_ursulas(ursula_test_config, request, testerchain):
|
||||
mocks = (
|
||||
mock_cert_storage,
|
||||
mock_cert_loading,
|
||||
|
@ -442,7 +431,6 @@ def fleet_of_highperf_mocked_ursulas(
|
|||
@pytest.fixture(scope="module")
|
||||
def highperf_mocked_alice(
|
||||
fleet_of_highperf_mocked_ursulas,
|
||||
test_registry_source_manager,
|
||||
monkeymodule,
|
||||
testerchain,
|
||||
):
|
||||
|
@ -510,7 +498,7 @@ def click_runner():
|
|||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def nominal_configuration_fields(test_registry_source_manager):
|
||||
def nominal_configuration_fields():
|
||||
config = UrsulaConfiguration(
|
||||
dev_mode=True,
|
||||
pre_payment_network=TEMPORARY_DOMAIN,
|
||||
|
@ -698,9 +686,7 @@ def control_time():
|
|||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def ursulas(
|
||||
testerchain, staking_providers, ursula_test_config, test_registry_source_manager
|
||||
):
|
||||
def ursulas(testerchain, ursula_test_config, staking_providers):
|
||||
if MOCK_KNOWN_URSULAS_CACHE:
|
||||
# TODO: Is this a safe assumption / test behaviour?
|
||||
# raise RuntimeError("Ursulas cache was unclear at fixture loading time. Did you use one of the ursula maker functions without cleaning up?")
|
||||
|
|
|
@ -130,7 +130,6 @@ def test_ursula_ritualist(
|
|||
dkg_size,
|
||||
ritual_id,
|
||||
variant,
|
||||
test_registry_source_manager,
|
||||
get_random_checksum_address,
|
||||
):
|
||||
"""Tests the DKG and the encryption/decryption of a message"""
|
||||
|
|
|
@ -14,7 +14,6 @@ def _policy_info_kwargs(enacted_policy):
|
|||
alice_verifying_key=enacted_policy.publisher_verifying_key,
|
||||
)
|
||||
|
||||
|
||||
def test_retrieval_kit(enacted_policy, ursulas):
|
||||
messages, message_kits = make_message_kits(enacted_policy.public_key)
|
||||
|
||||
|
|
|
@ -38,9 +38,7 @@ def test_bob_full_retrieve_flow(
|
|||
assert b"Welcome to flippering number 0." == delivered_cleartexts[0]
|
||||
|
||||
|
||||
def test_bob_retrieves(
|
||||
alice, ursulas, certificates_tempdir, test_registry_source_manager
|
||||
):
|
||||
def test_bob_retrieves(alice, ursulas, certificates_tempdir):
|
||||
"""A test to show that Bob can retrieve data from Ursula"""
|
||||
|
||||
# Let's partition Ursulas in two parts
|
||||
|
@ -115,7 +113,6 @@ def test_bob_retrieves(
|
|||
def test_bob_retrieves_with_treasure_map(
|
||||
bob, ursulas, enacted_policy, capsule_side_channel
|
||||
):
|
||||
enrico = capsule_side_channel.enrico
|
||||
message_kit = capsule_side_channel()
|
||||
treasure_map = enacted_policy.treasure_map
|
||||
alice_verifying_key = enacted_policy.publisher_verifying_key
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
import pytest
|
||||
|
||||
|
||||
def test_new_ursula_announces_herself(
|
||||
lonely_ursula_maker, test_registry_source_manager
|
||||
):
|
||||
def test_new_ursula_announces_herself(lonely_ursula_maker):
|
||||
ursula_in_a_house, ursula_with_a_mouse = lonely_ursula_maker(
|
||||
quantity=2, domain="useless_domain"
|
||||
)
|
||||
|
@ -32,9 +30,7 @@ def test_node_deployer(ursulas):
|
|||
assert deployer.application == ursula.rest_app
|
||||
|
||||
|
||||
def test_goerli_and_mumbai_as_conditions_providers(
|
||||
lonely_ursula_maker, test_registry_source_manager
|
||||
):
|
||||
def test_goerli_and_mumbai_as_conditions_providers(lonely_ursula_maker):
|
||||
INVALID_CHAIN_ID = 66775827584859395569954838 # If we eventually support a chain with this ID, heaven help us.
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
|
|
|
@ -96,7 +96,6 @@ def test_unlock_nucypher_keystore_invalid_password(
|
|||
alice_test_config,
|
||||
capsys,
|
||||
tmpdir,
|
||||
test_registry_source_manager,
|
||||
):
|
||||
|
||||
# Setup
|
||||
|
|
|
@ -78,7 +78,7 @@ def test_forget_cli_action(alice_test_config, test_emitter, mock_stdin, mocker,
|
|||
assert SUCCESSFUL_FORGET_NODES in captured.out
|
||||
|
||||
|
||||
def test_update_configuration_cli_action(config, test_emitter, test_registry_source_manager, capsys):
|
||||
def test_update_configuration_cli_action(config, test_emitter, capsys):
|
||||
config_class, config_file = config.__class__, config.filepath
|
||||
updates = dict(domain=TEMPORARY_DOMAIN)
|
||||
get_or_update_configuration(emitter=test_emitter, config_class=config_class, filepath=config_file, updates=updates)
|
||||
|
@ -91,7 +91,6 @@ def test_update_configuration_cli_action(config, test_emitter, test_registry_sou
|
|||
|
||||
def test_handle_update_missing_configuration_file_cli_action(config,
|
||||
test_emitter,
|
||||
test_registry_source_manager,
|
||||
mocker):
|
||||
config_class, config_file = config.__class__, config.filepath
|
||||
mocker.patch.object(config_class, '_read_configuration_file', side_effect=FileNotFoundError)
|
||||
|
@ -108,7 +107,6 @@ def test_handle_update_missing_configuration_file_cli_action(config,
|
|||
|
||||
def test_handle_update_invalid_configuration_file_cli_action(config,
|
||||
test_emitter,
|
||||
test_registry_source_manager,
|
||||
mocker,
|
||||
capsys):
|
||||
config_class = config.__class__
|
||||
|
|
|
@ -160,7 +160,6 @@ def test_select_client_account_with_balance_display(
|
|||
test_emitter,
|
||||
testerchain,
|
||||
capsys,
|
||||
test_registry_source_manager,
|
||||
mock_staking_agent,
|
||||
mock_token_agent,
|
||||
selection,
|
||||
|
|
|
@ -1,24 +1,20 @@
|
|||
|
||||
|
||||
import pytest
|
||||
|
||||
from nucypher.blockchain.eth.networks import NetworksInventory
|
||||
from nucypher.cli.actions.select import select_network
|
||||
|
||||
|
||||
__POLY_NETWORKS = NetworksInventory.POLY_NETWORKS
|
||||
__ETH_NETWORKS = NetworksInventory.ETH_NETWORKS
|
||||
|
||||
|
||||
@pytest.mark.parametrize('user_input', range(0, len(__ETH_NETWORKS)-1))
|
||||
@pytest.mark.parametrize(
|
||||
"user_input", range(0, len(NetworksInventory.ETH_NETWORKS) - 1)
|
||||
)
|
||||
def test_select_network_cli_action_eth(test_emitter, capsys, mock_stdin, user_input):
|
||||
mock_stdin.line(str(user_input))
|
||||
selection = __ETH_NETWORKS[user_input]
|
||||
selection = NetworksInventory.ETH_NETWORKS[user_input]
|
||||
result = select_network(emitter=test_emitter, network_type=NetworksInventory.ETH)
|
||||
assert result == selection
|
||||
assert result not in __POLY_NETWORKS
|
||||
assert result not in NetworksInventory.POLY_NETWORKS
|
||||
captured = capsys.readouterr()
|
||||
for name in __ETH_NETWORKS:
|
||||
for name in NetworksInventory.ETH_NETWORKS:
|
||||
assert name in captured.out
|
||||
assert mock_stdin.empty()
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
from nucypher.blockchain.eth.registry import InMemoryContractRegistry
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.cli.main import nucypher_cli
|
||||
from nucypher.config.characters import CharacterConfiguration, UrsulaConfiguration
|
||||
from nucypher.config.constants import (
|
||||
|
@ -26,13 +26,13 @@ CONFIG_CLASSES = (UrsulaConfiguration, )
|
|||
ENV = {NUCYPHER_ENVVAR_KEYSTORE_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_registry_sources")
|
||||
@pytest.mark.parametrize("config_class", CONFIG_CLASSES)
|
||||
def test_initialize_via_cli(
|
||||
config_class,
|
||||
custom_filepath: Path,
|
||||
click_runner,
|
||||
monkeypatch,
|
||||
test_registry_source_manager,
|
||||
):
|
||||
command = config_class.CHARACTER_CLASS.__name__.lower()
|
||||
|
||||
|
@ -72,14 +72,15 @@ def test_initialize_via_cli(
|
|||
assert not (custom_filepath / 'known_nodes').is_dir(), 'known_nodes directory does not exist'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('config_class', CONFIG_CLASSES)
|
||||
def test_reconfigure_via_cli(click_runner, custom_filepath: Path, config_class, monkeypatch, test_registry, test_registry_source_manager):
|
||||
|
||||
@pytest.mark.parametrize("config_class", CONFIG_CLASSES)
|
||||
def test_reconfigure_via_cli(
|
||||
click_runner, custom_filepath: Path, config_class, monkeypatch, test_registry
|
||||
):
|
||||
def fake_get_latest_registry(*args, **kwargs):
|
||||
return test_registry
|
||||
|
||||
monkeypatch.setattr(
|
||||
InMemoryContractRegistry, "from_latest_publication", fake_get_latest_registry
|
||||
ContractRegistry, "from_latest_publication", fake_get_latest_registry
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
CharacterConfiguration, "DEFAULT_PRE_PAYMENT_NETWORK", TEMPORARY_DOMAIN
|
||||
|
|
|
@ -3,6 +3,7 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
from nucypher.blockchain.eth.registry import LocalRegistrySource
|
||||
from nucypher.cli.main import nucypher_cli
|
||||
from nucypher.config.characters import UrsulaConfiguration
|
||||
from nucypher.config.constants import (
|
||||
|
@ -40,12 +41,9 @@ def test_destroy_with_no_configurations(click_runner, custom_filepath):
|
|||
assert not custom_filepath.exists()
|
||||
|
||||
|
||||
def test_corrupted_configuration(click_runner,
|
||||
custom_filepath,
|
||||
testerchain,
|
||||
agency_local_registry,
|
||||
test_registry_source_manager):
|
||||
|
||||
def test_corrupted_configuration(
|
||||
click_runner, custom_filepath, testerchain, test_registry, mocker
|
||||
):
|
||||
#
|
||||
# Setup
|
||||
#
|
||||
|
@ -99,6 +97,10 @@ def test_corrupted_configuration(click_runner,
|
|||
path = custom_filepath / known_nodes
|
||||
assert not path.exists()
|
||||
|
||||
mocker.patch.object(LocalRegistrySource, "get", return_value=dict())
|
||||
mock_registry_filepath = custom_filepath / "mock_registry.json"
|
||||
mock_registry_filepath.touch()
|
||||
|
||||
# Attempt installation again, with full args
|
||||
init_args = (
|
||||
"ursula",
|
||||
|
@ -116,14 +118,14 @@ def test_corrupted_configuration(click_runner,
|
|||
"--rest-host",
|
||||
MOCK_IP_ADDRESS,
|
||||
"--registry-filepath",
|
||||
str(agency_local_registry.filepath.absolute()),
|
||||
mock_registry_filepath,
|
||||
"--config-root",
|
||||
str(custom_filepath.absolute()),
|
||||
)
|
||||
|
||||
envvars = {NUCYPHER_ENVVAR_KEYSTORE_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD}
|
||||
result = click_runner.invoke(nucypher_cli, init_args, catch_exceptions=False, env=envvars)
|
||||
assert result.exit_code == 0
|
||||
assert result.exit_code == 0, result.output
|
||||
|
||||
default_filename = UrsulaConfiguration.generate_filename()
|
||||
|
||||
|
@ -141,7 +143,7 @@ def test_corrupted_configuration(click_runner,
|
|||
assert field in top_level_config_root
|
||||
|
||||
# "Corrupt" the configuration by removing the contract registry
|
||||
agency_local_registry.filepath.unlink()
|
||||
mock_registry_filepath.unlink()
|
||||
|
||||
# Attempt destruction with invalid configuration (missing registry)
|
||||
ursula_file_location = custom_filepath / default_filename
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import pytest
|
||||
|
||||
from nucypher.blockchain.eth.actors import Operator
|
||||
from nucypher.blockchain.eth.trackers.dkg import ActiveRitualTracker
|
||||
from nucypher.cli.commands import ursula
|
||||
|
@ -15,7 +17,8 @@ from tests.constants import (
|
|||
)
|
||||
|
||||
|
||||
def test_ursula_startup_ip_checkup(click_runner, mocker, test_registry_source_manager):
|
||||
@pytest.mark.usefixtures("mock_registry_sources")
|
||||
def test_ursula_startup_ip_checkup(click_runner, mocker):
|
||||
target = "nucypher.cli.actions.configure.determine_external_ip_address"
|
||||
|
||||
# Patch the get_external_ip call
|
||||
|
|
|
@ -43,7 +43,8 @@ def mock_dkg_tracker(mocker):
|
|||
return mock
|
||||
|
||||
|
||||
def test_interactive_initialize_ursula(click_runner, mocker, tmpdir, test_registry_source_manager):
|
||||
@pytest.mark.usefixtures("mock_registry_sources")
|
||||
def test_interactive_initialize_ursula(click_runner, mocker, tmpdir):
|
||||
|
||||
# Mock out filesystem writes
|
||||
mocker.patch.object(UrsulaConfiguration, 'initialize', autospec=True)
|
||||
|
@ -83,8 +84,9 @@ def test_interactive_initialize_ursula(click_runner, mocker, tmpdir, test_regist
|
|||
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, testerchain
|
||||
):
|
||||
deploy_port = select_test_port()
|
||||
# Use a custom local filepath for configuration
|
||||
init_args = (
|
||||
|
@ -133,8 +135,9 @@ def test_initialize_custom_configuration_root(click_runner, custom_filepath: Pat
|
|||
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
|
||||
):
|
||||
custom_config_filepath = custom_filepath / UrsulaConfiguration.generate_filename()
|
||||
assert custom_config_filepath.is_file(), 'Configuration file does not exist'
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ def mock_account_password_keystore(tmp_path_factory):
|
|||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"test_registry_source_manager", "monkeypatch_get_staking_provider_from_operator"
|
||||
"mock_registry_sources", "monkeypatch_get_staking_provider_from_operator"
|
||||
)
|
||||
def test_ursula_init_with_local_keystore_signer(
|
||||
click_runner, temp_dir_path, mocker, testerchain, mock_account_password_keystore
|
||||
|
|
|
@ -37,10 +37,12 @@ all_configurations = tuple(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("monkeypatch_get_staking_provider_from_operator")
|
||||
@pytest.mark.usefixtures(
|
||||
"mock_registry_sources", "monkeypatch_get_staking_provider_from_operator"
|
||||
)
|
||||
@pytest.mark.parametrize("character,configuration", characters_and_configurations)
|
||||
def test_development_character_configurations(
|
||||
character, configuration, test_registry_source_manager, mocker, testerchain
|
||||
character, configuration, mocker, testerchain
|
||||
):
|
||||
mocker.patch.object(
|
||||
CharacterConfiguration, "DEFAULT_PRE_PAYMENT_NETWORK", TEMPORARY_DOMAIN
|
||||
|
@ -96,7 +98,6 @@ def test_development_character_configurations(
|
|||
def test_default_character_configuration_preservation(
|
||||
configuration_class,
|
||||
testerchain,
|
||||
test_registry_source_manager,
|
||||
tmpdir,
|
||||
test_registry,
|
||||
):
|
||||
|
@ -170,7 +171,7 @@ def test_default_character_configuration_preservation(
|
|||
expected_filepath.unlink()
|
||||
|
||||
|
||||
def test_ursula_development_configuration(test_registry_source_manager, testerchain):
|
||||
def test_ursula_development_configuration(testerchain):
|
||||
config = UrsulaConfiguration(
|
||||
dev_mode=True,
|
||||
checksum_address=testerchain.unassigned_accounts[0],
|
||||
|
|
|
@ -38,7 +38,7 @@ def ursula_v4_config_filepath(tempfile_path):
|
|||
return tempfile_path
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("test_registry_source_manager")
|
||||
@pytest.mark.usefixtures("mock_registry_sources")
|
||||
def test_migrate_v4_to_latest(ursula_v4_config_filepath):
|
||||
_do_migration(config_file=ursula_v4_config_filepath)
|
||||
|
||||
|
|
|
@ -10,9 +10,7 @@ from tests.constants import INSECURE_DEVELOPMENT_PASSWORD, MOCK_ETH_PROVIDER_URI
|
|||
from tests.utils.middleware import MockRestMiddleware
|
||||
|
||||
|
||||
def test_alices_powers_are_persistent(
|
||||
ursulas, temp_dir_path, test_registry_source_manager, testerchain
|
||||
):
|
||||
def test_alices_powers_are_persistent(ursulas, temp_dir_path, testerchain):
|
||||
# Create a non-learning AliceConfiguration
|
||||
config_root = temp_dir_path / 'nucypher-custom-alice-config'
|
||||
alice_config = AliceConfiguration(
|
||||
|
|
|
@ -65,9 +65,8 @@ def test_generate_alice_keystore(temp_dir_path):
|
|||
assert delegating_pubkey == another_delegating_pubkey
|
||||
|
||||
|
||||
def test_characters_use_keystore(
|
||||
temp_dir_path, test_registry_source_manager, testerchain
|
||||
):
|
||||
@pytest.mark.usefixtures("mock_registry_sources")
|
||||
def test_characters_use_keystore(temp_dir_path, testerchain):
|
||||
keystore = Keystore.generate(
|
||||
password=INSECURE_DEVELOPMENT_PASSWORD,
|
||||
keystore_dir=temp_dir_path
|
||||
|
|
|
@ -76,6 +76,7 @@ class BaseTestNodeStorageBackends:
|
|||
# Storage Backend Tests
|
||||
#
|
||||
|
||||
@pytest.mark.usefixtures("mock_registry_sources")
|
||||
def test_read_and_write_to_storage(self, light_ursula, testerchain):
|
||||
assert self._read_and_write_metadata(ursula=light_ursula,
|
||||
node_storage=self.storage_backend,
|
||||
|
|
|
@ -19,12 +19,15 @@ from nucypher.blockchain.eth.interfaces import (
|
|||
BlockchainInterfaceFactory,
|
||||
)
|
||||
from nucypher.blockchain.eth.networks import NetworksInventory
|
||||
from nucypher.blockchain.eth.registry import InMemoryContractRegistry
|
||||
from nucypher.blockchain.eth.registry import (
|
||||
ContractRegistry,
|
||||
)
|
||||
from nucypher.blockchain.eth.signers import KeystoreSigner
|
||||
from nucypher.blockchain.eth.signers.software import Web3Signer
|
||||
from nucypher.characters.lawful import Ursula
|
||||
from nucypher.cli.types import ChecksumAddress
|
||||
from nucypher.config.characters import UrsulaConfiguration
|
||||
from nucypher.config.constants import TEMPORARY_DOMAIN
|
||||
from nucypher.crypto.powers import TransactingPower
|
||||
from nucypher.network.nodes import Teacher
|
||||
from tests.constants import (
|
||||
|
@ -33,8 +36,9 @@ from tests.constants import (
|
|||
NUMBER_OF_MOCK_KEYSTORE_ACCOUNTS,
|
||||
TESTERCHAIN_CHAIN_ID,
|
||||
)
|
||||
from tests.mock.interfaces import MockBlockchain, mock_registry_source_manager
|
||||
from tests.mock.interfaces import MockBlockchain
|
||||
from tests.mock.io import MockStdinWrapper
|
||||
from tests.utils.registry import MockRegistrySource, mock_registry_sources
|
||||
from tests.utils.ursula import (
|
||||
mock_permitted_multichain_connections,
|
||||
setup_multichain_ursulas,
|
||||
|
@ -129,14 +133,10 @@ def mock_interface(module_mocker):
|
|||
|
||||
@pytest.fixture(scope='module')
|
||||
def test_registry():
|
||||
registry = InMemoryContractRegistry()
|
||||
return registry
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def test_registry_source_manager(testerchain, test_registry):
|
||||
with mock_registry_source_manager(test_registry=test_registry) as real_inventory:
|
||||
yield real_inventory
|
||||
with mock_registry_sources():
|
||||
mock_source = MockRegistrySource(domain=TEMPORARY_DOMAIN)
|
||||
registry = ContractRegistry(source=mock_source)
|
||||
yield registry
|
||||
|
||||
|
||||
@pytest.fixture(scope='module', autouse=True)
|
||||
|
|
|
@ -38,7 +38,7 @@ performance bottlenecks.
|
|||
|
||||
|
||||
@pytest.mark.usefixtures("monkeypatch_get_staking_provider_from_operator")
|
||||
def test_alice_can_learn_about_a_whole_bunch_of_ursulas(highperf_mocked_alice, test_registry_source_manager):
|
||||
def test_alice_can_learn_about_a_whole_bunch_of_ursulas(highperf_mocked_alice):
|
||||
# During the fixture execution, Alice verified one node.
|
||||
# TODO: Consider changing this - #1449
|
||||
assert VerificationTracker.node_verifications == 1
|
||||
|
|
|
@ -7,9 +7,7 @@ from nucypher.network.middleware import RestMiddleware
|
|||
from tests.constants import MOCK_ETH_PROVIDER_URI
|
||||
|
||||
|
||||
def test_proper_seed_node_instantiation(
|
||||
lonely_ursula_maker, test_registry_source_manager
|
||||
):
|
||||
def test_proper_seed_node_instantiation(lonely_ursula_maker):
|
||||
_lonely_ursula_maker = partial(lonely_ursula_maker, quantity=1)
|
||||
firstula = _lonely_ursula_maker(domain="this-is-meaningful-now").pop()
|
||||
firstula_as_seed_node = firstula.seed_node_metadata()
|
||||
|
|
|
@ -42,7 +42,7 @@ def test_alice_finds_ursula_via_rest(alice, ursulas):
|
|||
|
||||
|
||||
@pytest.mark.usefixtures("monkeypatch_get_staking_provider_from_operator")
|
||||
def test_vladimir_illegal_interface_key_does_not_propagate(ursulas, test_registry_source_manager):
|
||||
def test_vladimir_illegal_interface_key_does_not_propagate(ursulas):
|
||||
"""
|
||||
Although Ursulas propagate each other's interface information, as demonstrated above,
|
||||
they do not propagate interface information for Vladimir.
|
||||
|
|
|
@ -9,9 +9,7 @@ from nucypher.characters.lawful import Ursula
|
|||
|
||||
|
||||
@pytest_twisted.inlineCallbacks
|
||||
def test_nodes_connect_via_tls_and_verify(
|
||||
lonely_ursula_maker, test_registry_source_manager
|
||||
):
|
||||
def test_nodes_connect_via_tls_and_verify(lonely_ursula_maker):
|
||||
node = lonely_ursula_maker(quantity=1).pop()
|
||||
node_deployer = node.get_deployer()
|
||||
|
||||
|
|
|
@ -11,9 +11,7 @@ from tests.utils.ursula import make_ursulas
|
|||
|
||||
|
||||
@pytest_twisted.inlineCallbacks
|
||||
def test_ursula_serves_statics(
|
||||
ursula_test_config, testerchain, test_registry_source_manager
|
||||
):
|
||||
def test_ursula_serves_statics(ursula_test_config, testerchain):
|
||||
with tempfile.TemporaryDirectory() as STATICS_DIR:
|
||||
os.environ['NUCYPHER_STATIC_FILES_ROOT'] = str(STATICS_DIR)
|
||||
|
||||
|
|
|
@ -1,62 +1,15 @@
|
|||
|
||||
|
||||
|
||||
import json
|
||||
from contextlib import contextmanager
|
||||
from typing import Union
|
||||
|
||||
from hexbytes import HexBytes
|
||||
|
||||
from nucypher.blockchain.eth.clients import EthereumTesterClient
|
||||
from nucypher.blockchain.eth.networks import NetworksInventory
|
||||
from nucypher.blockchain.eth.registry import (
|
||||
BaseContractRegistry,
|
||||
CanonicalRegistrySource,
|
||||
RegistrySourceManager,
|
||||
)
|
||||
from nucypher.config.constants import TEMPORARY_DOMAIN
|
||||
from tests.constants import MOCK_ETH_PROVIDER_URI, TESTERCHAIN_CHAIN_ID
|
||||
from tests.utils.blockchain import TesterBlockchain
|
||||
|
||||
|
||||
@contextmanager
|
||||
def mock_registry_source_manager(test_registry):
|
||||
|
||||
class MockRegistrySource(CanonicalRegistrySource):
|
||||
name = "Mock Registry Source"
|
||||
is_primary = False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if self.network != TEMPORARY_DOMAIN:
|
||||
raise ValueError(f"Somehow, MockRegistrySource is trying to get a registry for '{self.network}'. "
|
||||
f"Only '{TEMPORARY_DOMAIN}' is supported.'")
|
||||
|
||||
def get_publication_endpoint(self) -> str:
|
||||
return f":mock-registry-source:/{self.network}/{self.registry_name}"
|
||||
|
||||
def fetch_latest_publication(self) -> Union[str, bytes]:
|
||||
self.logger.debug(f"Reading registry at {self.get_publication_endpoint()}")
|
||||
if self.registry_name == BaseContractRegistry.REGISTRY_NAME:
|
||||
registry_data = test_registry.read()
|
||||
raw_registry_data = json.dumps(registry_data)
|
||||
return raw_registry_data
|
||||
|
||||
real_networks = NetworksInventory.NETWORKS
|
||||
real_eth_networks = NetworksInventory.ETH_NETWORKS
|
||||
real_poly_networks = NetworksInventory.POLY_NETWORKS
|
||||
try:
|
||||
RegistrySourceManager._FALLBACK_CHAIN = (MockRegistrySource,)
|
||||
NetworksInventory.NETWORKS = (TEMPORARY_DOMAIN,)
|
||||
NetworksInventory.ETH_NETWORKS = (TEMPORARY_DOMAIN,)
|
||||
NetworksInventory.POLY_NETWORKS = (TEMPORARY_DOMAIN,)
|
||||
yield real_networks
|
||||
finally:
|
||||
NetworksInventory.POLY_NETWORKS = real_poly_networks
|
||||
NetworksInventory.ETH_NETWORKS = real_eth_networks
|
||||
NetworksInventory.NETWORKS = real_networks
|
||||
|
||||
|
||||
class MockBlockchain(TesterBlockchain):
|
||||
|
||||
ETH_PROVIDER_URI = MOCK_ETH_PROVIDER_URI
|
||||
|
|
|
@ -4,11 +4,13 @@ from nucypher_core.ferveo import Keypair, Validator
|
|||
from nucypher.blockchain.eth.actors import Operator
|
||||
from nucypher.blockchain.eth.agents import ContractAgency
|
||||
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
|
||||
from nucypher.blockchain.eth.registry import InMemoryContractRegistry
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.config.constants import TEMPORARY_DOMAIN
|
||||
from nucypher.crypto.ferveo import dkg
|
||||
from nucypher.crypto.powers import TransactingPower
|
||||
from nucypher.network.nodes import Teacher
|
||||
from tests.mock.interfaces import MockBlockchain, MockEthereumClient
|
||||
from tests.utils.registry import MockRegistrySource, mock_registry_sources
|
||||
|
||||
|
||||
def pytest_addhooks(pluginmanager):
|
||||
|
@ -17,7 +19,9 @@ def pytest_addhooks(pluginmanager):
|
|||
|
||||
@pytest.fixture(scope='module')
|
||||
def test_registry():
|
||||
return InMemoryContractRegistry()
|
||||
with mock_registry_sources():
|
||||
source = MockRegistrySource(domain=TEMPORARY_DOMAIN)
|
||||
yield ContractRegistry(source=source)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
|
|
|
@ -12,7 +12,7 @@ Chapter 1: SIGNING
|
|||
"""
|
||||
|
||||
|
||||
def test_actor_without_signing_power_cannot_sign(test_registry_source_manager):
|
||||
def test_actor_without_signing_power_cannot_sign():
|
||||
"""
|
||||
We can create a Character with no real CryptoPower to speak of.
|
||||
This Character can't even sign a message.
|
||||
|
|
|
@ -2,7 +2,7 @@ from typing import List
|
|||
|
||||
from eth_typing import ChecksumAddress
|
||||
|
||||
from nucypher.blockchain.eth.registry import BaseContractRegistry
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.characters.lawful import Ursula
|
||||
from nucypher.config.characters import (
|
||||
AliceConfiguration,
|
||||
|
@ -23,11 +23,12 @@ TEST_CHARACTER_CONFIG_BASE_PARAMS = dict(
|
|||
)
|
||||
|
||||
|
||||
def assemble(checksum_address: str = None,
|
||||
eth_provider_uri: str = None,
|
||||
test_registry: BaseContractRegistry = None,
|
||||
known_nodes: List[Ursula] = None) -> dict:
|
||||
|
||||
def assemble(
|
||||
checksum_address: str = None,
|
||||
eth_provider_uri: str = None,
|
||||
test_registry: ContractRegistry = None,
|
||||
known_nodes: List[Ursula] = None,
|
||||
) -> dict:
|
||||
"""Assemble a dictionary of keyword arguments to use when constructing a test configuration."""
|
||||
# Generate runtime config params
|
||||
runtime_params = dict(
|
||||
|
|
Loading…
Reference in New Issue