2020-08-19 00:40:26 +00:00
|
|
|
import pytest
|
|
|
|
|
2022-12-07 11:14:59 +00:00
|
|
|
from nucypher.blockchain.economics import EconomicsFactory
|
2023-04-14 15:25:54 +00:00
|
|
|
from nucypher.blockchain.eth.agents import ContractAgency
|
2022-12-07 11:14:59 +00:00
|
|
|
from nucypher.crypto.powers import TransactingPower
|
|
|
|
from nucypher.network.nodes import Teacher
|
|
|
|
from tests.mock.agents import MockContractAgency
|
2020-08-19 00:40:26 +00:00
|
|
|
from tests.mock.interfaces import MockEthereumClient
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
def mock_ethereum_client(mocker):
|
|
|
|
web3_mock = mocker.Mock()
|
|
|
|
mock_client = MockEthereumClient(w3=web3_mock)
|
|
|
|
return mock_client
|
2022-12-07 11:14:59 +00:00
|
|
|
|
|
|
|
|
2022-12-01 10:19:22 +00:00
|
|
|
@pytest.fixture(scope='module', autouse=True)
|
2022-12-07 11:14:59 +00:00
|
|
|
def mock_transacting_power(module_mocker):
|
2022-12-01 10:19:22 +00:00
|
|
|
module_mocker.patch.object(TransactingPower, 'unlock')
|
2022-12-07 11:14:59 +00:00
|
|
|
|
|
|
|
|
2022-12-01 10:19:22 +00:00
|
|
|
@pytest.fixture(scope='module', autouse=True)
|
2022-12-07 11:14:59 +00:00
|
|
|
def mock_contract_agency(module_mocker, application_economics):
|
|
|
|
|
|
|
|
# Patch
|
2022-12-01 10:19:22 +00:00
|
|
|
module_mocker.patch.object(EconomicsFactory, 'get_economics', return_value=application_economics)
|
2022-12-07 11:14:59 +00:00
|
|
|
|
|
|
|
# Monkeypatch # TODO: Use better tooling for this monkeypatch?
|
|
|
|
get_agent = ContractAgency.get_agent
|
|
|
|
get_agent_by_name = ContractAgency.get_agent_by_contract_name
|
|
|
|
ContractAgency.get_agent = MockContractAgency.get_agent
|
2022-12-01 10:19:22 +00:00
|
|
|
ContractAgency.get_agent_by_contract_name = MockContractAgency.get_agent_by_contract_name
|
2022-12-07 11:14:59 +00:00
|
|
|
|
|
|
|
# Test
|
|
|
|
yield MockContractAgency()
|
|
|
|
|
|
|
|
# Restore the monkey patching
|
|
|
|
ContractAgency.get_agent = get_agent
|
|
|
|
ContractAgency.get_agent_by_contract_name = get_agent_by_name
|
|
|
|
|
|
|
|
|
2022-12-01 10:19:22 +00:00
|
|
|
@pytest.fixture(scope='session', autouse=True)
|
2022-12-07 11:14:59 +00:00
|
|
|
def mock_operator_bonding(session_mocker):
|
2022-12-01 10:19:22 +00:00
|
|
|
session_mocker.patch.object(Teacher, '_operator_is_bonded', autospec=True)
|