Adapt tests to new registry fetching; extract common fixture.

pull/1480/head
David Núñez 2019-11-27 20:08:33 +01:00
parent 2e21c26b18
commit da7a572549
3 changed files with 25 additions and 35 deletions

View File

@ -16,7 +16,6 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
""" """
import json import json
import os
import pytest import pytest
from nucypher.blockchain.eth.deployers import PreallocationEscrowDeployer from nucypher.blockchain.eth.deployers import PreallocationEscrowDeployer
@ -25,22 +24,8 @@ from nucypher.blockchain.eth.registry import LocalContractRegistry, IndividualAl
@pytest.fixture(autouse=True, scope='module') @pytest.fixture(autouse=True, scope='module')
def patch_individual_allocation_registry_fetch_latest_publication(agency, test_registry): def patch_individual_allocation_fetch_latest_publication(_patch_individual_allocation_fetch_latest_publication):
empty_allocation_escrow_deployer = PreallocationEscrowDeployer(registry=test_registry) pass
allocation_contract_abi = empty_allocation_escrow_deployer.get_contract_abi()
allocation_template = {
"BENEFICIARY_ADDRESS": ["ALLOCATION_CONTRACT_ADDRESS", allocation_contract_abi]
}
new_fetch_result = json.dumps(allocation_template).encode()
original_fetch = IndividualAllocationRegistry.fetch_latest_publication
def new_fetch(*args, **kwargs):
return new_fetch_result
IndividualAllocationRegistry.fetch_latest_publication = new_fetch
yield
IndividualAllocationRegistry.fetch_latest_publication = original_fetch
def test_contract_registry(tempfile_path): def test_contract_registry(tempfile_path):

View File

@ -53,22 +53,8 @@ from nucypher.utilities.sandbox.middleware import MockRestMiddleware
@pytest.fixture(autouse=True, scope='module') @pytest.fixture(autouse=True, scope='module')
def patch_fetch_latest_publication(test_registry): def patch_individual_allocation_fetch_latest_publication(_patch_individual_allocation_fetch_latest_publication):
empty_allocation_escrow_deployer = PreallocationEscrowDeployer(registry=test_registry) pass
allocation_contract_abi = empty_allocation_escrow_deployer.get_contract_abi()
allocation_template = {
"BENEFICIARY_ADDRESS": ["ALLOCATION_CONTRACT_ADDRESS", allocation_contract_abi]
}
new_fetch_result = json.dumps(allocation_template).encode()
original_fetch = IndividualAllocationRegistry.fetch_latest_publication
def new_fetch(*args, **kwargs):
return new_fetch_result
IndividualAllocationRegistry.fetch_latest_publication = new_fetch
yield
IndividualAllocationRegistry.fetch_latest_publication = original_fetch
@pytest.fixture(scope='module') @pytest.fixture(scope='module')

View File

@ -40,9 +40,11 @@ from nucypher.blockchain.eth.clients import NuCypherGethDevProcess
from nucypher.blockchain.eth.deployers import (NucypherTokenDeployer, from nucypher.blockchain.eth.deployers import (NucypherTokenDeployer,
StakingEscrowDeployer, StakingEscrowDeployer,
PolicyManagerDeployer, PolicyManagerDeployer,
AdjudicatorDeployer, StakingInterfaceDeployer) AdjudicatorDeployer,
StakingInterfaceDeployer,
PreallocationEscrowDeployer)
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.registry import InMemoryContractRegistry from nucypher.blockchain.eth.registry import InMemoryContractRegistry, GithubRegistrySource
from nucypher.blockchain.eth.sol.compile import SolidityCompiler from nucypher.blockchain.eth.sol.compile import SolidityCompiler
from nucypher.blockchain.eth.token import NU from nucypher.blockchain.eth.token import NU
from nucypher.characters.lawful import Enrico, Bob from nucypher.characters.lawful import Enrico, Bob
@ -823,3 +825,20 @@ def get_random_checksum_address():
checksum_address = to_checksum_address(canonical_address) checksum_address = to_checksum_address(canonical_address)
return checksum_address return checksum_address
return _get_random_checksum_address return _get_random_checksum_address
@pytest.fixture(scope='module')
def _patch_individual_allocation_fetch_latest_publication(agency, test_registry):
empty_allocation_escrow_deployer = PreallocationEscrowDeployer(registry=test_registry)
allocation_contract_abi = empty_allocation_escrow_deployer.get_contract_abi()
allocation_template = {
"BENEFICIARY_ADDRESS": ["ALLOCATION_CONTRACT_ADDRESS", allocation_contract_abi]
}
def new_fetch(*args, **kwargs):
return json.dumps(allocation_template).encode()
original_fetch = GithubRegistrySource.fetch_latest_publication
GithubRegistrySource.fetch_latest_publication = new_fetch
yield
GithubRegistrySource.fetch_latest_publication = original_fetch