Adapt tests and exmaples to merged Operator, without Ritualist.

pull/3230/head
Kieran Prasch 2023-09-14 19:00:24 +02:00 committed by derekpierre
parent 0f29569568
commit 499f903976
23 changed files with 259 additions and 194 deletions

View File

@ -76,8 +76,8 @@ wallet = Signer.from_signer_uri(SIGNER_URI)
password = os.environ.get('DEMO_ALICE_PASSWORD') or getpass(f"Enter password to unlock Alice's wallet ({ALICE_ADDRESS[:8]}): ") password = os.environ.get('DEMO_ALICE_PASSWORD') or getpass(f"Enter password to unlock Alice's wallet ({ALICE_ADDRESS[:8]}): ")
wallet.unlock_account(account=ALICE_ADDRESS, password=password) wallet.unlock_account(account=ALICE_ADDRESS, password=password)
# This is Alice's payment method. # This is Alice's PRE payment method.
payment_method = SubscriptionManagerPayment( pre_payment_method = SubscriptionManagerPayment(
network=L2_NETWORK, network=L2_NETWORK,
eth_provider=L2_PROVIDER eth_provider=L2_PROVIDER
) )
@ -88,7 +88,7 @@ alice = Alice(
signer=wallet, signer=wallet,
domain=L1_NETWORK, domain=L1_NETWORK,
eth_provider_uri=L1_PROVIDER, eth_provider_uri=L1_PROVIDER,
payment_method=payment_method pre_payment_method=pre_payment_method,
) )
# Alice puts her public key somewhere for Bob to find later... # Alice puts her public key somewhere for Bob to find later...
@ -113,7 +113,7 @@ remote_bob = Bob.from_public_keys(
# These are the policy details. # These are the policy details.
expiration = maya.now() + datetime.timedelta(days=1) expiration = maya.now() + datetime.timedelta(days=1)
threshold, shares = 2, 3 threshold, shares = 2, 3
price = alice.payment_method.quote(expiration=expiration.epoch, shares=shares).value price = alice.pre_payment_method.quote(expiration=expiration.epoch, shares=shares).value
# Alice grants access to Bob... # Alice grants access to Bob...
policy = alice.grant( policy = alice.grant(

View File

@ -77,8 +77,8 @@ wallet = Signer.from_signer_uri(SIGNER_URI)
password = os.environ.get('DEMO_ALICE_PASSWORD') or getpass(f"Enter password to unlock Alice's wallet ({ALICE_ADDRESS[:8]}): ") password = os.environ.get('DEMO_ALICE_PASSWORD') or getpass(f"Enter password to unlock Alice's wallet ({ALICE_ADDRESS[:8]}): ")
wallet.unlock_account(account=ALICE_ADDRESS, password=password) wallet.unlock_account(account=ALICE_ADDRESS, password=password)
# This is Alice's payment method. # This is Alice's PRE payment method.
payment_method = SubscriptionManagerPayment( pre_payment_method = SubscriptionManagerPayment(
network=L2_NETWORK, network=L2_NETWORK,
eth_provider=L2_PROVIDER eth_provider=L2_PROVIDER
) )
@ -89,7 +89,7 @@ alicia = Alice(
signer=wallet, signer=wallet,
domain=L1_NETWORK, domain=L1_NETWORK,
eth_provider_uri=L1_PROVIDER, eth_provider_uri=L1_PROVIDER,
payment_method=payment_method pre_payment_method=pre_payment_method,
) )
# Alice puts her public key somewhere for Bob to find later... # Alice puts her public key somewhere for Bob to find later...
@ -119,7 +119,7 @@ print(
# that **don't exist yet**. # that **don't exist yet**.
# In this example, we create a local file with encrypted data, containing # In this example, we create a local file with encrypted data, containing
# heart rate measurements from a heart monitor # heart rate measurements from a heart monitor
import heart_monitor import heart_monitor # ruff:noqa:F402
heart_monitor.generate_heart_rate_samples(policy_pubkey, heart_monitor.generate_heart_rate_samples(policy_pubkey,
samples=50, samples=50,
@ -129,7 +129,7 @@ heart_monitor.generate_heart_rate_samples(policy_pubkey,
# Alicia now wants to share data associated with this label. # Alicia now wants to share data associated with this label.
# To do so, she needs the public key of the recipient. # To do so, she needs the public key of the recipient.
# In this example, we generate it on the fly (for demonstration purposes) # In this example, we generate it on the fly (for demonstration purposes)
from doctor_keys import get_doctor_pubkeys from doctor_keys import get_doctor_pubkeys # ruff:noqa:F402
doctor_pubkeys = get_doctor_pubkeys() doctor_pubkeys = get_doctor_pubkeys()

View File

@ -10,7 +10,7 @@ from eth_typing import ChecksumAddress
from web3.contract.contract import ContractEvent from web3.contract.contract import ContractEvent
from web3.datastructures import AttributeDict from web3.datastructures import AttributeDict
from nucypher.blockchain.eth.actors import Ritualist from nucypher.blockchain.eth.actors import Operator
from nucypher.blockchain.eth.agents import CoordinatorAgent from nucypher.blockchain.eth.agents import CoordinatorAgent
from nucypher.blockchain.eth.trackers.dkg import ActiveRitualTracker from nucypher.blockchain.eth.trackers.dkg import ActiveRitualTracker
@ -26,7 +26,7 @@ def cohort(ursulas):
def test_action_required_not_participating(cohort): def test_action_required_not_participating(cohort):
ursula = cohort[0] ursula = cohort[0]
agent = ursula.coordinator_agent agent = ursula.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ursula) active_ritual_tracker = ActiveRitualTracker(operator=ursula)
participation_state = ActiveRitualTracker.ParticipationState( participation_state = ActiveRitualTracker.ParticipationState(
participating=False, # not participating participating=False, # not participating
@ -59,7 +59,7 @@ def test_action_required_not_participating(cohort):
def test_action_required_only_for_events_with_corresponding_actions(cohort): def test_action_required_only_for_events_with_corresponding_actions(cohort):
ursula = cohort[0] ursula = cohort[0]
agent = ursula.coordinator_agent agent = ursula.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ursula) active_ritual_tracker = ActiveRitualTracker(operator=ursula)
participation_state = ActiveRitualTracker.ParticipationState( participation_state = ActiveRitualTracker.ParticipationState(
participating=True, # participating participating=True, # participating
@ -97,7 +97,7 @@ def test_action_required_only_for_events_with_corresponding_actions(cohort):
def test_action_required_depending_on_participation_state(cohort): def test_action_required_depending_on_participation_state(cohort):
ursula = cohort[0] ursula = cohort[0]
agent = ursula.coordinator_agent agent = ursula.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ursula) active_ritual_tracker = ActiveRitualTracker(operator=ursula)
participation_state = ActiveRitualTracker.ParticipationState( participation_state = ActiveRitualTracker.ParticipationState(
participating=True, participating=True,
@ -161,7 +161,7 @@ def test_get_participation_state_start_ritual(cohort, get_random_checksum_addres
args_dict = {"ritualId": ritual_id} args_dict = {"ritualId": ritual_id}
ursula = cohort[0] ursula = cohort[0]
agent = ursula.coordinator_agent agent = ursula.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ursula) active_ritual_tracker = ActiveRitualTracker(operator=ursula)
# StartRitual # StartRitual
start_ritual_event = agent.contract.events.StartRitual() start_ritual_event = agent.contract.events.StartRitual()
@ -220,7 +220,7 @@ def test_get_participation_state_start_aggregation_round_participation_not_alrea
args_dict = {"ritualId": ritual_id} args_dict = {"ritualId": ritual_id}
ursula = cohort[0] ursula = cohort[0]
agent = ursula.coordinator_agent agent = ursula.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ursula) active_ritual_tracker = ActiveRitualTracker(operator=ursula)
start_aggregation_round_event = agent.contract.events.StartAggregationRound() start_aggregation_round_event = agent.contract.events.StartAggregationRound()
@ -286,7 +286,7 @@ def test_get_participation_state_start_aggregation_round_participation_already_t
args_dict = {"ritualId": ritual_id} args_dict = {"ritualId": ritual_id}
ursula = cohort[0] ursula = cohort[0]
agent = ursula.coordinator_agent agent = ursula.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ursula) active_ritual_tracker = ActiveRitualTracker(operator=ursula)
start_aggregation_round_event = agent.contract.events.StartAggregationRound() start_aggregation_round_event = agent.contract.events.StartAggregationRound()
@ -354,7 +354,7 @@ def test_get_participation_state_end_ritual_participation_not_already_tracked(
args_dict = {"ritualId": ritual_id} args_dict = {"ritualId": ritual_id}
ursula = cohort[0] ursula = cohort[0]
agent = ursula.coordinator_agent agent = ursula.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ursula) active_ritual_tracker = ActiveRitualTracker(operator=ursula)
end_ritual_event = agent.contract.events.EndRitual() end_ritual_event = agent.contract.events.EndRitual()
@ -486,7 +486,7 @@ def test_get_participation_state_end_ritual_participation_already_tracked(
args_dict = {"ritualId": ritual_id} args_dict = {"ritualId": ritual_id}
ursula = cohort[0] ursula = cohort[0]
agent = ursula.coordinator_agent agent = ursula.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ursula) active_ritual_tracker = ActiveRitualTracker(operator=ursula)
end_ritual_event = agent.contract.events.EndRitual() end_ritual_event = agent.contract.events.EndRitual()
@ -539,7 +539,7 @@ def test_get_participation_state_end_ritual_participation_already_tracked(
def test_get_participation_state_unexpected_event_without_ritual_id_arg(cohort): def test_get_participation_state_unexpected_event_without_ritual_id_arg(cohort):
ursula = cohort[0] ursula = cohort[0]
agent = ursula.coordinator_agent agent = ursula.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ursula) active_ritual_tracker = ActiveRitualTracker(operator=ursula)
# TimeoutChanged # TimeoutChanged
timeout_changed_event = agent.contract.events.TimeoutChanged() timeout_changed_event = agent.contract.events.TimeoutChanged()
@ -563,7 +563,7 @@ def test_get_participation_state_unexpected_event_without_ritual_id_arg(cohort):
def test_get_participation_state_unexpected_event_with_ritual_id_arg(cohort): def test_get_participation_state_unexpected_event_with_ritual_id_arg(cohort):
ursula = cohort[0] ursula = cohort[0]
agent = ursula.coordinator_agent agent = ursula.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ursula) active_ritual_tracker = ActiveRitualTracker(operator=ursula)
# create args data - faked to include ritual id arg # create args data - faked to include ritual id arg
args_dict = {"ritualId": 0, "oldTimeout": 1, "newTimeout": 2} args_dict = {"ritualId": 0, "oldTimeout": 1, "newTimeout": 2}
@ -598,7 +598,7 @@ def test_get_participation_state_purge_expired_cache_entries(
with patch.object(agent, "get_timeout", return_value=faked_ritual_timeout): with patch.object(agent, "get_timeout", return_value=faked_ritual_timeout):
# fake timeout only needed for initialization # fake timeout only needed for initialization
active_ritual_tracker = ActiveRitualTracker(ritualist=ursula) active_ritual_tracker = ActiveRitualTracker(operator=ursula)
now = maya.now() now = maya.now()
@ -727,11 +727,11 @@ def test_handle_event_multiple_concurrent_rituals(cohort, get_random_checksum_ad
ursula = cohort[0] ursula = cohort[0]
ritualist = Mock(spec=Ritualist) operator = Mock(spec=Operator)
ritualist.checksum_address = ursula.checksum_address operator.checksum_address = ursula.checksum_address
ritualist.coordinator_agent = ursula.coordinator_agent operator.coordinator_agent = ursula.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ritualist) active_ritual_tracker = ActiveRitualTracker(operator=operator)
block_number = 17692417 # random block number - value doesn't matter block_number = 17692417 # random block number - value doesn't matter
@ -776,17 +776,15 @@ def test_handle_event_multiple_concurrent_rituals(cohort, get_random_checksum_ad
assert len(active_ritual_tracker._participation_states) == (i + 1) assert len(active_ritual_tracker._participation_states) == (i + 1)
participation_state = active_ritual_tracker._participation_states[r_id] participation_state = active_ritual_tracker._participation_states[r_id]
if r_id != ritual_id_4: if r_id != ritual_id_4:
ritualist.perform_round_1.assert_called_with( operator.perform_round_1.assert_called_with(
ritual_id=r_id, initiator=ANY, participants=ANY, timestamp=ANY ritual_id=r_id, initiator=ANY, participants=ANY, timestamp=ANY
) )
check_participation_state(participation_state, expected_participating=True) check_participation_state(participation_state, expected_participating=True)
else: else:
check_participation_state(participation_state, expected_participating=False) check_participation_state(participation_state, expected_participating=False)
assert ( assert operator.perform_round_1.call_count == 3 # participation and action required
ritualist.perform_round_1.call_count == 3 assert operator.perform_round_2.call_count == 0 # nothing to do here
) # participation and action required
assert ritualist.perform_round_2.call_count == 0 # nothing to do here
assert len(active_ritual_tracker._participation_states) == 4 assert len(active_ritual_tracker._participation_states) == 4
# #
@ -806,9 +804,9 @@ def test_handle_event_multiple_concurrent_rituals(cohort, get_random_checksum_ad
d = active_ritual_tracker._handle_ritual_event(event_data, get_block_when) d = active_ritual_tracker._handle_ritual_event(event_data, get_block_when)
yield d yield d
assert ritualist.perform_round_1.call_count == 3 # same count as before assert operator.perform_round_1.call_count == 3 # same count as before
assert ritualist.perform_round_2.call_count == 1 # nothing to do here assert operator.perform_round_2.call_count == 1 # nothing to do here
ritualist.perform_round_2.assert_called_with(ritual_id=ritual_id_2, timestamp=ANY) operator.perform_round_2.assert_called_with(ritual_id=ritual_id_2, timestamp=ANY)
check_participation_state( check_participation_state(
active_ritual_tracker._participation_states[ritual_id_1], active_ritual_tracker._participation_states[ritual_id_1],
@ -842,8 +840,8 @@ def test_handle_event_multiple_concurrent_rituals(cohort, get_random_checksum_ad
d = active_ritual_tracker._handle_ritual_event(event_data, get_block_when) d = active_ritual_tracker._handle_ritual_event(event_data, get_block_when)
yield d yield d
assert ritualist.perform_round_1.call_count == 3 # same as before assert operator.perform_round_1.call_count == 3 # same as before
assert ritualist.perform_round_2.call_count == 1 # same as before assert operator.perform_round_2.call_count == 1 # same as before
check_participation_state( check_participation_state(
active_ritual_tracker._participation_states[ritual_id_1], active_ritual_tracker._participation_states[ritual_id_1],
@ -882,8 +880,8 @@ def test_handle_event_multiple_concurrent_rituals(cohort, get_random_checksum_ad
d = active_ritual_tracker._handle_ritual_event(event_data, get_block_when) d = active_ritual_tracker._handle_ritual_event(event_data, get_block_when)
yield d yield d
assert ritualist.perform_round_1.call_count == 3 # same as before assert operator.perform_round_1.call_count == 3 # same as before
assert ritualist.perform_round_2.call_count == 1 # same as before assert operator.perform_round_2.call_count == 1 # same as before
assert len(active_ritual_tracker._participation_states) == 4 assert len(active_ritual_tracker._participation_states) == 4
@ -924,8 +922,8 @@ def test_handle_event_multiple_concurrent_rituals(cohort, get_random_checksum_ad
d = active_ritual_tracker._handle_ritual_event(event_data, get_block_when) d = active_ritual_tracker._handle_ritual_event(event_data, get_block_when)
yield d yield d
assert ritualist.perform_round_1.call_count == 3 # same as before assert operator.perform_round_1.call_count == 3 # same as before
assert ritualist.perform_round_2.call_count == 1 # same as before assert operator.perform_round_2.call_count == 1 # same as before
check_participation_state( check_participation_state(
active_ritual_tracker._participation_states[ritual_id_1], active_ritual_tracker._participation_states[ritual_id_1],

View File

@ -10,7 +10,7 @@ from web3.middleware.simulate_unmined_transaction import (
unmined_receipt_simulator_middleware, unmined_receipt_simulator_middleware,
) )
from nucypher.blockchain.eth.actors import Operator, Ritualist from nucypher.blockchain.eth.actors import Operator
from nucypher.blockchain.eth.constants import NULL_ADDRESS from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.signers.software import Web3Signer from nucypher.blockchain.eth.signers.software import Web3Signer
from nucypher.blockchain.eth.trackers.pre import WorkTracker, WorkTrackerBase from nucypher.blockchain.eth.trackers.pre import WorkTracker, WorkTrackerBase
@ -89,7 +89,7 @@ def test_ursula_operator_confirmation_autopilot(
operator2 = testerchain.ursula_account(1) operator2 = testerchain.ursula_account(1)
min_authorization = taco_application_agent.get_min_authorization() min_authorization = taco_application_agent.get_min_authorization()
confirmation_spy = mocker.spy(Ritualist, "set_provider_public_key") confirmation_spy = mocker.spy(Operator, "set_provider_public_key")
# TODO: WorkerTracker may no longer be needed # TODO: WorkerTracker may no longer be needed
replacement_confirmation_spy = mocker.spy( replacement_confirmation_spy = mocker.spy(
WorkTrackerBase, "_WorkTrackerBase__fire_replacement_commitment" WorkTrackerBase, "_WorkTrackerBase__fire_replacement_commitment"

View File

@ -1,6 +1,7 @@
import datetime import datetime
import maya
import os import os
import maya
from nucypher_core import EncryptedKeyFrag from nucypher_core import EncryptedKeyFrag
from nucypher.config.constants import TEMPORARY_DOMAIN from nucypher.config.constants import TEMPORARY_DOMAIN
@ -28,8 +29,10 @@ def check(policy, bob, ursulas):
def test_grant_subscription_manager(alice, bob, ursulas, test_registry_source_manager): def test_grant_subscription_manager(alice, bob, ursulas, test_registry_source_manager):
payment_method = SubscriptionManagerPayment(eth_provider=TEST_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN) pre_payment_method = SubscriptionManagerPayment(
alice.payment_method = payment_method eth_provider=TEST_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN
)
alice.pre_payment_method = pre_payment_method
policy = alice.grant( policy = alice.grant(
bob=bob, bob=bob,
label=os.urandom(16), label=os.urandom(16),

View File

@ -126,7 +126,7 @@ def test_ursula_and_local_keystore_signer_integration(
"init", "init",
"--network", "--network",
TEMPORARY_DOMAIN, TEMPORARY_DOMAIN,
"--payment-network", "--pre-payment-network",
TEMPORARY_DOMAIN, TEMPORARY_DOMAIN,
"--operator-address", "--operator-address",
worker_account.address, worker_account.address,
@ -134,7 +134,7 @@ def test_ursula_and_local_keystore_signer_integration(
str(config_root_path.absolute()), str(config_root_path.absolute()),
"--eth-provider", "--eth-provider",
TEST_ETH_PROVIDER_URI, TEST_ETH_PROVIDER_URI,
"--payment-provider", "--pre-payment-provider",
TEST_POLYGON_PROVIDER_URI, TEST_POLYGON_PROVIDER_URI,
"--rest-host", "--rest-host",
MOCK_IP_ADDRESS, MOCK_IP_ADDRESS,

View File

@ -1,8 +1,8 @@
import time
from unittest import mock from unittest import mock
import pytest import pytest
import pytest_twisted as pt import pytest_twisted as pt
import time
from twisted.internet import threads from twisted.internet import threads
from nucypher.blockchain.eth.actors import Operator from nucypher.blockchain.eth.actors import Operator
@ -37,45 +37,60 @@ def test_missing_configuration_file(_default_filepath_mock, click_runner):
@pt.inlineCallbacks @pt.inlineCallbacks
def test_ursula_run_with_prometheus_but_no_metrics_port(click_runner): def test_ursula_run_with_prometheus_but_no_metrics_port(click_runner):
args = ('ursula', 'run', # Stat Ursula Command args = (
'--debug', # Display log output; Do not attach console "ursula",
'--dev', # Run in development mode (local ephemeral node) "run", # Stat Ursula Command
'--dry-run', # Disable twisted reactor in subprocess "--debug", # Display log output; Do not attach console
'--lonely', # Do not load seednodes "--dev", # Run in development mode (local ephemeral node)
'--prometheus', # Specify collection of prometheus metrics "--dry-run", # Disable twisted reactor in subprocess
'--eth-provider', TEST_ETH_PROVIDER_URI, "--lonely", # Do not load seednodes
'--payment-provider', TEST_POLYGON_PROVIDER_URI "--prometheus", # Specify collection of prometheus metrics
"--eth-provider",
TEST_ETH_PROVIDER_URI,
"--pre-payment-provider",
TEST_POLYGON_PROVIDER_URI,
) )
result = yield threads.deferToThread(click_runner.invoke, result = yield threads.deferToThread(
nucypher_cli, args, click_runner.invoke, nucypher_cli, args, catch_exceptions=False
catch_exceptions=False) )
assert result.exit_code != 0 assert result.exit_code != 0
expected_error = f"Error: --metrics-port is required when using --prometheus" expected_error = "Error: --metrics-port is required when using --prometheus"
assert expected_error in result.output assert expected_error in result.output
@pt.inlineCallbacks @pt.inlineCallbacks
def test_run_lone_default_development_ursula(click_runner, test_registry_source_manager, testerchain, mock_funding_and_bonding): def test_run_lone_default_development_ursula(
click_runner, test_registry_source_manager, testerchain, mock_funding_and_bonding
):
deploy_port = select_test_port() deploy_port = select_test_port()
args = ('ursula', 'run', # Stat Ursula Command args = (
'--debug', # Display log output; Do not attach console "ursula",
'--rest-port', deploy_port, # Network Port "run", # Stat Ursula Command
'--dev', # Run in development mode (ephemeral node) "--debug", # Display log output; Do not attach console
'--dry-run', # Disable twisted reactor in subprocess "--rest-port",
'--lonely', # Do not load seednodes, deploy_port, # Network Port
'--operator-address', testerchain.etherbase_account, "--dev", # Run in development mode (ephemeral node)
'--eth-provider', TEST_ETH_PROVIDER_URI, "--dry-run", # Disable twisted reactor in subprocess
'--payment-provider', TEST_ETH_PROVIDER_URI, "--lonely", # Do not load seednodes,
'--payment-network', TEMPORARY_DOMAIN, "--operator-address",
testerchain.etherbase_account,
"--eth-provider",
TEST_ETH_PROVIDER_URI,
"--pre-payment-provider",
TEST_ETH_PROVIDER_URI,
"--pre-payment-network",
TEMPORARY_DOMAIN,
) )
result = yield threads.deferToThread(click_runner.invoke, result = yield threads.deferToThread(
nucypher_cli, args, click_runner.invoke,
nucypher_cli,
args,
catch_exceptions=False, catch_exceptions=False,
input=INSECURE_DEVELOPMENT_PASSWORD + '\n') input=INSECURE_DEVELOPMENT_PASSWORD + "\n",
)
time.sleep(Learner._SHORT_LEARNING_DELAY) time.sleep(Learner._SHORT_LEARNING_DELAY)
assert result.exit_code == 0, result.output assert result.exit_code == 0, result.output
@ -102,23 +117,34 @@ def test_ursula_learns_via_cli(
deploy_port = select_test_port() deploy_port = select_test_port()
def run_ursula(): def run_ursula():
i = start_pytest_ursula_services(ursula=teacher) start_pytest_ursula_services(ursula=teacher)
args = ('ursula', 'run', args = (
'--debug', # Display log output; Do not attach console "ursula",
'--rest-port', deploy_port, # Network Port "run",
'--teacher', teacher_uri, "--debug", # Display log output; Do not attach console
'--dev', # Run in development mode (ephemeral node) "--rest-port",
'--dry-run', # Disable twisted reactor deploy_port, # Network Port
'--operator-address', testerchain.etherbase_account, "--teacher",
'--eth-provider', TEST_ETH_PROVIDER_URI, teacher_uri,
'--payment-provider', TEST_ETH_PROVIDER_URI, "--dev", # Run in development mode (ephemeral node)
'--payment-network', TEMPORARY_DOMAIN "--dry-run", # Disable twisted reactor
"--operator-address",
testerchain.etherbase_account,
"--eth-provider",
TEST_ETH_PROVIDER_URI,
"--pre-payment-provider",
TEST_ETH_PROVIDER_URI,
"--pre-payment-network",
TEMPORARY_DOMAIN,
) )
return threads.deferToThread(click_runner.invoke, return threads.deferToThread(
nucypher_cli, args, click_runner.invoke,
nucypher_cli,
args,
catch_exceptions=False, catch_exceptions=False,
input=INSECURE_DEVELOPMENT_PASSWORD + '\n') input=INSECURE_DEVELOPMENT_PASSWORD + "\n",
)
# Run the Callbacks # Run the Callbacks
d = run_ursula() d = run_ursula()
@ -142,25 +168,42 @@ def test_ursula_learns_via_cli(
def test_persistent_node_storage_integration( def test_persistent_node_storage_integration(
click_runner, custom_filepath, testerchain, ursulas, agency_local_registry, mocker click_runner, custom_filepath, testerchain, ursulas, agency_local_registry, mocker
): ):
mocker.patch.object(ActiveRitualTracker, "start")
mocker.patch.object(ActiveRitualTracker, 'start') (
alice, ursula, another_ursula, staking_provider, *all_yall = testerchain.unassigned_accounts alice,
ursula,
another_ursula,
staking_provider,
*all_yall,
) = testerchain.unassigned_accounts
filename = UrsulaConfiguration.generate_filename() filename = UrsulaConfiguration.generate_filename()
another_ursula_configuration_file_location = custom_filepath / filename another_ursula_configuration_file_location = custom_filepath / filename
init_args = ('ursula', 'init', init_args = (
'--eth-provider', TEST_ETH_PROVIDER_URI, "ursula",
'--payment-provider', TEST_POLYGON_PROVIDER_URI, "init",
'--operator-address', another_ursula, "--eth-provider",
'--network', TEMPORARY_DOMAIN, TEST_ETH_PROVIDER_URI,
'--payment-network', TEMPORARY_DOMAIN, "--pre-payment-provider",
'--rest-host', MOCK_IP_ADDRESS, TEST_POLYGON_PROVIDER_URI,
'--config-root', str(custom_filepath.absolute()), "--operator-address",
'--registry-filepath', str(agency_local_registry.filepath.absolute()), another_ursula,
"--network",
TEMPORARY_DOMAIN,
"--pre-payment-network",
TEMPORARY_DOMAIN,
"--rest-host",
MOCK_IP_ADDRESS,
"--config-root",
str(custom_filepath.absolute()),
"--registry-filepath",
str(agency_local_registry.filepath.absolute()),
) )
envvars = {NUCYPHER_ENVVAR_KEYSTORE_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD} envvars = {NUCYPHER_ENVVAR_KEYSTORE_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD}
result = click_runner.invoke(nucypher_cli, init_args, catch_exceptions=False, env=envvars) result = click_runner.invoke(
nucypher_cli, init_args, catch_exceptions=False, env=envvars
)
assert result.exit_code == 0 assert result.exit_code == 0
teacher = ursulas[-1] teacher = ursulas[-1]

View File

@ -3,7 +3,7 @@ import random
import pytest import pytest
from web3 import Web3 from web3 import Web3
from nucypher.blockchain.eth.actors import Ritualist from nucypher.blockchain.eth.actors import Operator
from nucypher.blockchain.eth.agents import ( from nucypher.blockchain.eth.agents import (
ContractAgency, ContractAgency,
CoordinatorAgent, CoordinatorAgent,
@ -480,5 +480,5 @@ def mock_condition_blockchains(session_mocker):
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module", autouse=True)
def mock_multichain_configuration(module_mocker, testerchain): def mock_multichain_configuration(module_mocker, testerchain):
module_mocker.patch.object( module_mocker.patch.object(
Ritualist, "_make_condition_provider", return_value=testerchain.provider Operator, "_make_condition_provider", return_value=testerchain.provider
) )

View File

@ -3,7 +3,7 @@ from collections import defaultdict
import pytest import pytest
from eth_utils.crypto import keccak from eth_utils.crypto import keccak
from nucypher.blockchain.eth.actors import Ritualist from nucypher.blockchain.eth.actors import Operator
from nucypher.blockchain.eth.networks import NetworksInventory from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.crypto.powers import TransactingPower from nucypher.crypto.powers import TransactingPower
from nucypher.network.nodes import Learner from nucypher.network.nodes import Learner
@ -92,7 +92,6 @@ def check_character_state_after_test(request):
from nucypher.network.nodes import Learner from nucypher.network.nodes import Learner
yield yield
if Learner._DEBUG_MODE: if Learner._DEBUG_MODE:
gmwe = global_mutable_where_everybody
module_name = request.module.__name__ module_name = request.module.__name__
test_learners = global_mutable_where_everybody.get(module_name, []) test_learners = global_mutable_where_everybody.get(module_name, [])
@ -159,5 +158,5 @@ def mock_condition_blockchains(session_mocker):
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module", autouse=True)
def mock_multichain_configuration(module_mocker, testerchain): def mock_multichain_configuration(module_mocker, testerchain):
module_mocker.patch.object( module_mocker.patch.object(
Ritualist, "_make_condition_provider", return_value=testerchain.provider Operator, "_make_condition_provider", return_value=testerchain.provider
) )

View File

@ -133,7 +133,7 @@ def random_address(random_account):
def ursula_test_config(test_registry, temp_dir_path, testerchain): def ursula_test_config(test_registry, temp_dir_path, testerchain):
config = make_ursula_test_configuration( config = make_ursula_test_configuration(
eth_provider_uri=TEST_ETH_PROVIDER_URI, eth_provider_uri=TEST_ETH_PROVIDER_URI,
payment_provider=TEST_ETH_PROVIDER_URI, pre_payment_provider=TEST_ETH_PROVIDER_URI,
test_registry=test_registry, test_registry=test_registry,
rest_port=select_test_port(), rest_port=select_test_port(),
operator_address=testerchain.ursulas_accounts.pop(), operator_address=testerchain.ursulas_accounts.pop(),
@ -148,7 +148,7 @@ def ursula_test_config(test_registry, temp_dir_path, testerchain):
def alice_test_config(ursulas, testerchain, test_registry): def alice_test_config(ursulas, testerchain, test_registry):
config = make_alice_test_configuration( config = make_alice_test_configuration(
eth_provider_uri=TEST_ETH_PROVIDER_URI, eth_provider_uri=TEST_ETH_PROVIDER_URI,
payment_provider=TEST_ETH_PROVIDER_URI, pre_payment_provider=TEST_ETH_PROVIDER_URI,
known_nodes=ursulas, known_nodes=ursulas,
checksum_address=testerchain.alice_account, checksum_address=testerchain.alice_account,
test_registry=test_registry, test_registry=test_registry,
@ -177,7 +177,7 @@ def idle_policy(testerchain, alice, bob, application_economics):
random_label = generate_random_label() random_label = generate_random_label()
expiration = maya.now() + timedelta(days=1) expiration = maya.now() + timedelta(days=1)
threshold, shares = 3, 5 threshold, shares = 3, 5
price = alice.payment_method.quote( price = alice.pre_payment_method.quote(
expiration=expiration.epoch, shares=shares expiration=expiration.epoch, shares=shares
).value # TODO: use default quote option ).value # TODO: use default quote option
policy = alice.create_policy( policy = alice.create_policy(
@ -339,7 +339,7 @@ def light_ursula(temp_dir_path, test_registry_source_manager, random_account, mo
mocker.patch.object( mocker.patch.object(
KeystoreSigner, "_KeystoreSigner__get_signer", return_value=random_account KeystoreSigner, "_KeystoreSigner__get_signer", return_value=random_account
) )
payment_method = SubscriptionManagerPayment( pre_payment_method = SubscriptionManagerPayment(
eth_provider=MOCK_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN eth_provider=MOCK_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN
) )
@ -351,7 +351,7 @@ def light_ursula(temp_dir_path, test_registry_source_manager, random_account, mo
rest_host=LOOPBACK_ADDRESS, rest_host=LOOPBACK_ADDRESS,
rest_port=select_test_port(), rest_port=select_test_port(),
domain=TEMPORARY_DOMAIN, domain=TEMPORARY_DOMAIN,
payment_method=payment_method, pre_payment_method=pre_payment_method,
checksum_address=random_account.address, checksum_address=random_account.address,
operator_address=random_account.address, operator_address=random_account.address,
eth_provider_uri=MOCK_ETH_PROVIDER_URI, eth_provider_uri=MOCK_ETH_PROVIDER_URI,
@ -447,8 +447,15 @@ def fleet_of_highperf_mocked_ursulas(
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def highperf_mocked_alice(fleet_of_highperf_mocked_ursulas, test_registry_source_manager, monkeymodule, testerchain): def highperf_mocked_alice(
monkeymodule.setattr(CharacterConfiguration, 'DEFAULT_PAYMENT_NETWORK', TEMPORARY_DOMAIN) fleet_of_highperf_mocked_ursulas,
test_registry_source_manager,
monkeymodule,
testerchain,
):
monkeymodule.setattr(
CharacterConfiguration, "DEFAULT_PRE_PAYMENT_NETWORK", TEMPORARY_DOMAIN
)
config = AliceConfiguration( config = AliceConfiguration(
dev_mode=True, dev_mode=True,
@ -522,7 +529,7 @@ def click_runner():
def nominal_configuration_fields(test_registry_source_manager): def nominal_configuration_fields(test_registry_source_manager):
config = UrsulaConfiguration( config = UrsulaConfiguration(
dev_mode=True, dev_mode=True,
payment_network=TEMPORARY_DOMAIN, pre_payment_network=TEMPORARY_DOMAIN,
domain=TEMPORARY_DOMAIN, domain=TEMPORARY_DOMAIN,
eth_provider_uri=TEST_ETH_PROVIDER_URI, eth_provider_uri=TEST_ETH_PROVIDER_URI,
) )

View File

@ -5,7 +5,7 @@ from unittest.mock import Mock
import maya import maya
import pytest import pytest
from nucypher.blockchain.eth.actors import Ritualist from nucypher.blockchain.eth.actors import Operator
from nucypher.blockchain.eth.agents import CoordinatorAgent from nucypher.blockchain.eth.agents import CoordinatorAgent
from nucypher.blockchain.eth.trackers.dkg import ActiveRitualTracker from nucypher.blockchain.eth.trackers.dkg import ActiveRitualTracker
@ -17,7 +17,7 @@ class BlockInfo(NamedTuple):
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def ritualist(ursulas, mock_coordinator_agent) -> Ritualist: def ritualist(ursulas, mock_coordinator_agent) -> Operator:
ursula = ursulas[0] ursula = ursulas[0]
mocked_agent = Mock(spec=CoordinatorAgent) mocked_agent = Mock(spec=CoordinatorAgent)
mocked_agent.contract = mock_coordinator_agent.contract mocked_agent.contract = mock_coordinator_agent.contract
@ -33,7 +33,7 @@ def ritualist(ursulas, mock_coordinator_agent) -> Ritualist:
def test_first_scan_start_block_number_simple(ritualist): def test_first_scan_start_block_number_simple(ritualist):
mocked_agent = ritualist.coordinator_agent mocked_agent = ritualist.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ritualist) active_ritual_tracker = ActiveRitualTracker(operator=ritualist)
now = maya.now() now = maya.now()
# latest block is 0 - return it # latest block is 0 - return it
@ -64,7 +64,7 @@ def test_first_scan_start_block_number_simple(ritualist):
def test_first_scan_start_block_calc_is_perfect(ritualist): def test_first_scan_start_block_calc_is_perfect(ritualist):
mocked_agent = ritualist.coordinator_agent mocked_agent = ritualist.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ritualist) active_ritual_tracker = ActiveRitualTracker(operator=ritualist)
now = maya.now() now = maya.now()
# #
@ -130,7 +130,7 @@ def test_first_scan_start_block_calc_is_perfect(ritualist):
def test_first_scan_start_block_calc_is_not_perfect_go_back_more_blocks(ritualist): def test_first_scan_start_block_calc_is_not_perfect_go_back_more_blocks(ritualist):
mocked_agent = ritualist.coordinator_agent mocked_agent = ritualist.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ritualist) active_ritual_tracker = ActiveRitualTracker(operator=ritualist)
now = maya.now() now = maya.now()
# #
@ -244,7 +244,7 @@ def test_first_scan_start_block_calc_is_not_perfect_go_back_more_blocks(ritualis
def test_get_ritual_participant_info(ritualist, get_random_checksum_address): def test_get_ritual_participant_info(ritualist, get_random_checksum_address):
mocked_agent = ritualist.coordinator_agent mocked_agent = ritualist.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ritualist) active_ritual_tracker = ActiveRitualTracker(operator=ritualist)
participants = [] participants = []
# random participants # random participants
@ -255,17 +255,17 @@ def test_get_ritual_participant_info(ritualist, get_random_checksum_address):
participants.append(participant) participants.append(participant)
mocked_agent.get_participants.return_value = participants mocked_agent.get_participants.return_value = participants
# ritualist not in participants list # operator not in participants list
participant_info = active_ritual_tracker._get_ritual_participant_info(ritual_id=0) participant_info = active_ritual_tracker._get_ritual_participant_info(ritual_id=0)
assert participant_info is None assert participant_info is None
# add ritualist to participants list # add operator to participants list
participant = CoordinatorAgent.Ritual.Participant( participant = CoordinatorAgent.Ritual.Participant(
provider=ritualist.checksum_address provider=ritualist.checksum_address
) )
participants.append(participant) participants.append(participant)
# ritualist in participants list # operator in participants list
participant_info = active_ritual_tracker._get_ritual_participant_info(ritual_id=0) participant_info = active_ritual_tracker._get_ritual_participant_info(ritual_id=0)
assert participant_info assert participant_info
assert participant_info.provider == ritualist.checksum_address assert participant_info.provider == ritualist.checksum_address
@ -275,7 +275,7 @@ def test_get_participation_state_values_from_contract(
ritualist, get_random_checksum_address ritualist, get_random_checksum_address
): ):
mocked_agent = ritualist.coordinator_agent mocked_agent = ritualist.coordinator_agent
active_ritual_tracker = ActiveRitualTracker(ritualist=ritualist) active_ritual_tracker = ActiveRitualTracker(operator=ritualist)
participants = [] participants = []
# random participants # random participants
@ -297,7 +297,7 @@ def test_get_participation_state_values_from_contract(
assert not posted_transcript assert not posted_transcript
assert not posted_aggregate assert not posted_aggregate
# add ritualist to participants list # add operator to participants list
ritual_participant = CoordinatorAgent.Ritual.Participant( ritual_participant = CoordinatorAgent.Ritual.Participant(
provider=ritualist.checksum_address provider=ritualist.checksum_address
) )

View File

@ -44,7 +44,7 @@ def test_initialize_via_cli(
TEMPORARY_DOMAIN, TEMPORARY_DOMAIN,
"--eth-provider", "--eth-provider",
MOCK_ETH_PROVIDER_URI, MOCK_ETH_PROVIDER_URI,
"--payment-provider", "--pre-payment-provider",
TEST_ETH_PROVIDER_URI, TEST_ETH_PROVIDER_URI,
"--config-root", "--config-root",
str(custom_filepath.absolute()), str(custom_filepath.absolute()),
@ -77,8 +77,13 @@ def test_reconfigure_via_cli(click_runner, custom_filepath: Path, config_class,
def fake_get_latest_registry(*args, **kwargs): def fake_get_latest_registry(*args, **kwargs):
return test_registry return test_registry
monkeypatch.setattr(InMemoryContractRegistry, 'from_latest_publication', fake_get_latest_registry)
monkeypatch.setattr(CharacterConfiguration, 'DEFAULT_PAYMENT_NETWORK', TEMPORARY_DOMAIN) monkeypatch.setattr(
InMemoryContractRegistry, "from_latest_publication", fake_get_latest_registry
)
monkeypatch.setattr(
CharacterConfiguration, "DEFAULT_PRE_PAYMENT_NETWORK", TEMPORARY_DOMAIN
)
custom_config_filepath = custom_filepath / config_class.generate_filename() custom_config_filepath = custom_filepath / config_class.generate_filename()

View File

@ -66,13 +66,13 @@ def test_corrupted_configuration(click_runner,
"init", "init",
"--eth-provider", "--eth-provider",
MOCK_ETH_PROVIDER_URI, MOCK_ETH_PROVIDER_URI,
"--payment-provider", "--pre-payment-provider",
TEST_POLYGON_PROVIDER_URI, TEST_POLYGON_PROVIDER_URI,
"--operator-address", "--operator-address",
another_ursula, another_ursula,
"--network", "--network",
TEMPORARY_DOMAIN, TEMPORARY_DOMAIN,
"--payment-network", "--pre-payment-network",
TEMPORARY_DOMAIN, TEMPORARY_DOMAIN,
"--rest-host", "--rest-host",
MOCK_IP_ADDRESS, MOCK_IP_ADDRESS,
@ -105,11 +105,11 @@ def test_corrupted_configuration(click_runner,
"init", "init",
"--network", "--network",
TEMPORARY_DOMAIN, TEMPORARY_DOMAIN,
"--payment-network", "--pre-payment-network",
TEMPORARY_DOMAIN, TEMPORARY_DOMAIN,
"--eth-provider", "--eth-provider",
MOCK_ETH_PROVIDER_URI, MOCK_ETH_PROVIDER_URI,
"--payment-provider", "--pre-payment-provider",
TEST_POLYGON_PROVIDER_URI, TEST_POLYGON_PROVIDER_URI,
"--operator-address", "--operator-address",
another_ursula, another_ursula,

View File

@ -35,7 +35,7 @@ def test_ursula_startup_ip_checkup(click_runner, mocker, test_registry_source_ma
TEMPORARY_DOMAIN, TEMPORARY_DOMAIN,
"--eth-provider", "--eth-provider",
MOCK_ETH_PROVIDER_URI, MOCK_ETH_PROVIDER_URI,
"--payment-provider", "--pre-payment-provider",
TEST_POLYGON_PROVIDER_URI, TEST_POLYGON_PROVIDER_URI,
"--force", "--force",
) )
@ -54,7 +54,7 @@ def test_ursula_startup_ip_checkup(click_runner, mocker, test_registry_source_ma
"--force", "--force",
"--eth-provider", "--eth-provider",
MOCK_ETH_PROVIDER_URI, MOCK_ETH_PROVIDER_URI,
"--payment-provider", "--pre-payment-provider",
TEST_POLYGON_PROVIDER_URI, TEST_POLYGON_PROVIDER_URI,
) )
result = click_runner.invoke( result = click_runner.invoke(
@ -72,7 +72,7 @@ def test_ursula_startup_ip_checkup(click_runner, mocker, test_registry_source_ma
"--force", "--force",
"--eth-provider", "--eth-provider",
MOCK_ETH_PROVIDER_URI, MOCK_ETH_PROVIDER_URI,
"--payment-provider", "--pre-payment-provider",
TEST_POLYGON_PROVIDER_URI, TEST_POLYGON_PROVIDER_URI,
) )
result = click_runner.invoke( result = click_runner.invoke(

View File

@ -5,15 +5,13 @@ from unittest.mock import PropertyMock
import pytest import pytest
import nucypher
from nucypher.blockchain.eth.actors import Ritualist
from nucypher.blockchain.eth.trackers.dkg import ActiveRitualTracker from nucypher.blockchain.eth.trackers.dkg import ActiveRitualTracker
from nucypher.cli.literature import ( from nucypher.cli.literature import (
COLLECT_NUCYPHER_PASSWORD, COLLECT_NUCYPHER_PASSWORD,
CONFIRM_IPV4_ADDRESS_QUESTION, CONFIRM_IPV4_ADDRESS_QUESTION,
REPEAT_FOR_CONFIRMATION, REPEAT_FOR_CONFIRMATION,
SELECT_OPERATOR_ACCOUNT, SELECT_OPERATOR_ACCOUNT,
SELECT_PAYMENT_NETWORK, SELECT_PRE_PAYMENT_NETWORK,
SUCCESSFUL_DESTRUCTION, SUCCESSFUL_DESTRUCTION,
) )
from nucypher.cli.main import nucypher_cli from nucypher.cli.main import nucypher_cli
@ -33,7 +31,6 @@ from tests.constants import (
MOCK_ETH_PROVIDER_URI, MOCK_ETH_PROVIDER_URI,
MOCK_IP_ADDRESS, MOCK_IP_ADDRESS,
YES_ENTER, YES_ENTER,
TESTERCHAIN_CHAIN_ID,
) )
from tests.utils.ursula import select_test_port from tests.utils.ursula import select_test_port
@ -64,7 +61,7 @@ def test_interactive_initialize_ursula(click_runner, mocker, tmpdir, test_regist
TEMPORARY_DOMAIN, TEMPORARY_DOMAIN,
"--eth-provider", "--eth-provider",
MOCK_ETH_PROVIDER_URI, MOCK_ETH_PROVIDER_URI,
"--payment-provider", "--pre-payment-provider",
MOCK_ETH_PROVIDER_URI, MOCK_ETH_PROVIDER_URI,
) )
@ -73,7 +70,7 @@ def test_interactive_initialize_ursula(click_runner, mocker, tmpdir, test_regist
assert result.exit_code == 0, result.output assert result.exit_code == 0, result.output
# Select network # Select network
assert SELECT_PAYMENT_NETWORK in result.output assert SELECT_PRE_PAYMENT_NETWORK in result.output
# Select account # Select account
assert SELECT_OPERATOR_ACCOUNT in result.output assert SELECT_OPERATOR_ACCOUNT in result.output
@ -103,9 +100,9 @@ def test_initialize_custom_configuration_root(click_runner, custom_filepath: Pat
deploy_port, deploy_port,
"--eth-provider", "--eth-provider",
MOCK_ETH_PROVIDER_URI, MOCK_ETH_PROVIDER_URI,
"--payment-provider", "--pre-payment-provider",
MOCK_ETH_PROVIDER_URI, MOCK_ETH_PROVIDER_URI,
"--payment-network", "--pre-payment-network",
TEMPORARY_DOMAIN, TEMPORARY_DOMAIN,
"--operator-address", "--operator-address",
testerchain.ursulas_accounts[0], testerchain.ursulas_accounts[0],
@ -217,11 +214,19 @@ def test_ursula_destroy_configuration(custom_filepath, click_runner):
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 # Run the destroy command
destruction_args = ('ursula', 'destroy', '--config-file', str(custom_config_filepath.absolute())) destruction_args = (
result = click_runner.invoke(nucypher_cli, destruction_args, "ursula",
input='Y\n'.format(INSECURE_DEVELOPMENT_PASSWORD), "destroy",
"--config-file",
str(custom_config_filepath.absolute()),
)
result = click_runner.invoke(
nucypher_cli,
destruction_args,
input="Y\n".format(),
catch_exceptions=False, catch_exceptions=False,
env={NUCYPHER_ENVVAR_KEYSTORE_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD}) env={NUCYPHER_ENVVAR_KEYSTORE_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD},
)
# CLI Output # CLI Output
assert not custom_config_filepath.is_file(), 'Configuration file still exists' assert not custom_config_filepath.is_file(), 'Configuration file still exists'

View File

@ -53,9 +53,9 @@ def test_ursula_init_with_local_keystore_signer(
"--eth-provider", "--eth-provider",
testerchain.eth_provider_uri, testerchain.eth_provider_uri,
# Layer 2 # Layer 2
"--payment-network", "--pre-payment-network",
TEMPORARY_DOMAIN, TEMPORARY_DOMAIN,
"--payment-provider", "--pre-payment-provider",
testerchain.eth_provider_uri, testerchain.eth_provider_uri,
"--rest-host", "--rest-host",
MOCK_IP_ADDRESS, MOCK_IP_ADDRESS,

View File

@ -43,7 +43,7 @@ def test_development_character_configurations(
character, configuration, test_registry_source_manager, mocker, testerchain character, configuration, test_registry_source_manager, mocker, testerchain
): ):
mocker.patch.object( mocker.patch.object(
CharacterConfiguration, "DEFAULT_PAYMENT_NETWORK", TEMPORARY_DOMAIN CharacterConfiguration, "DEFAULT_PRE_PAYMENT_NETWORK", TEMPORARY_DOMAIN
) )
params = dict( params = dict(
dev_mode=True, dev_mode=True,
@ -127,9 +127,9 @@ def test_default_character_configuration_preservation(
eth_provider_uri=MOCK_ETH_PROVIDER_URI, eth_provider_uri=MOCK_ETH_PROVIDER_URI,
domain=network, domain=network,
rest_host=MOCK_IP_ADDRESS, rest_host=MOCK_IP_ADDRESS,
payment_provider=MOCK_ETH_PROVIDER_URI, pre_payment_provider=MOCK_ETH_PROVIDER_URI,
policy_registry=test_registry, policy_registry=test_registry,
payment_network=TEMPORARY_DOMAIN, pre_payment_network=TEMPORARY_DOMAIN,
keystore=keystore, keystore=keystore,
) )
@ -138,7 +138,7 @@ def test_default_character_configuration_preservation(
checksum_address=fake_address, checksum_address=fake_address,
eth_provider_uri=MOCK_ETH_PROVIDER_URI, eth_provider_uri=MOCK_ETH_PROVIDER_URI,
domain=network, domain=network,
payment_network=TEMPORARY_DOMAIN, pre_payment_network=TEMPORARY_DOMAIN,
policy_registry=test_registry, policy_registry=test_registry,
) )
@ -176,7 +176,7 @@ def test_ursula_development_configuration(test_registry_source_manager, testerch
checksum_address=testerchain.unassigned_accounts[0], checksum_address=testerchain.unassigned_accounts[0],
operator_address=testerchain.unassigned_accounts[1], operator_address=testerchain.unassigned_accounts[1],
domain=TEMPORARY_DOMAIN, domain=TEMPORARY_DOMAIN,
payment_network=TEMPORARY_DOMAIN, pre_payment_network=TEMPORARY_DOMAIN,
eth_provider_uri=MOCK_ETH_PROVIDER_URI, eth_provider_uri=MOCK_ETH_PROVIDER_URI,
) )
assert config.is_me is True assert config.is_me is True

View File

@ -1,5 +1,3 @@
import datetime import datetime
import maya import maya
@ -22,7 +20,7 @@ def test_alices_powers_are_persistent(
config_root=config_root, config_root=config_root,
network_middleware=MockRestMiddleware(eth_provider_uri=MOCK_ETH_PROVIDER_URI), network_middleware=MockRestMiddleware(eth_provider_uri=MOCK_ETH_PROVIDER_URI),
domain=TEMPORARY_DOMAIN, domain=TEMPORARY_DOMAIN,
payment_network=TEMPORARY_DOMAIN, pre_payment_network=TEMPORARY_DOMAIN,
checksum_address=testerchain.alice_account, checksum_address=testerchain.alice_account,
start_learning_now=False, start_learning_now=False,
save_metadata=False, save_metadata=False,

View File

@ -74,7 +74,7 @@ def test_characters_use_keystore(
) )
keystore.unlock(password=INSECURE_DEVELOPMENT_PASSWORD) keystore.unlock(password=INSECURE_DEVELOPMENT_PASSWORD)
payment_method = SubscriptionManagerPayment( pre_payment_method = SubscriptionManagerPayment(
eth_provider=MOCK_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN eth_provider=MOCK_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN
) )
@ -84,7 +84,7 @@ def test_characters_use_keystore(
domain=TEMPORARY_DOMAIN, domain=TEMPORARY_DOMAIN,
eth_provider_uri=MOCK_ETH_PROVIDER_URI, eth_provider_uri=MOCK_ETH_PROVIDER_URI,
checksum_address=testerchain.alice_account, checksum_address=testerchain.alice_account,
payment_method=payment_method, pre_payment_method=pre_payment_method,
) )
Bob( Bob(
eth_provider_uri=MOCK_ETH_PROVIDER_URI, eth_provider_uri=MOCK_ETH_PROVIDER_URI,
@ -99,7 +99,7 @@ def test_characters_use_keystore(
rest_host=LOOPBACK_ADDRESS, rest_host=LOOPBACK_ADDRESS,
rest_port=12345, rest_port=12345,
domain=TEMPORARY_DOMAIN, domain=TEMPORARY_DOMAIN,
payment_method=payment_method, pre_payment_method=pre_payment_method,
operator_address=testerchain.ursulas_accounts[0], operator_address=testerchain.ursulas_accounts[0],
signer=Web3Signer(testerchain.client), signer=Web3Signer(testerchain.client),
) )
@ -158,7 +158,7 @@ def test_ritualist(temp_dir_path, testerchain, dkg_public_key):
) )
keystore.unlock(password=INSECURE_DEVELOPMENT_PASSWORD) keystore.unlock(password=INSECURE_DEVELOPMENT_PASSWORD)
payment_method = SubscriptionManagerPayment( pre_payment_method = SubscriptionManagerPayment(
eth_provider=MOCK_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN eth_provider=MOCK_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN
) )
@ -168,7 +168,7 @@ def test_ritualist(temp_dir_path, testerchain, dkg_public_key):
rest_host=LOOPBACK_ADDRESS, rest_host=LOOPBACK_ADDRESS,
rest_port=12345, rest_port=12345,
domain=TEMPORARY_DOMAIN, domain=TEMPORARY_DOMAIN,
payment_method=payment_method, pre_payment_method=pre_payment_method,
operator_address=testerchain.ursulas_accounts[0], operator_address=testerchain.ursulas_accounts[0],
signer=Web3Signer(testerchain.client), signer=Web3Signer(testerchain.client),
eth_provider_uri=MOCK_ETH_PROVIDER_URI, eth_provider_uri=MOCK_ETH_PROVIDER_URI,

View File

@ -6,7 +6,7 @@ from nucypher.config.constants import TEMPORARY_DOMAIN
from nucypher.config.storages import ForgetfulNodeStorage, TemporaryFileBasedNodeStorage from nucypher.config.storages import ForgetfulNodeStorage, TemporaryFileBasedNodeStorage
from nucypher.policy.payment import SubscriptionManagerPayment from nucypher.policy.payment import SubscriptionManagerPayment
from nucypher.utilities.networking import LOOPBACK_ADDRESS from nucypher.utilities.networking import LOOPBACK_ADDRESS
from tests.constants import MOCK_ETH_PROVIDER_URI, MOCK_IP_ADDRESS from tests.constants import MOCK_ETH_PROVIDER_URI
from tests.utils.ursula import select_test_port from tests.utils.ursula import select_test_port
ADDITIONAL_NODES_TO_LEARN_ABOUT = 10 ADDITIONAL_NODES_TO_LEARN_ABOUT = 10
@ -34,19 +34,23 @@ class BaseTestNodeStorageBackends:
node_from_storage = node_storage.get(stamp=ursula.stamp) node_from_storage = node_storage.get(stamp=ursula.stamp)
assert ursula == node_from_storage, "Node storage {} failed".format(node_storage) assert ursula == node_from_storage, "Node storage {} failed".format(node_storage)
payment_method = SubscriptionManagerPayment(eth_provider=MOCK_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN) pre_payment_method = SubscriptionManagerPayment(
eth_provider=MOCK_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN
)
# Save more nodes # Save more nodes
all_known_nodes = set() all_known_nodes = set()
for i in range(ADDITIONAL_NODES_TO_LEARN_ABOUT): for i in range(ADDITIONAL_NODES_TO_LEARN_ABOUT):
node = Ursula(rest_host=LOOPBACK_ADDRESS, node = Ursula(
rest_host=LOOPBACK_ADDRESS,
rest_port=select_test_port(), rest_port=select_test_port(),
domain=TEMPORARY_DOMAIN, domain=TEMPORARY_DOMAIN,
signer=signer, signer=signer,
eth_provider_uri=MOCK_ETH_PROVIDER_URI, eth_provider_uri=MOCK_ETH_PROVIDER_URI,
checksum_address=operator_addresses[i], checksum_address=operator_addresses[i],
operator_address=operator_addresses[i], operator_address=operator_addresses[i],
payment_method=payment_method) pre_payment_method=pre_payment_method,
)
node_storage.store_node_metadata(node=node) node_storage.store_node_metadata(node=node)
all_known_nodes.add(node) all_known_nodes.add(node)

View File

@ -72,7 +72,8 @@ SAMPLE_RATE: int = 15 # seconds
GAS_STRATEGY: str = 'fast' GAS_STRATEGY: str = 'fast'
MAX_GAS_PRICE: int = 200 # gwei MAX_GAS_PRICE: int = 200 # gwei
LABEL_PREFIX = 'random-metrics-label-' LABEL_PREFIX = 'random-metrics-label-'
LABEL_SUFFIXER = lambda: os.urandom(16).hex() def LABEL_SUFFIXER():
return os.urandom(16).hex()
HANDPICKED_URSULA_URIS: List[str] = [ HANDPICKED_URSULA_URIS: List[str] = [
# DEFAULT_SEEDNODE_URIS[0], # uncomment to use the seednode for granting # DEFAULT_SEEDNODE_URIS[0], # uncomment to use the seednode for granting
] ]
@ -151,8 +152,8 @@ def collect(alice: Alice,
def make_alice(known_nodes: Optional[Set[Ursula]] = None): def make_alice(known_nodes: Optional[Set[Ursula]] = None):
"""Initializes a new 'persistent alice configuration' for grant metrics collection.""" """Initializes a new 'persistent alice configuration' for grant metrics collection."""
# This is Alice's payment method. # This is Alice's PRE payment method.
payment_method = SubscriptionManagerPayment( pre_payment_method = SubscriptionManagerPayment(
network='polygon', network='polygon',
eth_provider=POLYGON_PROVIDER_URI eth_provider=POLYGON_PROVIDER_URI
) )
@ -175,7 +176,7 @@ def make_alice(known_nodes: Optional[Set[Ursula]] = None):
alice_config.initialize(password=INSECURE_PASSWORD) alice_config.initialize(password=INSECURE_PASSWORD)
alice_config.keystore.unlock(password=INSECURE_PASSWORD) alice_config.keystore.unlock(password=INSECURE_PASSWORD)
alice = alice_config.produce(payment_method=payment_method, signer=wallet) alice = alice_config.produce(pre_payment_method=pre_payment_method, signer=wallet)
alice.start_learning_loop(now=True) alice.start_learning_loop(now=True)
return alice return alice

View File

@ -72,7 +72,7 @@ def test_anybody_can_verify(random_address):
start_learning_now=False, start_learning_now=False,
domain=TEMPORARY_DOMAIN, domain=TEMPORARY_DOMAIN,
checksum_address=random_address, checksum_address=random_address,
payment_method=FreeReencryptions(), pre_payment_method=FreeReencryptions(),
eth_provider_uri=MOCK_ETH_PROVIDER_URI, eth_provider_uri=MOCK_ETH_PROVIDER_URI,
) )

View File

@ -10,7 +10,6 @@ from nucypher.config.characters import (
UrsulaConfiguration, UrsulaConfiguration,
) )
from nucypher.config.constants import TEMPORARY_DOMAIN from nucypher.config.constants import TEMPORARY_DOMAIN
from tests.constants import MOCK_IP_ADDRESS
from tests.utils.middleware import MockRestMiddleware from tests.utils.middleware import MockRestMiddleware
from tests.utils.ursula import select_test_port from tests.utils.ursula import select_test_port
@ -47,28 +46,31 @@ def assemble(checksum_address: str = None,
def make_ursula_test_configuration( def make_ursula_test_configuration(
operator_address: ChecksumAddress, operator_address: ChecksumAddress,
rest_port: int = select_test_port(), rest_port: int = select_test_port(),
payment_provider: str = None, pre_payment_provider: str = None,
**assemble_kwargs **assemble_kwargs
) -> UrsulaConfiguration: ) -> UrsulaConfiguration:
test_params = assemble(**assemble_kwargs) test_params = assemble(**assemble_kwargs)
ursula_config = UrsulaConfiguration( ursula_config = UrsulaConfiguration(
**test_params, **test_params,
rest_port=rest_port, rest_port=rest_port,
payment_provider=payment_provider, pre_payment_provider=pre_payment_provider,
payment_network=TEMPORARY_DOMAIN, pre_payment_network=TEMPORARY_DOMAIN,
operator_address=operator_address, operator_address=operator_address,
policy_registry=test_params["registry"] policy_registry=test_params["registry"]
) )
return ursula_config return ursula_config
def make_alice_test_configuration(payment_provider: str = None, def make_alice_test_configuration(
**assemble_kwargs) -> AliceConfiguration: pre_payment_provider: str = None, **assemble_kwargs
) -> AliceConfiguration:
test_params = assemble(**assemble_kwargs) test_params = assemble(**assemble_kwargs)
config = AliceConfiguration(**test_params, config = AliceConfiguration(
payment_provider=payment_provider, **test_params,
payment_network=TEMPORARY_DOMAIN, pre_payment_provider=pre_payment_provider,
policy_registry=test_params['registry']) pre_payment_network=TEMPORARY_DOMAIN,
policy_registry=test_params["registry"]
)
return config return config