Fix some tests; ERC721 contract needs to be deployed on APE, and MockContractAgency import is now inlined.

pull/3115/head
derekpierre 2023-04-26 15:59:33 -04:00 committed by Kieran Prasch
parent e0286d13c5
commit c157c8ccf7
6 changed files with 20 additions and 30 deletions

View File

@ -1,5 +1,3 @@
from pathlib import Path
import pytest
import nucypher
@ -8,8 +6,6 @@ from nucypher.blockchain.eth.agents import (
NucypherTokenAgent,
SubscriptionManagerAgent,
)
from nucypher.blockchain.eth.signers.software import Web3Signer
from nucypher.crypto.powers import TransactingPower
from nucypher.policy.conditions.context import USER_ADDRESS_CONTEXT
from nucypher.policy.conditions.evm import ContractCondition
from nucypher.policy.conditions.lingo import AND, OR, ConditionLingo, ReturnValueTest
@ -22,7 +18,6 @@ def condition_providers(testerchain):
return providers
@pytest.fixture(autouse=True)
def mock_condition_blockchains(mocker):
"""adds testerchain's chain ID to permitted conditional chains"""
mocker.patch.object(
@ -51,7 +46,7 @@ def compound_lingo(erc721_evm_condition_balanceof,
@pytest.fixture()
def erc20_evm_condition_balanceof(test_registry, agency):
def erc20_evm_condition_balanceof(testerchain, test_registry):
token = ContractAgency.get_agent(NucypherTokenAgent, registry=test_registry)
condition = ContractCondition(
contract_address=token.contract.address,
@ -65,22 +60,15 @@ def erc20_evm_condition_balanceof(test_registry, agency):
@pytest.fixture
def erc721_contract(testerchain, test_registry):
def erc721_contract(accounts, project, test_registry):
account = accounts[0]
origin, *everybody_else = testerchain.client.accounts
transacting_power = TransactingPower(
account=origin, signer=Web3Signer(testerchain.client)
)
contract, receipt = testerchain.deploy_contract(
transacting_power=transacting_power,
registry=test_registry,
contract_name="ConditionNFT",
)
# mint an NFT with tokenId = 1
tx = contract.functions.mint(origin, 1).transact({"from": origin})
testerchain.wait_for_receipt(tx)
# deploy contract
deployed_contract = account.deploy(project.ConditionNFT)
return contract
# mint nft with token id = 1
deployed_contract.mint(account.address, 1, sender=account)
return deployed_contract
@pytest.fixture
@ -116,7 +104,7 @@ def erc721_evm_condition_balanceof(erc721_contract):
@pytest.fixture
def subscription_manager_get_policy_zeroized_policy_struct_condition(
test_registry, agency
testerchain, test_registry
):
subscription_manager = ContractAgency.get_agent(
SubscriptionManagerAgent, registry=test_registry
@ -133,7 +121,7 @@ def subscription_manager_get_policy_zeroized_policy_struct_condition(
@pytest.fixture
def subscription_manager_is_active_policy_condition(test_registry, agency):
def subscription_manager_is_active_policy_condition(testerchain, test_registry):
subscription_manager = ContractAgency.get_agent(
SubscriptionManagerAgent,
registry=test_registry

View File

@ -325,7 +325,6 @@ def test_subscription_manager_get_policy_policy_struct_condition_evaluation(
def test_subscription_manager_get_policy_policy_struct_condition_key_tuple_evaluation(
testerchain,
agency,
test_registry,
idle_policy,
enacted_policy,
@ -445,7 +444,6 @@ def test_subscription_manager_get_policy_policy_struct_condition_key_tuple_evalu
def test_subscription_manager_get_policy_policy_struct_condition_index_and_value_context_var_evaluation(
testerchain,
agency,
test_registry,
idle_policy,
enacted_policy,
@ -499,7 +497,6 @@ def test_simple_compound_conditions_evaluation(testerchain, compound_timelock_li
"nucypher.policy.conditions.evm.get_context_value",
side_effect=_dont_validate_user_address,
)
@pytest.mark.usefixtures("agency")
def test_onchain_conditions_lingo_evaluation(
get_context_value_mock,
testerchain,

View File

@ -3,7 +3,7 @@ import pytest
from nucypher.blockchain.economics import EconomicsFactory
@pytest.mark.usefixtures('agency')
@pytest.mark.usefixtures('testerchain')
def test_retrieving_from_blockchain(application_economics, test_registry):
economics = EconomicsFactory.get_economics(registry=test_registry)
assert economics.pre_application_deployment_parameters == application_economics.pre_application_deployment_parameters

View File

@ -27,14 +27,14 @@ from tests.constants import (
MOCK_KEYSTORE_PATH,
NUMBER_OF_MOCK_KEYSTORE_ACCOUNTS,
)
from tests.mock.agents import MockContractAgency
from tests.mock.coordinator import MockCoordinatorAgent
from tests.mock.interfaces import MockBlockchain, mock_registry_source_manager
from tests.mock.io import MockStdinWrapper
@pytest.fixture(scope='function', autouse=True)
def mock_contract_agency(monkeypatch, module_mocker, application_economics):
from tests.mock.agents import MockContractAgency
monkeypatch.setattr(ContractAgency, 'get_agent', MockContractAgency.get_agent)
module_mocker.patch.object(EconomicsFactory, 'get_economics', return_value=application_economics)
mock_agency = MockContractAgency()
@ -80,6 +80,8 @@ def mock_adjudicator_agent(testerchain, application_economics, mock_contract_age
@pytest.fixture(scope="function", autouse=True)
def mock_coordinator_agent(testerchain, application_economics, mock_contract_agency):
from tests.mock.coordinator import MockCoordinatorAgent
mock_agent = MockCoordinatorAgent(blockchain=testerchain)
mock_contract_agency._MockContractAgency__agents[CoordinatorAgent] = mock_agent
yield mock_agent
@ -137,6 +139,8 @@ def mock_contract_agency(module_mocker, application_economics):
# Patch
module_mocker.patch.object(EconomicsFactory, 'get_economics', return_value=application_economics)
from tests.mock.agents import MockContractAgency
# Monkeypatch # TODO: Use better tooling for this monkeypatch?
get_agent = ContractAgency.get_agent
get_agent_by_name = ContractAgency.get_agent_by_contract_name

View File

@ -4,7 +4,6 @@ from nucypher.blockchain.economics import EconomicsFactory
from nucypher.blockchain.eth.agents import ContractAgency
from nucypher.crypto.powers import TransactingPower
from nucypher.network.nodes import Teacher
from tests.mock.agents import MockContractAgency
from tests.mock.interfaces import MockEthereumClient
@ -26,6 +25,8 @@ def mock_contract_agency(module_mocker, application_economics):
# Patch
module_mocker.patch.object(EconomicsFactory, 'get_economics', return_value=application_economics)
from tests.mock.agents import MockContractAgency
# Monkeypatch # TODO: Use better tooling for this monkeypatch?
get_agent = ContractAgency.get_agent
get_agent_by_name = ContractAgency.get_agent_by_contract_name

View File

@ -107,7 +107,7 @@ class TesterBlockchain(BlockchainInterface):
def ether_airdrop(self, amount: int) -> List[str]:
"""Airdrops ether from creator address to all other addresses!"""
coinbase, *addresses = self.accounts
coinbase, *addresses = self.client.accounts
tx_hashes = list()
for address in addresses:
tx = {'to': address, 'from': coinbase, 'value': amount, 'gasPrice': self.w3.eth.generate_gas_price()}