Use a constant for the temporary domain

pull/3322/head
Kieran Prasch 2023-10-29 19:42:02 +01:00 committed by KPrasch
parent 63b3d4aee9
commit ae9f4b40fa
13 changed files with 50 additions and 70 deletions

View File

@ -1,5 +1,4 @@
from nucypher.blockchain.eth import domains
from nucypher.blockchain.eth import domains
from nucypher.blockchain.eth.signers import InMemorySigner
from nucypher.characters.chaotic import NiceGuyEddie as _Enrico
from nucypher.characters.chaotic import ThisBobAlwaysDecrypts

View File

@ -9,10 +9,9 @@ from nucypher_core import FleetStateChecksum, NodeMetadata
from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Union
from nucypher import characters
from nucypher.blockchain.eth.domains import TACoDomain
from nucypher.utilities.logging import Logger
from .nicknames import Nickname
from nucypher.blockchain.eth import domains
from ..blockchain.eth.domains import TACoDomain
class ArchivedFleetState(NamedTuple):

View File

@ -64,7 +64,7 @@ def select_client_account(
blockchain = BlockchainInterfaceFactory.get_interface(endpoint=polygon_endpoint)
if signer_uri and not signer:
testnet = domain != domains.MAINNET.name
testnet = str(domain) != str(domains.MAINNET)
signer = Signer.from_signer_uri(signer_uri, testnet=testnet)
enumerated_accounts = dict(enumerate(signer.accounts))

View File

@ -21,7 +21,7 @@ from tests.constants import (
INSECURE_DEVELOPMENT_PASSWORD,
MIN_OPERATOR_SECONDS,
TEST_ETH_PROVIDER_URI,
TESTERCHAIN_CHAIN_ID,
TESTERCHAIN_CHAIN_ID, TEMPORARY_DOMAIN,
)
from tests.utils.blockchain import TesterBlockchain
from tests.utils.registry import ApeRegistrySource
@ -273,10 +273,10 @@ def deployed_contracts(
@pytest.fixture(scope="module", autouse=True)
def test_registry(deployed_contracts, module_mocker, temporary_domain):
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)
source = ApeRegistrySource(domain=TEMPORARY_DOMAIN)
registry = ContractRegistry(source=source)
yield registry
@ -403,7 +403,7 @@ def multichain_ursulas(ursulas, multichain_ids, mock_rpc_condition):
@pytest.fixture(scope="module", autouse=True)
def mock_condition_blockchains(module_mocker, temporary_domain):
def mock_condition_blockchains(module_mocker):
"""adds testerchain's chain ID to permitted conditional chains"""
module_mocker.patch.dict(
"nucypher.policy.conditions.evm._CONDITION_CHAINS",
@ -412,7 +412,7 @@ def mock_condition_blockchains(module_mocker, temporary_domain):
module_mocker.patch(
"nucypher.blockchain.eth.domains.get_domain",
return_value=temporary_domain
return_value=TEMPORARY_DOMAIN
)

View File

@ -137,7 +137,7 @@ def disable_check_grant_requirements(session_mocker):
@pytest.fixture(scope="module", autouse=True)
def mock_condition_blockchains(module_mocker, temporary_domain):
def mock_condition_blockchains(module_mocker):
"""adds testerchain's chain ID to permitted conditional chains"""
module_mocker.patch.dict(
"nucypher.policy.conditions.evm._CONDITION_CHAINS",

View File

@ -7,11 +7,11 @@ from random import SystemRandom
from hexbytes import HexBytes
from web3 import Web3
from nucypher.blockchain.eth.domains import ChainInfo
from nucypher.blockchain.eth.domains import ChainInfo, TACoDomain
from nucypher.blockchain.eth.token import NU
from nucypher.config.constants import (
NUCYPHER_ENVVAR_KEYSTORE_PASSWORD,
NUCYPHER_ENVVAR_OPERATOR_ETH_PASSWORD,
NUCYPHER_ENVVAR_OPERATOR_ETH_PASSWORD, TEMPORARY_DOMAIN_NAME,
)
#
@ -74,6 +74,12 @@ TESTERCHAIN_CHAIN_ID = 131277322940537
TESTERCHAIN_CHAIN_INFO = ChainInfo(131277322940537, "eth-tester")
TEMPORARY_DOMAIN = TACoDomain(
name=TEMPORARY_DOMAIN_NAME,
eth_chain=TESTERCHAIN_CHAIN_INFO,
polygon_chain=TESTERCHAIN_CHAIN_INFO,
)
#
# Insecure Secrets

View File

@ -18,7 +18,6 @@ from web3 import Web3
import tests
from nucypher.blockchain.eth.actors import Operator
from nucypher.blockchain.eth.domains import TACoDomain
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.signers.software import KeystoreSigner
from nucypher.blockchain.eth.trackers.dkg import EventScannerTask
@ -50,8 +49,7 @@ from tests.constants import (
MOCK_CUSTOM_INSTALLATION_PATH_2,
MOCK_ETH_PROVIDER_URI,
TEST_ETH_PROVIDER_URI,
TESTERCHAIN_CHAIN_ID, TESTERCHAIN_CHAIN_INFO,
)
TESTERCHAIN_CHAIN_ID, TEMPORARY_DOMAIN, )
from tests.mock.interfaces import MockBlockchain
from tests.mock.performance_mocks import (
mock_cert_generation,
@ -306,15 +304,6 @@ def lonely_ursula_maker(ursula_test_config, testerchain):
# Blockchain
#
@pytest.fixture(scope='session')
def temporary_domain():
_domain = TACoDomain(
name=TEMPORARY_DOMAIN_NAME,
eth_chain=TESTERCHAIN_CHAIN_INFO,
polygon_chain=TESTERCHAIN_CHAIN_INFO,
)
return _domain
@pytest.fixture(scope="module")
def mock_registry_sources(module_mocker):
@ -547,9 +536,9 @@ def worker_configuration_file_location(custom_filepath) -> Path:
@pytest.fixture(autouse=True)
def mock_teacher_nodes(mocker, temporary_domain):
def mock_teacher_nodes(mocker):
mock_nodes = tuple(u.rest_url() for u in MOCK_KNOWN_URSULAS_CACHE.values())[0:2]
mocker.patch.dict(TEACHER_NODES, {temporary_domain: mock_nodes}, clear=True)
mocker.patch.dict(TEACHER_NODES, {TEMPORARY_DOMAIN: mock_nodes}, clear=True)
@pytest.fixture(autouse=True)

View File

@ -31,7 +31,7 @@ from tests.constants import (
KEYFILE_NAME_TEMPLATE,
MOCK_KEYSTORE_PATH,
NUMBER_OF_MOCK_KEYSTORE_ACCOUNTS,
TESTERCHAIN_CHAIN_ID,
TESTERCHAIN_CHAIN_ID, TEMPORARY_DOMAIN,
)
from tests.mock.interfaces import MockBlockchain
from tests.mock.io import MockStdinWrapper
@ -129,9 +129,9 @@ def mock_interface(module_mocker):
@pytest.fixture(scope='module')
def test_registry(module_mocker, temporary_domain):
def test_registry(module_mocker):
with mock_registry_sources(mocker=module_mocker):
mock_source = MockRegistrySource(domain=temporary_domain)
mock_source = MockRegistrySource(domain=TEMPORARY_DOMAIN)
registry = ContractRegistry(source=mock_source)
yield registry
@ -276,7 +276,7 @@ def monkeypatch_get_staking_provider_from_operator(monkeymodule):
@pytest.fixture(scope="module", autouse=True)
def mock_condition_blockchains(module_mocker, temporary_domain):
def mock_condition_blockchains(module_mocker):
"""adds testerchain's chain ID to permitted conditional chains"""
module_mocker.patch.dict(
"nucypher.policy.conditions.evm._CONDITION_CHAINS",

View File

@ -8,7 +8,7 @@ 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.constants import TESTERCHAIN_CHAIN_INFO, TEMPORARY_DOMAIN
from tests.utils.registry import MockRegistrySource
from tests.utils.ursula import make_ursulas
@ -33,9 +33,9 @@ def domain_2():
@pytest.fixture(scope="module")
def test_registry(module_mocker, domain_1, domain_2, temporary_domain):
def test_registry(module_mocker, domain_1, domain_2):
with tests.utils.registry.mock_registry_sources(
mocker=module_mocker, _domains=[domain_1, domain_2, temporary_domain]
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))

View File

@ -9,6 +9,7 @@ from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
from nucypher.crypto.ferveo import dkg
from nucypher.crypto.powers import TransactingPower
from nucypher.network.nodes import Teacher
from tests.constants import TEMPORARY_DOMAIN
from tests.mock.interfaces import MockBlockchain, MockEthereumClient
from tests.utils.registry import MockRegistrySource, mock_registry_sources
@ -19,9 +20,9 @@ def pytest_addhooks(pluginmanager):
@pytest.fixture(scope='module')
def test_registry(module_mocker, temporary_domain):
def test_registry(module_mocker):
with mock_registry_sources(mocker=module_mocker):
source = MockRegistrySource(domain=temporary_domain)
source = MockRegistrySource(domain=TEMPORARY_DOMAIN)
yield ContractRegistry(source=source)

View File

@ -2,7 +2,7 @@ import pytest
from nucypher.blockchain.eth.registry import ContractRegistry
from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
from tests.constants import TESTERCHAIN_CHAIN_ID
from tests.constants import TESTERCHAIN_CHAIN_ID, TEMPORARY_DOMAIN
from tests.utils.registry import MockRegistrySource
@ -34,8 +34,8 @@ def data(record):
@pytest.fixture(scope="function")
def source(data, temporary_domain):
source = MockRegistrySource(domain=temporary_domain)
def source(data):
source = MockRegistrySource(domain=TEMPORARY_DOMAIN)
source.data = data
return source
@ -77,9 +77,9 @@ def test_local_registry_unknown_contract_name_search(registry):
)
def test_local_contract_registry_ambiguous_search_terms(data, name, record, address, temporary_domain):
def test_local_contract_registry_ambiguous_search_terms(data, name, record, address):
data[TESTERCHAIN_CHAIN_ID]["fakeContract"] = record[name]
source = MockRegistrySource(domain=temporary_domain)
source = MockRegistrySource(domain=TEMPORARY_DOMAIN)
source.data = data
registry = ContractRegistry(source=source)
with pytest.raises(ContractRegistry.AmbiguousSearchTerms):

View File

@ -12,6 +12,7 @@ from nucypher.blockchain.eth.registry import (
RegistrySourceManager,
)
from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
from tests.constants import TEMPORARY_DOMAIN
@pytest.fixture(scope="function")
@ -46,8 +47,8 @@ def test_registry_filepath(tmpdir, registry_data):
@pytest.mark.usefixtures("mock_200_response")
def test_github_registry_source(registry_data, temporary_domain):
source = GithubRegistrySource(domain=temporary_domain)
def test_github_registry_source(registry_data):
source = GithubRegistrySource(domain=TEMPORARY_DOMAIN)
assert source.domain.name == TEMPORARY_DOMAIN_NAME
assert str(source.domain) == TEMPORARY_DOMAIN_NAME
assert bytes(source.domain) == TEMPORARY_DOMAIN_NAME.encode("utf-8")
@ -57,9 +58,9 @@ def test_github_registry_source(registry_data, temporary_domain):
assert data == source.data
def test_local_registry_source(registry_data, test_registry_filepath, temporary_domain):
def test_local_registry_source(registry_data, test_registry_filepath):
source = LocalRegistrySource(
filepath=test_registry_filepath, domain=temporary_domain
filepath=test_registry_filepath, domain=TEMPORARY_DOMAIN
)
assert source.domain.name == TEMPORARY_DOMAIN_NAME
assert str(source.domain) == TEMPORARY_DOMAIN_NAME
@ -70,13 +71,13 @@ def test_local_registry_source(registry_data, test_registry_filepath, temporary_
assert data == source.data
def test_embedded_registry_source(registry_data, test_registry_filepath, mocker, temporary_domain):
def test_embedded_registry_source(registry_data, test_registry_filepath, mocker):
mocker.patch.object(
EmbeddedRegistrySource,
"get_publication_endpoint",
return_value=test_registry_filepath,
)
source = EmbeddedRegistrySource(domain=temporary_domain)
source = EmbeddedRegistrySource(domain=TEMPORARY_DOMAIN)
assert source.domain.name == TEMPORARY_DOMAIN_NAME
assert str(source.domain) == TEMPORARY_DOMAIN_NAME
assert bytes(source.domain) == TEMPORARY_DOMAIN_NAME.encode("utf-8")
@ -87,7 +88,7 @@ def test_embedded_registry_source(registry_data, test_registry_filepath, mocker,
def test_registry_source_manager_fallback(
registry_data, test_registry_filepath, mocker, temporary_domain
registry_data, test_registry_filepath, mocker
):
github_source_get = mocker.patch.object(
GithubRegistrySource, "get", side_effect=RegistrySource.Unavailable
@ -102,7 +103,7 @@ def test_registry_source_manager_fallback(
GithubRegistrySource,
EmbeddedRegistrySource,
)
source_manager = RegistrySourceManager(domain=temporary_domain)
source_manager = RegistrySourceManager(domain=TEMPORARY_DOMAIN)
assert source_manager.domain.name == TEMPORARY_DOMAIN_NAME
assert str(source_manager.domain) == TEMPORARY_DOMAIN_NAME
assert bytes(source_manager.domain) == TEMPORARY_DOMAIN_NAME.encode("utf-8")

View File

@ -12,37 +12,22 @@ from nucypher.blockchain.eth.registry import (
RegistrySourceManager,
)
from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
from tests.constants import TESTERCHAIN_CHAIN_INFO
from tests.constants import TEMPORARY_DOMAIN
@contextmanager
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,
)
]
_domains = [TEMPORARY_DOMAIN]
supported_domains = dict()
for domain in _domains:
test_domain = TACoDomain(
name=str(domain),
eth_chain=TESTERCHAIN_CHAIN_INFO,
polygon_chain=TESTERCHAIN_CHAIN_INFO,
)
supported_domains[str(domain)] = test_domain
_supported_domains = mocker.patch('nucypher.blockchain.eth.domains.SUPPORTED_DOMAINS', new_callable=dict)
_supported_domains.update(supported_domains)
_supported_domains = mocker.patch.dict(
'nucypher.blockchain.eth.domains.SUPPORTED_DOMAINS',
{domain.name: domain for domain in _domains},
)
mocker.patch.object(MockRegistrySource, "ALLOWED_DOMAINS", list(map(str, _domains)))
mocker.patch.object(RegistrySourceManager, "_FALLBACK_CHAIN", (MockRegistrySource,))
yield # run the test
yield
class MockRegistrySource(RegistrySource):