Rename networks module to domains, and remove NetworksInventory class; module contains all values and methods now.

pull/3262/head
derekpierre 2023-10-03 16:06:10 -04:00
parent 0f119934f4
commit bee3c926d4
26 changed files with 138 additions and 153 deletions

View File

@ -2,8 +2,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.networks import NetworksInventory
from nucypher.blockchain.eth.registry import ContractRegistry
from nucypher.blockchain.eth.signers import InMemorySigner
from nucypher.characters.lawful import Bob, Enrico
@ -20,7 +20,7 @@ GlobalLoggerSettings.set_log_level(log_level_name=LOG_LEVEL)
GlobalLoggerSettings.start_console_logging()
eth_endpoint = os.environ["DEMO_L1_PROVIDER_URI"]
taco_domain = NetworksInventory.from_domain_name("lynx")
taco_domain = domains.from_domain_name("lynx")
polygon_endpoint = os.environ["DEMO_L2_PROVIDER_URI"]

View File

@ -2,8 +2,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.networks import NetworksInventory
from nucypher.blockchain.eth.registry import ContractRegistry
from nucypher.blockchain.eth.signers import InMemorySigner
from nucypher.characters.lawful import Bob, Enrico
@ -20,7 +20,7 @@ GlobalLoggerSettings.set_log_level(log_level_name=LOG_LEVEL)
GlobalLoggerSettings.start_console_logging()
eth_endpoint = os.environ["DEMO_L1_PROVIDER_URI"]
taco_domain = NetworksInventory.from_domain_name("lynx")
taco_domain = domains.from_domain_name("lynx")
polygon_endpoint = os.environ["DEMO_L2_PROVIDER_URI"]

View File

@ -27,6 +27,7 @@ from web3 import HTTPProvider, Web3
from web3.types import TxReceipt
from nucypher.acumen.nicknames import Nickname
from nucypher.blockchain.eth import domains
from nucypher.blockchain.eth.agents import (
ContractAgency,
CoordinatorAgent,
@ -37,7 +38,6 @@ from nucypher.blockchain.eth.clients import PUBLIC_CHAINS
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.decorators import validate_checksum_address
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.registry import (
ContractRegistry,
)
@ -93,7 +93,7 @@ class BaseActor:
self.transacting_power = transacting_power
self.registry = registry
self.network = domain
self.taco_domain = NetworksInventory.from_domain_name(self.network)
self.taco_domain = domains.from_domain_name(self.network)
self._saved_receipts = list() # track receipts of transmitted transactions
def __repr__(self):

View File

@ -0,0 +1,67 @@
from enum import Enum
from typing import NamedTuple
from nucypher.config.constants import TEMPORARY_DOMAIN
class ChainInfo(NamedTuple):
id: int
name: str
class EthChain(ChainInfo, Enum):
MAINNET = ChainInfo(1, "mainnet")
GOERLI = ChainInfo(5, "goerli")
SEPOLIA = ChainInfo(11155111, "sepolia")
TESTERCHAIN = ChainInfo(131277322940537, TEMPORARY_DOMAIN)
class PolygonChain(ChainInfo, Enum):
POLYGON = ChainInfo(137, "polygon")
MUMBAI = ChainInfo(80001, "mumbai")
TESTERCHAIN = ChainInfo(131277322940537, TEMPORARY_DOMAIN)
class TACoDomain(NamedTuple):
name: str
eth_chain: EthChain
polygon_chain: PolygonChain
def is_testnet(self) -> bool:
return self.eth_chain != EthChain.MAINNET
class UnrecognizedDomain(RuntimeError):
"""Raised when a provided domain name is not recognized."""
MAINNET = TACoDomain("mainnet", EthChain.MAINNET, PolygonChain.POLYGON)
# Testnets
ORYX = TACoDomain("oryx", EthChain.GOERLI, PolygonChain.POLYGON)
LYNX = TACoDomain("lynx", EthChain.GOERLI, PolygonChain.MUMBAI)
TAPIR = TACoDomain("tapir", EthChain.SEPOLIA, PolygonChain.MUMBAI)
IBEX = TACoDomain(
"ibex", EthChain.GOERLI, None
) # this is required for configuration file migrations (backwards compatibility)
DEFAULT_DOMAIN_NAME: str = MAINNET.name
SUPPORTED_DOMAINS = [
MAINNET,
ORYX,
LYNX,
TAPIR,
]
SUPPORTED_DOMAIN_NAMES = [domain.name for domain in SUPPORTED_DOMAINS]
# TODO not needed once merged with registry changes
POLYGON_CHAINS = [domain.polygon_chain.name for domain in SUPPORTED_DOMAINS]
def from_domain_name(domain: str) -> TACoDomain:
for taco_domain in SUPPORTED_DOMAINS:
if taco_domain.name == domain:
return taco_domain
raise UnrecognizedDomain(f"{domain} is not a recognized domain.")

View File

@ -1,68 +0,0 @@
from enum import Enum
from typing import NamedTuple
from nucypher.config.constants import TEMPORARY_DOMAIN
class ChainInfo(NamedTuple):
id: int
name: str
class EthChain(ChainInfo, Enum):
MAINNET = ChainInfo(1, "mainnet")
GOERLI = ChainInfo(5, "goerli")
SEPOLIA = ChainInfo(11155111, "sepolia")
TESTERCHAIN = ChainInfo(131277322940537, TEMPORARY_DOMAIN)
class PolygonChain(ChainInfo, Enum):
POLYGON = ChainInfo(137, "polygon")
MUMBAI = ChainInfo(80001, "mumbai")
TESTERCHAIN = ChainInfo(131277322940537, TEMPORARY_DOMAIN)
class TACoDomain(NamedTuple):
name: str
eth_chain: EthChain
polygon_chain: PolygonChain
def is_testnet(self) -> bool:
return self.eth_chain != EthChain.MAINNET
class UnrecognizedDomain(RuntimeError):
"""Raised when a provided domain name is not recognized."""
class NetworksInventory:
MAINNET = TACoDomain("mainnet", EthChain.MAINNET, PolygonChain.POLYGON)
# Testnets
ORYX = TACoDomain("oryx", EthChain.GOERLI, PolygonChain.POLYGON)
LYNX = TACoDomain("lynx", EthChain.GOERLI, PolygonChain.MUMBAI)
TAPIR = TACoDomain("tapir", EthChain.SEPOLIA, PolygonChain.MUMBAI)
IBEX = TACoDomain(
"ibex", EthChain.GOERLI, None
) # this is required for configuration file migrations (backwards compatibility)
SUPPORTED_DOMAINS = [
MAINNET,
ORYX,
LYNX,
TAPIR,
]
SUPPORTED_DOMAIN_NAMES = [domain.name for domain in SUPPORTED_DOMAINS]
# TODO not needed once merged with registry changes
POLYGON_CHAINS = [domain.polygon_chain.name for domain in SUPPORTED_DOMAINS]
DEFAULT_DOMAIN_NAME: str = MAINNET.name
@classmethod
def from_domain_name(cls, domain: str) -> TACoDomain:
for taco_domain in cls.SUPPORTED_DOMAINS:
if taco_domain.name == domain:
return taco_domain
raise UnrecognizedDomain(f"{domain} is not a recognized domain.")

View File

@ -9,7 +9,7 @@ import requests
from requests import Response
from web3.types import ABI
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth import domains
from nucypher.utilities.logging import Logger
RegistryArtifact = Dict[str, Union[str, ABI]]
@ -34,10 +34,10 @@ class RegistrySource(ABC):
"""Raised when there are no available registry sources"""
def __init__(self, domain: str, *args, **kwargs):
if domain not in NetworksInventory.SUPPORTED_DOMAIN_NAMES:
if domain not in domains.SUPPORTED_DOMAIN_NAMES:
raise ValueError(
f"{self.__class__.__name__} not available for domain '{domain}'. "
f"Valid options are: {', '.join(list(NetworksInventory.SUPPORTED_DOMAIN_NAMES))}"
f"Valid options are: {', '.join(list(domains.SUPPORTED_DOMAIN_NAMES))}"
)
self.domain = domain
self.data = self.get()

View File

@ -6,8 +6,8 @@ import click
from tabulate import tabulate
from web3.main import Web3
from nucypher.blockchain.eth import domains
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.registry import (
ContractRegistry,
)
@ -71,7 +71,7 @@ def select_client_account(
)
if signer_uri and not signer:
testnet = domain != NetworksInventory.MAINNET.name
testnet = domain != domains.MAINNET.name
signer = Signer.from_signer_uri(signer_uri, testnet=testnet)
# Display accounts info
@ -118,7 +118,7 @@ def select_client_account(
def select_domain(emitter: StdoutEmitter, message: Optional[str] = None) -> str:
"""Interactively select a domain from TACo domain inventory list"""
emitter.message(message=message or str(), color="yellow")
domain_list = NetworksInventory.SUPPORTED_DOMAIN_NAMES
domain_list = domains.SUPPORTED_DOMAIN_NAMES
rows = [[n] for n in domain_list]
emitter.echo(tabulate(rows, showindex="always"))
choice = click.prompt(

View File

@ -3,6 +3,7 @@ from pathlib import Path
import click
from web3 import Web3
from nucypher.blockchain.eth import domains
from nucypher.blockchain.eth.agents import (
ContractAgency,
TACoApplicationAgent,
@ -11,7 +12,6 @@ from nucypher.blockchain.eth.constants import (
AVERAGE_BLOCK_TIME_IN_SECONDS,
TACO_CONTRACT_NAMES,
)
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.cli.config import group_general_config
from nucypher.cli.options import (
group_options,
@ -42,7 +42,7 @@ option_domain = click.option(
"--domain",
help="TACo Domain",
type=click.STRING,
default=click.Choice(NetworksInventory.SUPPORTED_DOMAIN_NAMES),
default=click.Choice(domains.SUPPORTED_DOMAIN_NAMES),
required=True,
)

View File

@ -176,7 +176,7 @@ def option_message_kit(required: bool = False, multiple: bool = False):
def option_domain(
required: bool = False,
default: str = None, # NetworksInventory.DEFAULT is not a good global default (2214)
default: str = None, # nucypher.blockchain.eth.domains.DEFAULT.name is not a good global default (#2214)
validate: bool = False,
):
return click.option(

View File

@ -10,7 +10,7 @@ from cryptography.exceptions import InternalError
from eth_utils import to_checksum_address
from nucypher_core.umbral import PublicKey
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth import domains
from nucypher.blockchain.eth.token import TToken
from nucypher.policy.payment import PRE_PAYMENT_METHODS
from nucypher.utilities.networking import InvalidOperatorIP, validate_operator_ip
@ -97,9 +97,9 @@ class NuCypherDomainName(click.ParamType):
def convert(self, value, param, ctx):
if self.validate:
domain = str(value).lower()
if domain not in NetworksInventory.SUPPORTED_DOMAIN_NAMES:
if domain not in domains.SUPPORTED_DOMAIN_NAMES:
self.fail(
f"'{value}' is not a recognized domain. Valid options are: {list(NetworksInventory.SUPPORTED_DOMAIN_NAMES)}"
f"'{value}' is not a recognized domain. Valid options are: {list(domains.SUPPORTED_DOMAIN_NAMES)}"
)
else:
return domain

View File

@ -16,8 +16,8 @@ from constant_sorrow.constants import (
)
from eth_utils.address import is_checksum_address
from nucypher.blockchain.eth import domains
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.registry import (
ContractRegistry,
LocalRegistrySource,
@ -307,7 +307,7 @@ class CharacterConfiguration(BaseConfiguration):
CHARACTER_CLASS = NotImplemented
MNEMONIC_KEYSTORE = False
DEFAULT_DOMAIN = NetworksInventory.DEFAULT_DOMAIN_NAME
DEFAULT_DOMAIN = domains.DEFAULT_DOMAIN_NAME
DEFAULT_NETWORK_MIDDLEWARE = RestMiddleware
TEMP_CONFIGURATION_DIR_PREFIX = 'tmp-nucypher'
SIGNER_ENVVAR = None
@ -420,7 +420,7 @@ class CharacterConfiguration(BaseConfiguration):
# Learner
self.domain = domain
self.taco_domain = NetworksInventory.from_domain_name(self.domain)
self.taco_domain = domains.from_domain_name(self.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

View File

@ -5,7 +5,7 @@ from typing import Dict, List, Optional
from cryptography.x509 import Certificate
from eth_utils import is_checksum_address
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth import domains
from nucypher.config.base import CharacterConfiguration
from nucypher.config.constants import (
NUCYPHER_ENVVAR_ALICE_ETH_PASSWORD,
@ -70,7 +70,7 @@ class UrsulaConfiguration(CharacterConfiguration):
def configure_condition_blockchain_endpoints(self) -> None:
"""Configure default condition provider URIs for eth and polygon network."""
taco_domain = NetworksInventory.from_domain_name(self.domain)
taco_domain = domains.from_domain_name(self.domain)
# Polygon
polygon_chain_id = taco_domain.polygon_chain.id

View File

@ -1,11 +1,11 @@
from typing import Dict
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth import domains
from nucypher.config.migrations.common import perform_migration
def __migration(config: Dict) -> Dict:
taco_domain = NetworksInventory.from_domain_name(config["domain"])
taco_domain = domains.from_domain_name(config["domain"])
eth_provider = config["eth_provider_uri"]
eth_chain_id = taco_domain.eth_chain.id
polygon_provider = config["payment_provider"]

View File

@ -26,9 +26,9 @@ from twisted.internet.defer import Deferred
from nucypher import characters
from nucypher.acumen.nicknames import Nickname
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.networks import NetworksInventory
from nucypher.blockchain.eth.registry import ContractRegistry
from nucypher.config.constants import SeednodeMetadata
from nucypher.config.storages import ForgetfulNodeStorage
@ -46,14 +46,14 @@ from nucypher.network.protocols import InterfaceInfo, SuspiciousActivity
from nucypher.utilities.logging import Logger
TEACHER_NODES = {
NetworksInventory.MAINNET.name: (
domains.MAINNET.name: (
'https://closest-seed.nucypher.network:9151',
'https://seeds.nucypher.network',
'https://mainnet.nucypher.network:9151',
),
NetworksInventory.LYNX.name: ("https://lynx.nucypher.network:9151",),
NetworksInventory.TAPIR.name: ("https://tapir.nucypher.network:9151",),
NetworksInventory.ORYX.name: ("https://oryx.nucypher.network:9151",),
domains.LYNX.name: ("https://lynx.nucypher.network:9151",),
domains.TAPIR.name: ("https://tapir.nucypher.network:9151",),
domains.ORYX.name: ("https://oryx.nucypher.network:9151",),
}
@ -271,7 +271,7 @@ class Learner:
self.learning_deferred = Deferred()
self.domain = domain
self.taco_domain = NetworksInventory.from_domain_name(self.domain)
self.taco_domain = domains.from_domain_name(self.domain)
default_middleware = self.__DEFAULT_MIDDLEWARE_CLASS(
registry=self.registry, eth_endpoint=self.eth_endpoint
)

View File

@ -5,8 +5,8 @@ import maya
from nucypher_core import ReencryptionRequest
from web3.types import ChecksumAddress, Timestamp, TxReceipt, Wei
from nucypher.blockchain.eth import domains
from nucypher.blockchain.eth.agents import ContractAgency, SubscriptionManagerAgent
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.registry import ContractRegistry
from nucypher.policy import policies
@ -73,7 +73,7 @@ class ContractPayment(PaymentMethod, ABC):
):
super().__init__(*args, **kwargs)
self.blockchain_endpoint = blockchain_endpoint
self.taco_domain = NetworksInventory.from_domain_name(domain)
self.taco_domain = domains.from_domain_name(domain)
if not registry:
registry = ContractRegistry.from_latest_publication(domain=domain)
self.registry = registry

View File

@ -20,6 +20,7 @@ import rlcompleter
import click
from nucypher.blockchain.eth import domains
from nucypher.blockchain.eth.agents import (
ContractAgency,
CoordinatorAgent,
@ -27,7 +28,6 @@ from nucypher.blockchain.eth.agents import (
TACoApplicationAgent,
TACoChildApplicationAgent,
)
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.registry import ContractRegistry
from nucypher.utilities.emitters import StdoutEmitter
from nucypher.utilities.logging import GlobalLoggerSettings
@ -45,7 +45,7 @@ emitter = StdoutEmitter(verbosity=2)
"--domain",
"domain",
help="TACo domain",
type=click.Choice(NetworksInventory.SUPPORTED_DOMAIN_NAMES),
type=click.Choice(domains.SUPPORTED_DOMAIN_NAMES),
default="lynx",
)
@click.option(

View File

@ -6,12 +6,12 @@ import maya
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.networks import NetworksInventory
from nucypher.blockchain.eth.registry import ContractRegistry
from nucypher.blockchain.eth.signers import InMemorySigner, Signer
from nucypher.characters.lawful import Bob, Enrico
@ -154,7 +154,7 @@ def nucypher_dkg(
),
)
taco_domain = NetworksInventory.from_domain_name(domain)
taco_domain = domains.from_domain_name(domain)
registry = ContractRegistry.from_latest_publication(
domain=domain
)

View File

@ -11,13 +11,12 @@ from nucypher.blockchain.eth.agents import (
TACoApplicationAgent,
TACoChildApplicationAgent,
)
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.networks import (
from nucypher.blockchain.eth.domains import (
EthChain,
NetworksInventory,
PolygonChain,
TACoDomain,
)
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
@ -304,8 +303,8 @@ def deployed_contracts(
@pytest.fixture(scope="module", autouse=True)
def test_registry(deployed_contracts):
with tests.utils.registry.mock_registry_sources():
def test_registry(deployed_contracts, module_mocker):
with tests.utils.registry.mock_registry_sources(mocker=module_mocker):
RegistrySourceManager._FALLBACK_CHAIN = (ApeRegistrySource,)
source = ApeRegistrySource(domain=TEMPORARY_DOMAIN)
registry = ContractRegistry(source=source)
@ -445,8 +444,8 @@ def mock_condition_blockchains(session_mocker):
TEMPORARY_DOMAIN, EthChain.TESTERCHAIN, PolygonChain.TESTERCHAIN
)
session_mocker.patch.object(
NetworksInventory, "from_domain_name", return_value=test_domain
session_mocker.patch(
"nucypher.blockchain.eth.domains.from_domain_name", return_value=test_domain
)

View File

@ -4,9 +4,8 @@ import pytest
from eth_utils.crypto import keccak
from nucypher.blockchain.eth.actors import Operator
from nucypher.blockchain.eth.networks import (
from nucypher.blockchain.eth.domains import (
EthChain,
NetworksInventory,
PolygonChain,
TACoDomain,
)
@ -151,8 +150,8 @@ def mock_condition_blockchains(session_mocker):
TEMPORARY_DOMAIN, EthChain.TESTERCHAIN, PolygonChain.TESTERCHAIN
)
session_mocker.patch.object(
NetworksInventory, "from_domain_name", return_value=test_domain
session_mocker.patch(
"nucypher.blockchain.eth.domains.from_domain_name", return_value=test_domain
)

View File

@ -304,8 +304,8 @@ def lonely_ursula_maker(ursula_test_config, testerchain):
@pytest.fixture(scope="module")
def mock_registry_sources():
with tests.utils.registry.mock_registry_sources():
def mock_registry_sources(module_mocker):
with tests.utils.registry.mock_registry_sources(module_mocker):
yield

View File

@ -1,9 +1,9 @@
import pytest
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth import domains
from nucypher.cli.actions.select import select_domain
__DOMAINS = NetworksInventory.SUPPORTED_DOMAIN_NAMES
__DOMAINS = domains.SUPPORTED_DOMAIN_NAMES
@pytest.mark.parametrize("user_input", range(0, len(__DOMAINS) - 1))

View File

@ -14,16 +14,15 @@ from nucypher.blockchain.eth.agents import (
TACoChildApplicationAgent,
)
from nucypher.blockchain.eth.clients import EthereumClient
from nucypher.blockchain.eth.domains import (
EthChain,
PolygonChain,
TACoDomain,
)
from nucypher.blockchain.eth.interfaces import (
BlockchainInterface,
BlockchainInterfaceFactory,
)
from nucypher.blockchain.eth.networks import (
EthChain,
NetworksInventory,
PolygonChain,
TACoDomain,
)
from nucypher.blockchain.eth.registry import (
ContractRegistry,
)
@ -137,8 +136,8 @@ def mock_interface(module_mocker):
@pytest.fixture(scope='module')
def test_registry():
with mock_registry_sources():
def test_registry(module_mocker):
with mock_registry_sources(mocker=module_mocker):
mock_source = MockRegistrySource(domain=TEMPORARY_DOMAIN)
registry = ContractRegistry(source=mock_source)
yield registry
@ -295,8 +294,8 @@ def mock_condition_blockchains(session_mocker):
TEMPORARY_DOMAIN, EthChain.TESTERCHAIN, PolygonChain.TESTERCHAIN
)
session_mocker.patch.object(
NetworksInventory, "from_domain_name", return_value=test_domain
session_mocker.patch(
"nucypher.blockchain.eth.domains.from_domain_name", return_value=test_domain
)

View File

@ -22,7 +22,7 @@ from nucypher_core.umbral import SecretKey
from web3 import Web3
from web3.types import Wei
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.domains import LYNX
from nucypher.blockchain.eth.signers import Signer
from nucypher.characters.lawful import Alice, Bob, Ursula
from nucypher.config.characters import AliceConfiguration
@ -54,7 +54,7 @@ except KeyError:
raise RuntimeError(message)
# Alice Configuration
TACO_DOMAIN: str = NetworksInventory.LYNX.name # mainnet
TACO_DOMAIN: str = LYNX.name # mainnet
DEFAULT_SEEDNODE_URIS: List[str] = [
*TEACHER_NODES[TACO_DOMAIN],
]

View File

@ -18,8 +18,8 @@ def pytest_addhooks(pluginmanager):
@pytest.fixture(scope='module')
def test_registry():
with mock_registry_sources():
def test_registry(module_mocker):
with mock_registry_sources(mocker=module_mocker):
source = MockRegistrySource(domain=TEMPORARY_DOMAIN)
yield ContractRegistry(source=source)

View File

@ -1,6 +1,6 @@
import pytest
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth import domains
from nucypher.network.nodes import TEACHER_NODES
@ -11,6 +11,6 @@ def mock_teacher_nodes(mocker):
def test_default_teacher_seednodes_defined():
for domain in NetworksInventory.SUPPORTED_DOMAIN_NAMES:
for domain in domains.SUPPORTED_DOMAIN_NAMES:
teacher_nodes = TEACHER_NODES[domain]
assert len(teacher_nodes) > 0

View File

@ -5,9 +5,9 @@ from typing import List
from ape.contracts import ContractInstance
from eth_utils import to_checksum_address
from nucypher.blockchain.eth.networks import (
from nucypher.blockchain.eth import domains
from nucypher.blockchain.eth.domains import (
EthChain,
NetworksInventory,
PolygonChain,
TACoDomain,
)
@ -20,26 +20,15 @@ from nucypher.config.constants import TEMPORARY_DOMAIN
@contextmanager
def mock_registry_sources():
# capture the real values
real_domains = NetworksInventory.SUPPORTED_DOMAINS
real_domain_names = NetworksInventory.SUPPORTED_DOMAIN_NAMES
real_registry_sources = RegistrySourceManager._FALLBACK_CHAIN
# set the mock values
NetworksInventory.SUPPORTED_DOMAIN_NAMES = [TEMPORARY_DOMAIN]
def mock_registry_sources(mocker):
test_domain = TACoDomain(
TEMPORARY_DOMAIN, EthChain.TESTERCHAIN, PolygonChain.TESTERCHAIN
)
NetworksInventory.SUPPORTED_DOMAINS = [test_domain]
RegistrySourceManager._FALLBACK_CHAIN = (MockRegistrySource,)
yield # run the test
mocker.patch.object(domains, "SUPPORTED_DOMAINS", [test_domain])
mocker.patch.object(domains, "SUPPORTED_DOMAIN_NAMES", [TEMPORARY_DOMAIN])
# restore the real values
NetworksInventory.SUPPORTED_DOMAINS = real_domains
NetworksInventory.SUPPORTED_DOMAIN_NAMES = real_domain_names
RegistrySourceManager._FALLBACK_CHAIN = real_registry_sources
mocker.patch.object(RegistrySourceManager, "_FALLBACK_CHAIN", (MockRegistrySource,))
class MockRegistrySource(RegistrySource):