mirror of https://github.com/nucypher/nucypher.git
passing test suite with internal cache supporting multichain.
parent
c895d24ba9
commit
74c18f33d7
|
@ -106,7 +106,7 @@ class EconomicsFactory:
|
|||
|
||||
# Agents
|
||||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent, registry=registry, eth_provider_uri=eth_provider_uri
|
||||
PREApplicationAgent, registry=registry, provider_uri=eth_provider_uri
|
||||
)
|
||||
|
||||
# PRE Application
|
||||
|
|
|
@ -134,7 +134,7 @@ class NucypherTokenActor(BaseActor):
|
|||
return self.__token_agent
|
||||
self.__token_agent = ContractAgency.get_agent(
|
||||
NucypherTokenAgent,
|
||||
eth_provider_uri=self.eth_provider_uri,
|
||||
provider_uri=self.eth_provider_uri,
|
||||
registry=self.registry,
|
||||
)
|
||||
return self.__token_agent
|
||||
|
@ -201,7 +201,7 @@ class Operator(BaseActor):
|
|||
if is_me:
|
||||
self.application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
eth_provider_uri=eth_provider_uri,
|
||||
provider_uri=eth_provider_uri,
|
||||
registry=self.registry,
|
||||
)
|
||||
self.work_tracker = work_tracker or WorkTracker(worker=self)
|
||||
|
@ -315,7 +315,7 @@ class Ritualist(BaseActor):
|
|||
self.coordinator_agent = ContractAgency.get_agent(
|
||||
CoordinatorAgent,
|
||||
registry=InMemoryContractRegistry.from_latest_publication(network=network),
|
||||
eth_provider_uri=provider_uri, # TODO: rename, this might be a polygon provider
|
||||
provider_uri=provider_uri, # TODO: rename, this might be a polygon provider
|
||||
)
|
||||
|
||||
# track active onchain rituals
|
||||
|
@ -626,9 +626,7 @@ class PolicyAuthor(NucypherTokenActor):
|
|||
def __init__(self, eth_provider_uri: str, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=self.registry,
|
||||
eth_provider_uri=eth_provider_uri
|
||||
PREApplicationAgent, registry=self.registry, provider_uri=eth_provider_uri
|
||||
)
|
||||
|
||||
def create_policy(self, *args, **kwargs):
|
||||
|
|
|
@ -63,7 +63,7 @@ class EthereumContractAgent:
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
eth_provider_uri: str,
|
||||
provider_uri: str,
|
||||
registry: BaseContractRegistry,
|
||||
contract: Optional[Contract] = None,
|
||||
transaction_gas: Optional[Wei] = None,
|
||||
|
@ -74,7 +74,7 @@ class EthereumContractAgent:
|
|||
self.registry = registry
|
||||
|
||||
self.blockchain = BlockchainInterfaceFactory.get_or_create_interface(
|
||||
eth_provider_uri=eth_provider_uri
|
||||
eth_provider_uri=provider_uri
|
||||
)
|
||||
|
||||
if not contract: # Fetch the contract
|
||||
|
@ -762,13 +762,13 @@ class ContractAgency:
|
|||
cls,
|
||||
agent_class: Type[Agent],
|
||||
registry: Optional[BaseContractRegistry],
|
||||
eth_provider_uri: Optional[str],
|
||||
provider_uri: Optional[str],
|
||||
contract_version: Optional[str] = None,
|
||||
) -> Agent:
|
||||
if not issubclass(agent_class, EthereumContractAgent):
|
||||
raise TypeError("Only agent subclasses can be used from the agency.")
|
||||
|
||||
if not eth_provider_uri:
|
||||
if not provider_uri:
|
||||
raise ValueError(
|
||||
"Need to specify an Ethereum provider URI in order to get an agent from the ContractAgency"
|
||||
)
|
||||
|
@ -782,7 +782,14 @@ class ContractAgency:
|
|||
try:
|
||||
return cast(Agent, cls.__agents[registry_id][agent_class])
|
||||
except KeyError:
|
||||
agent = cast(Agent, agent_class(registry=registry, eth_provider_uri=eth_provider_uri, contract_version=contract_version))
|
||||
agent = cast(
|
||||
Agent,
|
||||
agent_class(
|
||||
registry=registry,
|
||||
provider_uri=provider_uri,
|
||||
contract_version=contract_version,
|
||||
),
|
||||
)
|
||||
cls.__agents[registry_id] = cls.__agents.get(registry_id, dict())
|
||||
cls.__agents[registry_id][agent_class] = agent
|
||||
return agent
|
||||
|
@ -810,7 +817,7 @@ class ContractAgency:
|
|||
agent: EthereumContractAgent = cls.get_agent(
|
||||
agent_class=agent_class,
|
||||
registry=registry,
|
||||
eth_provider_uri=eth_provider_uri,
|
||||
provider_uri=eth_provider_uri,
|
||||
contract_version=contract_version
|
||||
)
|
||||
return agent
|
||||
|
|
|
@ -459,7 +459,7 @@ class Bob(Character):
|
|||
)
|
||||
coordinator_agent = ContractAgency.get_agent(
|
||||
CoordinatorAgent,
|
||||
eth_provider_uri=coordinator_provider_uri,
|
||||
provider_uri=coordinator_provider_uri,
|
||||
registry=InMemoryContractRegistry.from_latest_publication(
|
||||
network=coordinator_network
|
||||
),
|
||||
|
@ -1270,7 +1270,7 @@ class Ursula(Teacher, Character, Operator, Ritualist):
|
|||
# Check the node's stake (optional)
|
||||
if minimum_stake > 0 and staking_provider_address:
|
||||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent, eth_provider_uri=provider_uri, registry=registry
|
||||
PREApplicationAgent, provider_uri=provider_uri, registry=registry
|
||||
)
|
||||
seednode_stake = application_agent.get_authorized_stake(
|
||||
staking_provider=staking_provider_address
|
||||
|
|
|
@ -104,7 +104,7 @@ def select_client_account(emitter,
|
|||
row.append(f'{ether_balance} ETH')
|
||||
if show_nu_balance:
|
||||
token_agent = ContractAgency.get_agent(
|
||||
NucypherTokenAgent, registry=registry, eth_provider_uri=eth_provider_uri
|
||||
NucypherTokenAgent, registry=registry, provider_uri=eth_provider_uri
|
||||
)
|
||||
token_balance = NU.from_units(token_agent.get_balance(account, registry))
|
||||
row.append(token_balance)
|
||||
|
|
|
@ -1045,7 +1045,7 @@ class Teacher:
|
|||
the case that the "staking provider" isn't "staking" (e.g., all her tokens have been slashed).
|
||||
"""
|
||||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent, eth_provider_uri=provider_uri, registry=registry
|
||||
PREApplicationAgent, provider_uri=provider_uri, registry=registry
|
||||
) # type: PREApplicationAgent
|
||||
staking_provider_address = application_agent.get_staking_provider_from_operator(operator_address=self.operator_address)
|
||||
if staking_provider_address == NULL_ADDRESS:
|
||||
|
@ -1058,7 +1058,7 @@ class Teacher:
|
|||
As a follow-up, this checks that the staking provider is, indeed, staking.
|
||||
"""
|
||||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent, registry=registry, eth_provider_uri=eth_provider_uri
|
||||
PREApplicationAgent, registry=registry, provider_uri=eth_provider_uri
|
||||
) # type: PREApplicationAgent
|
||||
is_staking = application_agent.is_authorized(staking_provider=self.checksum_address) # checksum address here is staking provider
|
||||
return is_staking
|
||||
|
|
|
@ -32,7 +32,7 @@ class OperatorBondedTracker(SimpleTask):
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=self._ursula.registry,
|
||||
eth_provider_uri=self._ursula.eth_provider_uri,
|
||||
provider_uri=self._ursula.eth_provider_uri,
|
||||
)
|
||||
staking_provider_address = application_agent.get_staking_provider_from_operator(
|
||||
operator_address=self._ursula.operator_address)
|
||||
|
|
|
@ -84,9 +84,7 @@ class ContractPayment(PaymentMethod, ABC):
|
|||
if self.__agent:
|
||||
return self.__agent # get cache
|
||||
agent = ContractAgency.get_agent(
|
||||
agent_class=self._AGENT,
|
||||
eth_provider_uri=self.provider,
|
||||
registry=self.registry
|
||||
agent_class=self._AGENT, provider_uri=self.provider, registry=self.registry
|
||||
)
|
||||
self.__agent = agent
|
||||
return self.__agent # set cache
|
||||
|
|
|
@ -40,7 +40,7 @@ def cohort(ursulas):
|
|||
def coordinator_agent(testerchain, test_registry):
|
||||
"""Creates a coordinator agent"""
|
||||
return ContractAgency.get_agent(
|
||||
CoordinatorAgent, registry=test_registry, eth_provider_uri=TEST_ETH_PROVIDER_URI
|
||||
CoordinatorAgent, registry=test_registry, provider_uri=TEST_ETH_PROVIDER_URI
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ def test_ursula_operator_confirmation(
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
|
||||
staking_provider = testerchain.stake_provider_account(0)
|
||||
|
@ -98,7 +98,7 @@ def test_ursula_operator_confirmation_autopilot(
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
staking_provider2 = testerchain.stake_provider_account(1)
|
||||
operator2 = testerchain.ursula_account(1)
|
||||
|
@ -172,7 +172,7 @@ def test_work_tracker(
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
|
||||
staking_provider3 = testerchain.stake_provider_account(2)
|
||||
|
|
|
@ -9,12 +9,12 @@ def test_get_agent_with_different_registries(application_economics, test_registr
|
|||
application_agent_1 = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
application_agent_2 = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
assert application_agent_2.registry == application_agent_1.registry == test_registry
|
||||
assert application_agent_2 is application_agent_1
|
||||
|
@ -23,7 +23,7 @@ def test_get_agent_with_different_registries(application_economics, test_registr
|
|||
application_agent_2 = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=agency_local_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
assert application_agent_2.registry == test_registry
|
||||
assert application_agent_2 is application_agent_1
|
||||
|
|
|
@ -17,7 +17,7 @@ from tests.constants import TEST_ETH_PROVIDER_URI
|
|||
@pytest.fixture(scope='module')
|
||||
def agent(testerchain, test_registry) -> CoordinatorAgent:
|
||||
coordinator_agent = ContractAgency.get_agent(
|
||||
CoordinatorAgent, registry=test_registry, eth_provider_uri=TEST_ETH_PROVIDER_URI
|
||||
CoordinatorAgent, registry=test_registry, provider_uri=TEST_ETH_PROVIDER_URI
|
||||
)
|
||||
return coordinator_agent
|
||||
|
||||
|
@ -41,7 +41,7 @@ def ursulas(cohort, test_registry):
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
for provider in cohort:
|
||||
operator = application_agent.get_operator_from_staking_provider(provider)
|
||||
|
|
|
@ -17,7 +17,7 @@ def test_get_min_authorization(test_registry, application_economics):
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
result = application_agent.get_min_authorization()
|
||||
assert result == application_economics.min_authorization
|
||||
|
@ -27,7 +27,7 @@ def test_get_min_seconds(test_registry, application_economics):
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
result = application_agent.get_min_operator_seconds()
|
||||
assert result == application_economics.min_operator_seconds
|
||||
|
@ -39,7 +39,7 @@ def test_authorized_tokens(
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
provider_account = staking_providers[0]
|
||||
authorized_amount = application_agent.get_authorized_stake(staking_provider=provider_account)
|
||||
|
@ -52,7 +52,7 @@ def test_staking_providers_and_operators_relationships(
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
|
||||
staking_provider_account, operator_account, *other = testerchain.unassigned_accounts
|
||||
|
@ -83,7 +83,7 @@ def test_get_staker_population(staking_providers, test_registry):
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
|
||||
# Apart from all the providers in the fixture, we also added a new provider above
|
||||
|
@ -94,7 +94,7 @@ def test_get_swarm(staking_providers, test_registry):
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
|
||||
swarm = application_agent.swarm()
|
||||
|
@ -112,7 +112,7 @@ def test_sample_staking_providers(test_registry):
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
|
||||
providers_population = application_agent.get_staking_providers_population()
|
||||
|
@ -140,7 +140,7 @@ def test_get_staking_provider_info(testerchain, test_registry):
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
staking_provider_account, operator_account, *other = testerchain.unassigned_accounts
|
||||
info: StakingProviderInfo = application_agent.get_staking_provider_info(staking_provider=staking_provider_account)
|
||||
|
|
|
@ -20,7 +20,7 @@ def test_sampling_distribution(testerchain, test_registry, threshold_staking, ap
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
stake_provider_accounts = testerchain.stake_providers_accounts
|
||||
amount = application_economics.min_authorization
|
||||
|
|
|
@ -93,7 +93,7 @@ def test_invalid_operators_tolerance(
|
|||
application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
(
|
||||
creator,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from nucypher.characters.lawful import Character
|
||||
from nucypher.config.constants import TEMPORARY_DOMAIN
|
||||
from tests.constants import MOCK_ETH_PROVIDER_URI
|
||||
from tests.constants import TEST_ETH_PROVIDER_URI
|
||||
|
||||
|
||||
def test_character_transacting_power_signing(testerchain, test_registry):
|
||||
|
@ -10,7 +10,7 @@ def test_character_transacting_power_signing(testerchain, test_registry):
|
|||
signer = Character(
|
||||
is_me=True,
|
||||
domain=TEMPORARY_DOMAIN,
|
||||
eth_provider_uri=MOCK_ETH_PROVIDER_URI,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
registry=test_registry,
|
||||
checksum_address=eth_address,
|
||||
)
|
||||
|
@ -125,7 +125,7 @@ def test_transacting_power_sign_agent_transaction(testerchain, test_registry):
|
|||
agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=MOCK_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
contract_function = agent.contract.functions.confirmOperatorAddress()
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ def mock_funded_account_password_keystore(tmp_path_factory, testerchain, thresho
|
|||
pre_application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
pre_application_agent.bond_operator(
|
||||
staking_provider=provider_address,
|
||||
|
|
|
@ -59,7 +59,7 @@ def erc20_evm_condition_balanceof(testerchain, test_registry):
|
|||
token = ContractAgency.get_agent(
|
||||
NucypherTokenAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
condition = ContractCondition(
|
||||
contract_address=token.contract.address,
|
||||
|
@ -122,7 +122,7 @@ def subscription_manager_get_policy_zeroized_policy_struct_condition(
|
|||
subscription_manager = ContractAgency.get_agent(
|
||||
SubscriptionManagerAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
condition = ContractCondition(
|
||||
contract_address=subscription_manager.contract.address,
|
||||
|
@ -159,7 +159,7 @@ def custom_context_variable_erc20_condition(
|
|||
token = ContractAgency.get_agent(
|
||||
NucypherTokenAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
condition = ContractCondition(
|
||||
contract_address=token.contract.address,
|
||||
|
|
|
@ -25,7 +25,7 @@ from nucypher.policy.conditions.exceptions import (
|
|||
RPCExecutionFailed,
|
||||
)
|
||||
from nucypher.policy.conditions.lingo import ConditionLingo, ReturnValueTest
|
||||
from tests.constants import TESTERCHAIN_CHAIN_ID
|
||||
from tests.constants import TEST_POLYGON_PROVIDER_URI, TESTERCHAIN_CHAIN_ID
|
||||
from tests.utils.policy import make_message_kits
|
||||
|
||||
|
||||
|
@ -460,7 +460,9 @@ def test_subscription_manager_get_policy_policy_struct_condition_index_and_value
|
|||
":sponsor": sponsor,
|
||||
} # user-defined context vars
|
||||
subscription_manager = ContractAgency.get_agent(
|
||||
SubscriptionManagerAgent, registry=test_registry
|
||||
SubscriptionManagerAgent,
|
||||
registry=test_registry,
|
||||
provider_uri=TEST_POLYGON_PROVIDER_URI,
|
||||
)
|
||||
|
||||
# test "sponsor" index not equal to correct value
|
||||
|
|
|
@ -73,7 +73,7 @@ def staking_providers(testerchain, test_registry, threshold_staking):
|
|||
pre_application_agent = ContractAgency.get_agent(
|
||||
PREApplicationAgent,
|
||||
registry=test_registry,
|
||||
eth_provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
blockchain = pre_application_agent.blockchain
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ from tests.mock.coordinator import MockCoordinatorAgent
|
|||
@pytest.fixture(scope="module")
|
||||
def agent(mock_contract_agency) -> MockCoordinatorAgent:
|
||||
coordinator_agent: CoordinatorAgent = mock_contract_agency.get_agent(
|
||||
CoordinatorAgent, registry=None, eth_provider_uri=MOCK_ETH_PROVIDER_URI
|
||||
CoordinatorAgent, registry=None, provider_uri=MOCK_ETH_PROVIDER_URI
|
||||
)
|
||||
return coordinator_agent
|
||||
|
||||
|
|
Loading…
Reference in New Issue