mirror of https://github.com/nucypher/nucypher.git
use TACoDomain everywhere
parent
09bc914ce7
commit
b1afa231d5
|
@ -1,3 +1,4 @@
|
|||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.blockchain.eth.signers import InMemorySigner
|
||||
from nucypher.characters.chaotic import NiceGuyEddie as _Enrico
|
||||
|
@ -9,7 +10,7 @@ THIS_IS_NOT_A_TRINKET = 55 # sometimes called "public key"
|
|||
|
||||
signer = InMemorySigner()
|
||||
enrico = _Enrico(encrypting_key=THIS_IS_NOT_A_TRINKET, signer=signer)
|
||||
bob = ThisBobAlwaysDecrypts(domain=TACoDomain.LYNX.name, eth_endpoint="Nowhere")
|
||||
bob = ThisBobAlwaysDecrypts(domain=domains.LYNX, eth_endpoint="Nowhere")
|
||||
|
||||
ANYTHING_CAN_BE_PASSED_AS_RITUAL_ID = 55
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import datetime
|
||||
import maya
|
||||
import os
|
||||
from getpass import getpass
|
||||
from pathlib import Path
|
||||
|
||||
import maya
|
||||
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.blockchain.eth.signers.base import Signer
|
||||
from nucypher.characters.lawful import Alice, Bob
|
||||
from nucypher.characters.lawful import Enrico as Enrico
|
||||
|
@ -45,7 +44,7 @@ print("\n************** Setup **************\n")
|
|||
# Domain #
|
||||
##########
|
||||
|
||||
TACO_DOMAIN = TACoDomain.LYNX.name
|
||||
TACO_DOMAIN = domains.LYNX
|
||||
|
||||
#####################
|
||||
# Bob the BUIDLer ##
|
||||
|
|
|
@ -17,14 +17,13 @@
|
|||
import base64
|
||||
import datetime
|
||||
import json
|
||||
import maya
|
||||
import os
|
||||
import shutil
|
||||
from getpass import getpass
|
||||
from pathlib import Path
|
||||
|
||||
import maya
|
||||
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.blockchain.eth.signers import Signer
|
||||
from nucypher.characters.lawful import Alice, Bob
|
||||
from nucypher.policy.payment import SubscriptionManagerPayment
|
||||
|
@ -58,7 +57,7 @@ try:
|
|||
except KeyError:
|
||||
raise RuntimeError("Missing environment variables to run demo.")
|
||||
|
||||
TACO_DOMAIN = TACoDomain.LYNX.name
|
||||
TACO_DOMAIN = domains.LYNX
|
||||
|
||||
|
||||
#######################################
|
||||
|
|
|
@ -9,6 +9,7 @@ import msgpack
|
|||
from nucypher_core import EncryptedTreasureMap, MessageKit
|
||||
from nucypher_core.umbral import PublicKey
|
||||
|
||||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.characters.lawful import Bob
|
||||
from nucypher.crypto.keypairs import DecryptingKeypair, SigningKeypair
|
||||
|
@ -28,7 +29,7 @@ except KeyError:
|
|||
raise RuntimeError("Missing environment variables to run demo.")
|
||||
|
||||
|
||||
TACO_DOMAIN = TACoDomain.LYNX.name
|
||||
TACO_DOMAIN = domains.LYNX
|
||||
|
||||
# To create a Bob, we need the doctor's private keys previously generated.
|
||||
from doctor_keys import get_doctor_privkeys # noqa: E402
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import os
|
||||
|
||||
from nucypher_core.ferveo import DkgPublicKey
|
||||
|
||||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.blockchain.eth.agents import CoordinatorAgent
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.blockchain.eth.signers import InMemorySigner
|
||||
from nucypher.characters.lawful import Bob, Enrico
|
||||
|
@ -20,7 +19,7 @@ GlobalLoggerSettings.set_log_level(log_level_name=LOG_LEVEL)
|
|||
GlobalLoggerSettings.start_console_logging()
|
||||
|
||||
eth_endpoint = os.environ["DEMO_L1_PROVIDER_URI"]
|
||||
domain = TACoDomain.LYNX.name
|
||||
domain = domains.LYNX
|
||||
|
||||
polygon_endpoint = os.environ["DEMO_L2_PROVIDER_URI"]
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import os
|
||||
|
||||
from nucypher_core.ferveo import DkgPublicKey
|
||||
|
||||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.blockchain.eth.agents import CoordinatorAgent
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.blockchain.eth.signers import InMemorySigner
|
||||
from nucypher.characters.lawful import Bob, Enrico
|
||||
|
@ -21,7 +20,7 @@ GlobalLoggerSettings.set_log_level(log_level_name=LOG_LEVEL)
|
|||
GlobalLoggerSettings.start_console_logging()
|
||||
|
||||
eth_endpoint = os.environ["DEMO_L1_PROVIDER_URI"]
|
||||
domain = TACoDomain.LYNX.name
|
||||
domain = domains.LYNX
|
||||
|
||||
polygon_endpoint = os.environ["DEMO_L2_PROVIDER_URI"]
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@ class RegistrySource(ABC):
|
|||
class Unavailable(RegistrySourceError):
|
||||
"""Raised when there are no available registry sources"""
|
||||
|
||||
def __init__(self, domain: TACoDomain, *args, **kwargs):
|
||||
def __init__(self, domain: Union[str, TACoDomain], *args, **kwargs):
|
||||
domain = domains.get_domain(str(domain))
|
||||
if domain not in domains.SUPPORTED_DOMAINS:
|
||||
raise ValueError(
|
||||
f"{self.__class__.__name__} not available for domain '{domain}'. "
|
||||
|
@ -154,14 +155,14 @@ class EmbeddedRegistrySource(LocalRegistrySource):
|
|||
|
||||
_CONTRACT_REGISTRY_BASE = Path(__file__).parent / "contract_registry"
|
||||
|
||||
def __init__(self, domain: str, *args, **kwargs):
|
||||
def __init__(self, domain, *args, **kwargs):
|
||||
self.domain = domain
|
||||
filepath = self.get_publication_endpoint()
|
||||
super().__init__(domain=domain, filepath=filepath, *args, **kwargs)
|
||||
|
||||
@property
|
||||
def registry_name(self) -> str:
|
||||
return f"{self.domain}.json"
|
||||
return f"{str(self.domain)}.json"
|
||||
|
||||
def get_publication_endpoint(self) -> Path:
|
||||
"""Get the path to the embedded contract registry."""
|
||||
|
@ -302,12 +303,11 @@ class ContractRegistry:
|
|||
@classmethod
|
||||
def from_latest_publication(
|
||||
cls,
|
||||
domain: TACoDomain,
|
||||
domain: Union[str, TACoDomain],
|
||||
source_manager: Optional[RegistrySourceManager] = None,
|
||||
) -> "ContractRegistry":
|
||||
"""Get the latest contract registry available from a registry source chain."""
|
||||
if not isinstance(domain, TACoDomain):
|
||||
raise TypeError(f"Expected TACoDomain, got {type(domain)}")
|
||||
domain = domains.get_domain(str(domain))
|
||||
source_manager = source_manager or RegistrySourceManager(domain=domain)
|
||||
source = source_manager.fetch_latest_publication()
|
||||
registry = cls(source=source)
|
||||
|
|
|
@ -1010,7 +1010,7 @@ class Ursula(Teacher, Character, Operator):
|
|||
self.start_learning_loop(now=eager)
|
||||
if emitter:
|
||||
emitter.message(
|
||||
f"✓ Node Discovery ({self.domain.capitalize()})", color="green"
|
||||
f"✓ Node Discovery ({self.domain})", color="green"
|
||||
)
|
||||
|
||||
if ritual_tracking:
|
||||
|
@ -1364,7 +1364,7 @@ class Ursula(Teacher, Character, Operator):
|
|||
operator_address=self.operator_address,
|
||||
rest_url=self.rest_url(),
|
||||
timestamp=self.timestamp,
|
||||
domain=domain,
|
||||
domain=str(domain),
|
||||
version=version,
|
||||
fleet_state=fleet_state,
|
||||
previous_fleet_states=previous_fleet_states,
|
||||
|
|
|
@ -64,7 +64,7 @@ def select_client_account(
|
|||
blockchain = BlockchainInterfaceFactory.get_interface(endpoint=polygon_endpoint)
|
||||
|
||||
if signer_uri and not signer:
|
||||
testnet = domain != TACoDomain.MAINNET.name
|
||||
testnet = domain != domains.MAINNET.name
|
||||
signer = Signer.from_signer_uri(signer_uri, testnet=testnet)
|
||||
|
||||
enumerated_accounts = dict(enumerate(signer.accounts))
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
import json
|
||||
import re
|
||||
from abc import ABC, abstractmethod
|
||||
from decimal import Decimal
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from typing import Callable, List, Optional, Union
|
||||
|
||||
from constant_sorrow.constants import (
|
||||
DEVELOPMENT_CONFIGURATION,
|
||||
LIVE_CONFIGURATION,
|
||||
|
@ -14,9 +9,13 @@ from constant_sorrow.constants import (
|
|||
UNINITIALIZED_CONFIGURATION,
|
||||
UNKNOWN_VERSION,
|
||||
)
|
||||
from decimal import Decimal
|
||||
from eth_utils.address import is_checksum_address
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from typing import Callable, List, Optional, Union
|
||||
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
|
||||
from nucypher.blockchain.eth.registry import (
|
||||
ContractRegistry,
|
||||
|
@ -415,8 +414,7 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
self.signer_uri = signer_uri or None
|
||||
|
||||
# Learner
|
||||
self.domain = domain
|
||||
self.taco_domain_info = TACoDomain.get_domain_info(self.domain)
|
||||
self.domain = domains.get_domain(str(domain))
|
||||
self.learn_on_same_thread = learn_on_same_thread
|
||||
self.abort_on_learning_error = abort_on_learning_error
|
||||
self.start_learning_now = start_learning_now
|
||||
|
@ -451,7 +449,7 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
self.log.info(f"Using local registry ({self.registry}).")
|
||||
|
||||
self.signer = Signer.from_signer_uri(
|
||||
self.signer_uri, testnet=self.taco_domain_info.is_testnet
|
||||
self.signer_uri, testnet=self.domain.is_testnet
|
||||
)
|
||||
|
||||
#
|
||||
|
@ -662,7 +660,7 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
keystore_path=keystore_path,
|
||||
|
||||
# Behavior
|
||||
domain=self.domain,
|
||||
domain=str(self.domain),
|
||||
learn_on_same_thread=self.learn_on_same_thread,
|
||||
abort_on_learning_error=self.abort_on_learning_error,
|
||||
start_learning_now=self.start_learning_now,
|
||||
|
@ -834,7 +832,7 @@ class CharacterConfiguration(BaseConfiguration):
|
|||
if pre_payment_class.ONCHAIN:
|
||||
# on-chain payment strategies require a blockchain connection
|
||||
pre_payment_strategy = pre_payment_class(
|
||||
domain=self.taco_domain_info.name,
|
||||
domain=str(self.domain),
|
||||
blockchain_endpoint=self.polygon_endpoint,
|
||||
registry=self.registry,
|
||||
)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from cryptography.x509 import Certificate
|
||||
from eth_utils import is_checksum_address
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from nucypher.config.base import CharacterConfiguration
|
||||
from nucypher.config.constants import (
|
||||
|
@ -70,7 +69,7 @@ class UrsulaConfiguration(CharacterConfiguration):
|
|||
def configure_condition_blockchain_endpoints(self) -> None:
|
||||
"""Configure default condition provider URIs for eth and polygon network."""
|
||||
# Polygon
|
||||
polygon_chain_id = self.taco_domain_info.polygon_chain.id
|
||||
polygon_chain_id = self.domain.polygon_chain.id
|
||||
polygon_endpoints = self.condition_blockchain_endpoints.get(
|
||||
polygon_chain_id, []
|
||||
)
|
||||
|
@ -81,7 +80,7 @@ class UrsulaConfiguration(CharacterConfiguration):
|
|||
polygon_endpoints.append(self.polygon_endpoint)
|
||||
|
||||
# Ethereum
|
||||
staking_chain_id = self.taco_domain_info.eth_chain.id
|
||||
staking_chain_id = self.domain.eth_chain.id
|
||||
staking_chain_endpoints = self.condition_blockchain_endpoints.get(
|
||||
staking_chain_id, []
|
||||
)
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
from typing import Dict
|
||||
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.config.migrations.common import perform_migration
|
||||
|
||||
|
||||
def __migration(config: Dict) -> Dict:
|
||||
taco_domain_info = TACoDomain.get_domain_info(config["domain"])
|
||||
domain = domains.get_domain(config["domain"])
|
||||
eth_provider = config["eth_provider_uri"]
|
||||
eth_chain_id = taco_domain_info.eth_chain.id
|
||||
eth_chain_id = domain.eth_chain.id
|
||||
polygon_provider = config["payment_provider"]
|
||||
polygon_chain_id = taco_domain_info.polygon_chain.id
|
||||
polygon_chain_id = domain.polygon_chain.id
|
||||
if "condition_provider_uris" in config:
|
||||
return config
|
||||
config["condition_provider_uris"] = {
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
import time
|
||||
from collections import defaultdict, deque
|
||||
from contextlib import suppress
|
||||
from pathlib import Path
|
||||
from queue import Queue
|
||||
from typing import Callable, List, Optional, Set, Tuple
|
||||
|
||||
import maya
|
||||
import requests
|
||||
import time
|
||||
from constant_sorrow.constants import (
|
||||
CERTIFICATE_NOT_SAVED,
|
||||
FLEET_STATES_MATCH,
|
||||
|
@ -14,14 +10,18 @@ from constant_sorrow.constants import (
|
|||
NOT_SIGNED,
|
||||
RELAX,
|
||||
)
|
||||
from contextlib import suppress
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.x509 import Certificate, load_der_x509_certificate
|
||||
from eth_utils import to_checksum_address
|
||||
from nucypher_core import MetadataResponse, MetadataResponsePayload, NodeMetadata
|
||||
from nucypher_core.umbral import Signature
|
||||
from pathlib import Path
|
||||
from queue import Queue
|
||||
from requests.exceptions import SSLError
|
||||
from twisted.internet import reactor, task
|
||||
from twisted.internet.defer import Deferred
|
||||
from typing import Callable, List, Optional, Set, Tuple
|
||||
|
||||
from nucypher import characters
|
||||
from nucypher.acumen.nicknames import Nickname
|
||||
|
@ -29,7 +29,6 @@ from nucypher.acumen.perception import FleetSensor
|
|||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.blockchain.eth.agents import ContractAgency, TACoApplicationAgent
|
||||
from nucypher.blockchain.eth.constants import NULL_ADDRESS
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.config.constants import SeednodeMetadata
|
||||
from nucypher.config.storages import ForgetfulNodeStorage
|
||||
|
@ -47,13 +46,13 @@ from nucypher.network.protocols import InterfaceInfo, SuspiciousActivity
|
|||
from nucypher.utilities.logging import Logger
|
||||
|
||||
TEACHER_NODES = {
|
||||
TACoDomain.MAINNET.name: (
|
||||
domains.MAINNET: (
|
||||
'https://closest-seed.nucypher.network:9151',
|
||||
'https://seeds.nucypher.network',
|
||||
'https://mainnet.nucypher.network:9151',
|
||||
),
|
||||
TACoDomain.LYNX.name: ("https://lynx.nucypher.network:9151",),
|
||||
TACoDomain.TAPIR.name: ("https://tapir.nucypher.network:9151",),
|
||||
domains.LYNX: ("https://lynx.nucypher.network:9151",),
|
||||
domains.TAPIR: ("https://tapir.nucypher.network:9151",),
|
||||
}
|
||||
|
||||
|
||||
|
@ -352,7 +351,7 @@ class Learner:
|
|||
discovered = []
|
||||
|
||||
if self.domain:
|
||||
canonical_sage_uris = TEACHER_NODES.get(str(self.domain), ())
|
||||
canonical_sage_uris = TEACHER_NODES.get(self.domain, ())
|
||||
|
||||
for uri in canonical_sage_uris:
|
||||
try:
|
||||
|
@ -411,7 +410,7 @@ class Learner:
|
|||
restored_from_disk = []
|
||||
invalid_nodes = defaultdict(list)
|
||||
for node in stored_nodes:
|
||||
if node.domain != self.domain:
|
||||
if str(node.domain) != str(self.domain):
|
||||
invalid_nodes[node.domain].append(node)
|
||||
continue
|
||||
restored_node = self.remember_node(node, record_fleet_state=False) # TODO: Validity status 1866
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
import random
|
||||
import time
|
||||
|
||||
import click
|
||||
import maya
|
||||
import random
|
||||
import time
|
||||
from nucypher_core.ferveo import DkgPublicKey
|
||||
from web3 import Web3
|
||||
|
||||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.blockchain.eth.agents import (
|
||||
ContractAgency,
|
||||
CoordinatorAgent,
|
||||
TACoApplicationAgent,
|
||||
)
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.blockchain.eth.signers import InMemorySigner, Signer
|
||||
from nucypher.characters.lawful import Bob, Enrico
|
||||
|
@ -47,8 +46,8 @@ def get_transacting_power(signer: Signer):
|
|||
"--domain",
|
||||
"domain",
|
||||
help="TACo Domain",
|
||||
type=click.Choice([TACoDomain.TAPIR.name, TACoDomain.LYNX.name]),
|
||||
default=TACoDomain.LYNX.name,
|
||||
type=click.Choice([domains.TAPIR.name, domains.LYNX.name]),
|
||||
default=domains.LYNX.name,
|
||||
)
|
||||
@click.option(
|
||||
"--eth-endpoint",
|
||||
|
@ -154,7 +153,7 @@ def nucypher_dkg(
|
|||
),
|
||||
)
|
||||
|
||||
taco_domain_info = TACoDomain.get_domain_info(domain)
|
||||
domain = domains.get_domain(domain)
|
||||
registry = ContractRegistry.from_latest_publication(domain=domain)
|
||||
coordinator_agent = ContractAgency.get_agent(
|
||||
agent_class=CoordinatorAgent,
|
||||
|
@ -191,7 +190,7 @@ def nucypher_dkg(
|
|||
|
||||
emitter.echo("--------- Initiating Ritual ---------", color="yellow")
|
||||
emitter.echo(
|
||||
f"Commencing DKG Ritual(s) on {taco_domain_info.polygon_chain.name} using {account_address}",
|
||||
f"Commencing DKG Ritual(s) on {domain.polygon_chain.name} using {account_address}",
|
||||
color="green",
|
||||
)
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ from nucypher.blockchain.eth.agents import (
|
|||
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry, RegistrySourceManager
|
||||
from nucypher.blockchain.eth.signers.software import Web3Signer
|
||||
from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
|
||||
from nucypher.crypto.powers import TransactingPower
|
||||
from nucypher.policy.conditions.evm import RPCCondition
|
||||
from nucypher.utilities.logging import Logger
|
||||
|
@ -274,10 +273,10 @@ def deployed_contracts(
|
|||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def test_registry(deployed_contracts, module_mocker):
|
||||
def test_registry(deployed_contracts, module_mocker, temporary_domain):
|
||||
with tests.utils.registry.mock_registry_sources(mocker=module_mocker):
|
||||
RegistrySourceManager._FALLBACK_CHAIN = (ApeRegistrySource,)
|
||||
source = ApeRegistrySource(domain=TEMPORARY_DOMAIN_NAME)
|
||||
source = ApeRegistrySource(domain=temporary_domain)
|
||||
registry = ContractRegistry(source=source)
|
||||
yield registry
|
||||
|
||||
|
|
|
@ -144,11 +144,6 @@ def mock_condition_blockchains(module_mocker, temporary_domain):
|
|||
{TESTERCHAIN_CHAIN_ID: "eth-tester/pyevm"},
|
||||
)
|
||||
|
||||
module_mocker.patch(
|
||||
"nucypher.blockchain.eth.domains.get_domain",
|
||||
return_value=temporary_domain
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def mock_multichain_configuration(module_mocker, testerchain):
|
||||
|
|
|
@ -547,9 +547,9 @@ def worker_configuration_file_location(custom_filepath) -> Path:
|
|||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_teacher_nodes(mocker):
|
||||
def mock_teacher_nodes(mocker, temporary_domain):
|
||||
mock_nodes = tuple(u.rest_url() for u in MOCK_KNOWN_URSULAS_CACHE.values())[0:2]
|
||||
mocker.patch.dict(TEACHER_NODES, {TEMPORARY_DOMAIN_NAME: mock_nodes}, clear=True)
|
||||
mocker.patch.dict(TEACHER_NODES, {temporary_domain: mock_nodes}, clear=True)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
|
|
@ -74,7 +74,7 @@ def test_development_character_configurations(
|
|||
assert len(thing_one.checksum_address) == 42
|
||||
|
||||
# Domain
|
||||
assert TEMPORARY_DOMAIN_NAME == thing_one.domain
|
||||
assert TEMPORARY_DOMAIN_NAME == str(thing_one.domain)
|
||||
|
||||
# Node Storage
|
||||
assert isinstance(thing_one.node_storage, ForgetfulNodeStorage)
|
||||
|
|
|
@ -6,7 +6,7 @@ from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
|
|||
from nucypher.config.storages import ForgetfulNodeStorage, TemporaryFileBasedNodeStorage
|
||||
from nucypher.policy.payment import SubscriptionManagerPayment
|
||||
from nucypher.utilities.networking import LOOPBACK_ADDRESS
|
||||
from tests.constants import MOCK_ETH_PROVIDER_URI
|
||||
from tests.constants import MOCK_ETH_PROVIDER_URI, TESTERCHAIN_CHAIN_ID
|
||||
from tests.utils.ursula import select_test_port
|
||||
|
||||
ADDITIONAL_NODES_TO_LEARN_ABOUT = 10
|
||||
|
|
|
@ -25,7 +25,6 @@ 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_NAME
|
||||
from nucypher.crypto.powers import TransactingPower
|
||||
from nucypher.network.nodes import Teacher
|
||||
from tests.constants import (
|
||||
|
@ -284,10 +283,6 @@ def mock_condition_blockchains(module_mocker, temporary_domain):
|
|||
{TESTERCHAIN_CHAIN_ID: "eth-tester/pyevm"},
|
||||
)
|
||||
|
||||
module_mocker.patch(
|
||||
"nucypher.blockchain.eth.domains.get_domain",
|
||||
return_value=temporary_domain
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
|
|
@ -1,31 +1,41 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
|
||||
import tests
|
||||
from nucypher.acumen.perception import FleetSensor
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.characters.lawful import Ursula
|
||||
from nucypher.config.storages import LocalFileBasedNodeStorage
|
||||
from nucypher.network.nodes import TEACHER_NODES
|
||||
from tests.constants import TESTERCHAIN_CHAIN_INFO
|
||||
from tests.utils.registry import MockRegistrySource
|
||||
from tests.utils.ursula import make_ursulas
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def domain_1():
|
||||
return "domain_uno"
|
||||
return TACoDomain(
|
||||
name="domain_uno",
|
||||
eth_chain=TESTERCHAIN_CHAIN_INFO,
|
||||
polygon_chain=TESTERCHAIN_CHAIN_INFO,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def domain_2():
|
||||
return "domain_dos"
|
||||
return TACoDomain(
|
||||
name="domain_dos",
|
||||
eth_chain=TESTERCHAIN_CHAIN_INFO,
|
||||
polygon_chain=TESTERCHAIN_CHAIN_INFO,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def test_registry(module_mocker, domain_1, domain_2):
|
||||
def test_registry(module_mocker, domain_1, domain_2, temporary_domain):
|
||||
with tests.utils.registry.mock_registry_sources(
|
||||
mocker=module_mocker, domain_names=[domain_1, domain_2]
|
||||
mocker=module_mocker, domains=[domain_1, domain_2, temporary_domain]
|
||||
):
|
||||
# doesn't really matter what domain is used here
|
||||
registry = ContractRegistry(MockRegistrySource(domain=domain_1))
|
||||
|
|
|
@ -18,5 +18,5 @@ def test_registry(module_mocker):
|
|||
|
||||
def test_default_teacher_seednodes_defined():
|
||||
for domain in domains.SUPPORTED_DOMAINS:
|
||||
teacher_nodes = TEACHER_NODES[domain.name]
|
||||
teacher_nodes = TEACHER_NODES[domain]
|
||||
assert len(teacher_nodes) > 0
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from typing import List
|
||||
|
||||
from eth_typing import ChecksumAddress
|
||||
from typing import List
|
||||
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.characters.lawful import Ursula
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
from collections import defaultdict
|
||||
from contextlib import contextmanager
|
||||
from typing import List
|
||||
|
||||
from ape.contracts import ContractInstance
|
||||
from contextlib import contextmanager
|
||||
from eth_utils import to_checksum_address
|
||||
from typing import List
|
||||
|
||||
from nucypher.blockchain.eth.domains import (
|
||||
DomainInfo,
|
||||
TACoDomain,
|
||||
)
|
||||
from nucypher.blockchain.eth.domains import TACoDomain
|
||||
from nucypher.blockchain.eth.registry import (
|
||||
RegistryData,
|
||||
RegistrySource,
|
||||
|
@ -19,23 +16,35 @@ from tests.constants import TESTERCHAIN_CHAIN_INFO
|
|||
|
||||
|
||||
@contextmanager
|
||||
def mock_registry_sources(mocker, domain_names: List[str] = None):
|
||||
if not domain_names:
|
||||
domain_names = [TEMPORARY_DOMAIN_NAME]
|
||||
def mock_registry_sources(mocker, domains: List[TACoDomain] = None):
|
||||
if not domains:
|
||||
domains = [
|
||||
TACoDomain(
|
||||
name=TEMPORARY_DOMAIN_NAME,
|
||||
eth_chain=TESTERCHAIN_CHAIN_INFO,
|
||||
polygon_chain=TESTERCHAIN_CHAIN_INFO,
|
||||
)
|
||||
]
|
||||
|
||||
supported_domains = []
|
||||
supported_domain_names = []
|
||||
for domain_name in domain_names:
|
||||
test_domain = DomainInfo(
|
||||
domain_name, TESTERCHAIN_CHAIN_INFO, TESTERCHAIN_CHAIN_INFO
|
||||
for domain in domains:
|
||||
test_domain = TACoDomain(
|
||||
name=str(domain),
|
||||
eth_chain=TESTERCHAIN_CHAIN_INFO,
|
||||
polygon_chain=TESTERCHAIN_CHAIN_INFO,
|
||||
)
|
||||
supported_domains.append(test_domain)
|
||||
supported_domain_names.append(domain_name)
|
||||
supported_domain_names.append(str(domain))
|
||||
|
||||
mocker.patch.object(TACoDomain, "SUPPORTED_DOMAINS", supported_domains)
|
||||
mocker.patch.object(TACoDomain, "SUPPORTED_DOMAIN_NAMES", supported_domain_names)
|
||||
mocker.patch.object(MockRegistrySource, "ALLOWED_DOMAINS", domain_names)
|
||||
|
||||
_supported_domains = mocker.patch('nucypher.blockchain.eth.domains.SUPPORTED_DOMAINS', new_callable=list)
|
||||
_supported_domains.extend(supported_domains)
|
||||
|
||||
_supported_domain_names = mocker.patch('nucypher.blockchain.eth.domains.SUPPORTED_DOMAIN_NAMES', new_callable=list)
|
||||
_supported_domain_names.extend(supported_domain_names)
|
||||
|
||||
mocker.patch.object(MockRegistrySource, "ALLOWED_DOMAINS", list(map(str, domains)))
|
||||
mocker.patch.object(RegistrySourceManager, "_FALLBACK_CHAIN", (MockRegistrySource,))
|
||||
|
||||
yield # run the test
|
||||
|
@ -49,7 +58,7 @@ class MockRegistrySource(RegistrySource):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if self.domain.name not in self.ALLOWED_DOMAINS:
|
||||
if str(self.domain) not in self.ALLOWED_DOMAINS:
|
||||
raise ValueError(
|
||||
f"Somehow, MockRegistrySource is trying to get a registry for '{self.domain}'. "
|
||||
f"Only '{','.join(self.ALLOWED_DOMAINS)}' are supported.'"
|
||||
|
@ -76,7 +85,7 @@ class ApeRegistrySource(RegistrySource):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if self.domain != TEMPORARY_DOMAIN_NAME:
|
||||
if str(self.domain) != TEMPORARY_DOMAIN_NAME:
|
||||
raise ValueError(
|
||||
f"Somehow, ApeRegistrySource is trying to get a registry for '{self.domain}'. "
|
||||
f"Only '{TEMPORARY_DOMAIN_NAME}' is supported.'"
|
||||
|
|
Loading…
Reference in New Issue