handle integration and unit mocking of ad-hoc ursula account bonding.

pull/3213/head
Kieran Prasch 2023-09-12 18:25:32 +02:00
parent 570e3574b3
commit 4fc0176a96
6 changed files with 23 additions and 7 deletions

View File

@ -19,6 +19,7 @@ from web3 import Web3
import tests
from nucypher.blockchain.economics import Economics
from nucypher.blockchain.eth.actors import Operator
from nucypher.blockchain.eth.clients import EthereumClient
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.registry import LocalContractRegistry
@ -341,6 +342,11 @@ def light_ursula(temp_dir_path, test_registry_source_manager, random_account, mo
payment_method = SubscriptionManagerPayment(
eth_provider=MOCK_ETH_PROVIDER_URI, network=TEMPORARY_DOMAIN
)
mocker.patch.object(
Operator, "get_staking_provider_address", return_value=random_account.address
)
ursula = Ursula(
rest_host=LOOPBACK_ADDRESS,
rest_port=select_test_port(),

View File

@ -1,5 +1,3 @@
import json
import secrets
from pathlib import Path
@ -30,7 +28,9 @@ def mock_account_password_keystore(tmp_path_factory):
return account, password, keystore
@pytest.mark.usefixtures("test_registry_source_manager")
@pytest.mark.usefixtures(
"test_registry_source_manager", "monkeypatch_get_staking_provider_from_operator"
)
def test_ursula_init_with_local_keystore_signer(
click_runner, temp_dir_path, mocker, testerchain, mock_account_password_keystore
):

View File

@ -37,6 +37,7 @@ all_configurations = tuple(
)
@pytest.mark.usefixtures("monkeypatch_get_staking_provider_from_operator")
@pytest.mark.parametrize("character,configuration", characters_and_configurations)
def test_development_character_configurations(
character, configuration, test_registry_source_manager, mocker, testerchain

View File

@ -246,7 +246,6 @@ def mock_transacting_power(module_mocker, monkeymodule):
@pytest.fixture(scope="module", autouse=True)
def staking_providers(testerchain, test_registry, monkeymodule):
def faked(self, *args, **kwargs):
return testerchain.stake_providers_accounts[testerchain.ursulas_accounts.index(self.transacting_power.account)]
@ -254,6 +253,15 @@ def staking_providers(testerchain, test_registry, monkeymodule):
return testerchain.stake_providers_accounts
@pytest.fixture(scope="module")
def monkeypatch_get_staking_provider_from_operator(monkeymodule):
monkeymodule.setattr(
Operator,
"get_staking_provider_address",
lambda self: self.transacting_power.account,
)
@pytest.fixture(scope="session", autouse=True)
def mock_condition_blockchains(session_mocker):
"""adds testerchain's chain ID to permitted conditional chains"""

View File

@ -1,9 +1,8 @@
import contextlib
import pytest
import time
import maya
import pytest
from nucypher_core.umbral import SecretKey, Signer
from nucypher.characters.lawful import Ursula
@ -15,7 +14,7 @@ from tests.mock.performance_mocks import (
mock_message_verification,
mock_metadata_validation,
mock_secret_source,
mock_verify_node
mock_verify_node,
)
from tests.utils.ursula import MOCK_KNOWN_URSULAS_CACHE
@ -38,6 +37,7 @@ performance bottlenecks.
"""
@pytest.mark.usefixtures("monkeypatch_get_staking_provider_from_operator")
def test_alice_can_learn_about_a_whole_bunch_of_ursulas(highperf_mocked_alice, test_registry_source_manager):
# During the fixture execution, Alice verified one node.
# TODO: Consider changing this - #1449

View File

@ -41,6 +41,7 @@ def test_alice_finds_ursula_via_rest(alice, ursulas):
assert ursula in alice.known_nodes
@pytest.mark.usefixtures("monkeypatch_get_staking_provider_from_operator")
def test_vladimir_illegal_interface_key_does_not_propagate(ursulas, test_registry_source_manager):
"""
Although Ursulas propagate each other's interface information, as demonstrated above,