Expands domains data model to include condition chains

pull/3323/head
Kieran Prasch 2023-10-30 20:52:05 +01:00 committed by KPrasch
parent 1d179cc276
commit d63a6cb93d
11 changed files with 52 additions and 16 deletions

View File

@ -9,9 +9,9 @@ from eth_typing import ChecksumAddress
from nucypher_core import FleetStateChecksum, NodeMetadata
from nucypher import characters
from nucypher.blockchain.eth.domains import TACoDomain
from nucypher.utilities.logging import Logger
from ..blockchain.eth.domains import TACoDomain
from .nicknames import Nickname

View File

@ -1,5 +1,5 @@
from enum import Enum
from typing import Any, Dict, NamedTuple
from typing import Any, Dict, NamedTuple, Tuple
from cytoolz.functoolz import memoize
@ -25,10 +25,17 @@ class PolygonChain(ChainInfo, Enum):
class TACoDomain:
def __init__(self, name: str, eth_chain: EthChain, polygon_chain: PolygonChain):
def __init__(
self,
name: str,
eth_chain: EthChain,
polygon_chain: PolygonChain,
condition_chains: Tuple[ChainInfo, ...],
):
self.name = name
self.eth_chain = eth_chain
self.polygon_chain = polygon_chain
self.condition_chains = condition_chains
def __repr__(self) -> str:
return f"<TACoDomain {self.name}>"
@ -63,18 +70,26 @@ MAINNET = TACoDomain(
name="mainnet",
eth_chain=EthChain.MAINNET,
polygon_chain=PolygonChain.MAINNET,
condition_chains=(EthChain.MAINNET, PolygonChain.MAINNET),
)
LYNX = TACoDomain(
name="lynx",
eth_chain=EthChain.GOERLI,
polygon_chain=PolygonChain.MUMBAI,
condition_chains=(
EthChain.MAINNET,
EthChain.GOERLI,
PolygonChain.MUMBAI,
PolygonChain.MAINNET,
),
)
TAPIR = TACoDomain(
name="tapir",
eth_chain=EthChain.SEPOLIA,
polygon_chain=PolygonChain.MUMBAI,
condition_chains=(EthChain.SEPOLIA, PolygonChain.MUMBAI),
)

View File

@ -6,9 +6,9 @@ from nucypher_core import ReencryptionRequest
from web3.types import ChecksumAddress, Timestamp, TxReceipt, Wei
from nucypher.blockchain.eth.agents import ContractAgency, SubscriptionManagerAgent
from nucypher.blockchain.eth.domains import TACoDomain
from nucypher.blockchain.eth.registry import ContractRegistry
from nucypher.policy import policies
from tests.utils.registry import TACoDomain
class PaymentMethod(ABC):

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 import domains
from nucypher.blockchain.eth.registry import ContractRegistry
from nucypher.utilities.emitters import StdoutEmitter
from nucypher.utilities.logging import GlobalLoggerSettings

View File

@ -79,6 +79,7 @@ TEMPORARY_DOMAIN = TACoDomain(
name=TEMPORARY_DOMAIN_NAME,
eth_chain=TESTERCHAIN_CHAIN_INFO,
polygon_chain=TESTERCHAIN_CHAIN_INFO,
condition_chains=(TESTERCHAIN_CHAIN_INFO,),
)

View File

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

View File

@ -286,7 +286,6 @@ def mock_condition_blockchains(module_mocker):
)
@pytest.fixture(scope="module")
def multichain_ids(module_mocker):
ids = mock_permitted_multichain_connections(mocker=module_mocker)

View File

@ -20,6 +20,7 @@ def domain_1():
name="domain_uno",
eth_chain=TESTERCHAIN_CHAIN_INFO,
polygon_chain=TESTERCHAIN_CHAIN_INFO,
condition_chains=(TESTERCHAIN_CHAIN_INFO,),
)
@ -29,6 +30,7 @@ def domain_2():
name="domain_dos",
eth_chain=TESTERCHAIN_CHAIN_INFO,
polygon_chain=TESTERCHAIN_CHAIN_INFO,
condition_chains=(TESTERCHAIN_CHAIN_INFO,),
)

View File

@ -9,13 +9,13 @@ from nucypher.blockchain.eth.domains import (
@pytest.fixture(scope="module")
def test_registry(module_mocker):
# override fixture which mocks SUPPORTED_DOMAINS
# override fixture which mocks domains.SUPPORTED_DOMAINS
yield
@pytest.fixture(scope="module", autouse=True)
def mock_condition_blockchains(module_mocker):
# override fixture which mocks get_domain
# override fixture which mocks domains.get_domain
yield
@ -49,9 +49,32 @@ def test_polygon_chains(poly_chain_test):
@pytest.mark.parametrize(
"taco_domain_test",
(
(domains.MAINNET, "mainnet", EthChain.MAINNET, PolygonChain.MAINNET),
(domains.LYNX, "lynx", EthChain.GOERLI, PolygonChain.MUMBAI),
(domains.TAPIR, "tapir", EthChain.SEPOLIA, PolygonChain.MUMBAI),
(
domains.MAINNET,
"mainnet",
EthChain.MAINNET,
PolygonChain.MAINNET,
(EthChain.MAINNET, PolygonChain.MAINNET),
),
(
domains.LYNX,
"lynx",
EthChain.GOERLI,
PolygonChain.MUMBAI,
(
EthChain.MAINNET,
EthChain.GOERLI,
PolygonChain.MUMBAI,
PolygonChain.MAINNET,
),
),
(
domains.TAPIR,
"tapir",
EthChain.SEPOLIA,
PolygonChain.MUMBAI,
(EthChain.SEPOLIA, PolygonChain.MUMBAI),
),
),
)
def test_taco_domain_info(taco_domain_test):

View File

@ -12,7 +12,7 @@ def mock_teacher_nodes(mocker):
@pytest.fixture(scope="module")
def test_registry(module_mocker):
# override fixture which mocks SUPPORTED_DOMAINS
# override fixture which mocks domains.SUPPORTED_DOMAINS
yield

View File

@ -19,12 +19,10 @@ from tests.constants import TEMPORARY_DOMAIN
def mock_registry_sources(mocker, _domains: List[TACoDomain] = None):
if not _domains:
_domains = [TEMPORARY_DOMAIN]
_supported_domains = mocker.patch.dict(
"nucypher.blockchain.eth.domains.SUPPORTED_DOMAINS",
{str(domain): domain for domain in _domains},
)
mocker.patch.object(MockRegistrySource, "ALLOWED_DOMAINS", list(map(str, _domains)))
mocker.patch.object(RegistrySourceManager, "_FALLBACK_CHAIN", (MockRegistrySource,))
yield