mirror of https://github.com/nucypher/nucypher.git
Merge pull request #2993 from KPrasch/development
[WIP] Export reusable pytest fixtures and cleanuppull/3001/head
commit
785a59663b
|
@ -7,7 +7,7 @@ concurrency:
|
|||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
contract-tests:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
@ -29,4 +29,4 @@ jobs:
|
|||
run: python ./scripts/installation/install_solc.py
|
||||
|
||||
- name: Run Contract tests
|
||||
run: pytest tests/contracts
|
||||
run: python -m pytest tests/contracts
|
||||
|
|
|
@ -34,40 +34,40 @@ jobs:
|
|||
run: python -c "import nucypher; print(nucypher.__version__)"
|
||||
|
||||
- name: Unit Tests
|
||||
run: pytest tests/unit
|
||||
run: python -m pytest tests/unit
|
||||
|
||||
- name: Integration Tests
|
||||
run: pytest tests/integration
|
||||
run: python -m pytest tests/integration
|
||||
|
||||
- name: Agents Tests
|
||||
run: pytest tests/acceptance/blockchain/agents
|
||||
run: python -m pytest tests/acceptance/blockchain/agents
|
||||
|
||||
- name: Actors Tests
|
||||
run: pytest tests/acceptance/blockchain/actors
|
||||
run: python -m pytest tests/acceptance/blockchain/actors
|
||||
|
||||
- name: Deployers Tests
|
||||
run: pytest tests/acceptance/blockchain/deployers
|
||||
run: python -m pytest tests/acceptance/blockchain/deployers
|
||||
|
||||
- name: Interfaces Tests
|
||||
run: pytest tests/acceptance/blockchain/interfaces
|
||||
run: python -m pytest tests/acceptance/blockchain/interfaces
|
||||
|
||||
- name: Conditions Tests
|
||||
run: pytest tests/acceptance/blockchain/conditions
|
||||
run: python -m pytest tests/acceptance/blockchain/conditions
|
||||
|
||||
- name: Characters Tests
|
||||
run: pytest tests/acceptance/characters
|
||||
run: python -m pytest tests/acceptance/characters
|
||||
|
||||
- name: Node Discovery Tests
|
||||
run: pytest tests/acceptance/learning
|
||||
run: python -m pytest tests/acceptance/learning
|
||||
|
||||
- name: Network Tests
|
||||
run: pytest tests/acceptance/network
|
||||
run: python -m pytest tests/acceptance/network
|
||||
|
||||
- name: Utility Tests
|
||||
run: pytest tests/acceptance/utilities
|
||||
run: python -m pytest tests/acceptance/utilities
|
||||
|
||||
- name: Check CLI Entrypoint
|
||||
run: nucypher --help
|
||||
|
||||
- name: CLI Tests
|
||||
run: pytest tests/acceptance/cli
|
||||
run: python -m pytest tests/acceptance/cli
|
||||
|
|
30
setup.py
30
setup.py
|
@ -22,11 +22,11 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import sys
|
||||
from setuptools import find_packages, setup
|
||||
from setuptools.command.develop import develop
|
||||
from setuptools.command.install import install
|
||||
|
@ -122,10 +122,6 @@ def read_requirements(path):
|
|||
INSTALL_REQUIRES = read_requirements('requirements.txt')
|
||||
DEV_REQUIRES = read_requirements('dev-requirements.txt')
|
||||
|
||||
# Direct dependencies are not supported on PyPI, instead use `pip -r docs-requirements`
|
||||
# https://github.com/pypa/twine/issues/726
|
||||
# DOC_REQUIRES = read_requirements('docs-requirements.txt')
|
||||
|
||||
BENCHMARK_REQUIRES = [
|
||||
'pytest-benchmark'
|
||||
]
|
||||
|
@ -138,21 +134,14 @@ DEPLOY_REQUIRES = [
|
|||
]
|
||||
|
||||
URSULA_REQUIRES = ['prometheus_client', 'sentry-sdk'] # TODO: Consider renaming to 'monitor', etc.
|
||||
ALICE_REQUIRES = ['qrcode']
|
||||
BOB_REQUIRES = ['qrcode']
|
||||
|
||||
EXTRAS = {
|
||||
|
||||
# Admin
|
||||
'dev': DEV_REQUIRES + URSULA_REQUIRES + ALICE_REQUIRES,
|
||||
'dev': DEV_REQUIRES + URSULA_REQUIRES,
|
||||
'benchmark': DEV_REQUIRES + BENCHMARK_REQUIRES,
|
||||
'deploy': DEPLOY_REQUIRES,
|
||||
# 'docs': DOC_REQUIRES,
|
||||
|
||||
# User
|
||||
'ursula': URSULA_REQUIRES,
|
||||
'alice': ALICE_REQUIRES,
|
||||
'bob': BOB_REQUIRES,
|
||||
}
|
||||
|
||||
|
||||
|
@ -164,15 +153,20 @@ setup(
|
|||
extras_require=EXTRAS,
|
||||
|
||||
# Package Data
|
||||
packages=find_packages(exclude=["tests", "scripts"]),
|
||||
packages=find_packages(exclude=["scripts"]),
|
||||
include_package_data=True,
|
||||
zip_safe=False,
|
||||
|
||||
# Entry Points
|
||||
entry_points={'console_scripts': [
|
||||
'nucypher = nucypher.cli.main:nucypher_cli',
|
||||
'nucypher-deploy = nucypher.cli.commands.deploy:deploy',
|
||||
]},
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'nucypher = nucypher.cli.main:nucypher_cli',
|
||||
'nucypher-deploy = nucypher.cli.commands.deploy:deploy'
|
||||
],
|
||||
'pytest11': [
|
||||
"pytest-nucypher = tests.fixtures"
|
||||
]
|
||||
},
|
||||
|
||||
# setup.py commands
|
||||
cmdclass={
|
||||
|
|
|
@ -15,6 +15,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
import pytest
|
||||
|
@ -76,8 +77,9 @@ def monkeysession():
|
|||
# Pytest configuration
|
||||
#
|
||||
|
||||
|
||||
pytest_plugins = [
|
||||
'tests.fixtures', # Includes external fixtures module
|
||||
'pytest-nucypher', # Includes external fixtures module via plugin
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -15,16 +15,11 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from bisect import bisect
|
||||
|
||||
import pytest
|
||||
from eth_tester.exceptions import TransactionFailed
|
||||
from web3 import Web3
|
||||
from web3.contract import Contract
|
||||
|
||||
from nucypher.blockchain.eth.constants import NULL_ADDRESS
|
||||
from nucypher.blockchain.eth.token import NU
|
||||
from nucypher.utilities.ethereum import get_array_data_location, get_mapping_entry_location, to_bytes32
|
||||
from tests.contracts.main.staking_escrow.conftest import TOTAL_SUPPLY
|
||||
|
||||
|
||||
|
|
|
@ -700,69 +700,6 @@ def funded_blockchain(testerchain, agency, application_economics, test_registry)
|
|||
yield testerchain, deployer_address
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def stakeholder_config_file_location():
|
||||
path = Path('/', 'tmp', 'nucypher-test-stakeholder.json')
|
||||
if path.exists():
|
||||
path.unlink()
|
||||
yield path
|
||||
if path.exists():
|
||||
path.unlink()
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def software_stakeholder(testerchain, agency, stakeholder_config_file_location, test_registry):
|
||||
token_agent = ContractAgency.get_agent(NucypherTokenAgent, registry=test_registry)
|
||||
|
||||
# Setup
|
||||
path = stakeholder_config_file_location
|
||||
if path.exists():
|
||||
path.unlink()
|
||||
|
||||
# 0xaAa482c790b4301bE18D75A0D1B11B2ACBEF798B
|
||||
stakeholder_private_key = '255f64a948eeb1595b8a2d1e76740f4683eca1c8f1433d13293db9b6e27676cc'
|
||||
address = testerchain.provider.ethereum_tester.add_account(private_key=stakeholder_private_key,
|
||||
password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
||||
testerchain.provider.ethereum_tester.unlock_account(account=address, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
||||
tx = {'to': address,
|
||||
'from': testerchain.etherbase_account,
|
||||
'value': Web3.to_wei('1', 'ether')}
|
||||
|
||||
txhash = testerchain.client.w3.eth.send_transaction(tx)
|
||||
_receipt = testerchain.wait_for_receipt(txhash)
|
||||
|
||||
# Mock TransactingPower consumption (Etherbase)
|
||||
transacting_power = TransactingPower(account=testerchain.etherbase_account,
|
||||
signer=Web3Signer(testerchain.client),
|
||||
password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
||||
token_agent.transfer(amount=NU(200_000, 'NU').to_units(),
|
||||
transacting_power=transacting_power,
|
||||
target_address=address)
|
||||
|
||||
# Create stakeholder from on-chain values given accounts over a web3 provider
|
||||
signer = Web3Signer(testerchain.client)
|
||||
signer.unlock_account(account=address, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
stakeholder = StakeHolder(registry=test_registry,
|
||||
domain=TEMPORARY_DOMAIN,
|
||||
signer=signer,
|
||||
initial_address=address)
|
||||
|
||||
# Teardown
|
||||
yield stakeholder
|
||||
if path.exists():
|
||||
path.unlink()
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def stakeholder_configuration(testerchain, agency_local_registry):
|
||||
config = StakeHolderConfiguration(eth_provider_uri=testerchain.eth_provider_uri,
|
||||
registry_filepath=agency_local_registry.filepath)
|
||||
return config
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def manual_operator(testerchain):
|
||||
worker_private_key = os.urandom(32).hex()
|
||||
|
@ -919,26 +856,6 @@ def nominal_federated_configuration_fields():
|
|||
del config
|
||||
|
||||
|
||||
# TODO: Not used?
|
||||
@pytest.fixture(scope='module')
|
||||
def mock_allocation_infile(testerchain, application_economics, get_random_checksum_address):
|
||||
accounts = [get_random_checksum_address() for _ in range(10)]
|
||||
# accounts = testerchain.unassigned_accounts
|
||||
allocation_data = list()
|
||||
amount = 2 * application_economics.min_authorization
|
||||
min_periods = application_economics.min_operator_seconds
|
||||
for account in accounts:
|
||||
substake = [{'checksum_address': account, 'amount': amount, 'lock_periods': min_periods + i} for i in range(24)]
|
||||
allocation_data.extend(substake)
|
||||
|
||||
with open(MOCK_ALLOCATION_INFILE, 'w') as file:
|
||||
file.write(json.dumps(allocation_data))
|
||||
|
||||
yield MOCK_ALLOCATION_INFILE
|
||||
if MOCK_ALLOCATION_INFILE.is_file():
|
||||
MOCK_ALLOCATION_INFILE.unlink()
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def new_local_registry():
|
||||
filename = f'{BASE_TEMP_PREFIX}mock-empty-registry-{datetime.now().strftime(DATETIME_FORMAT)}.json'
|
||||
|
@ -978,12 +895,6 @@ def worker_configuration_file_location(custom_filepath) -> Path:
|
|||
return _configuration_file_location
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def stakeholder_configuration_file_location(custom_filepath) -> Path:
|
||||
_configuration_file_location = MOCK_CUSTOM_INSTALLATION_PATH / StakeHolderConfiguration.generate_filename()
|
||||
return _configuration_file_location
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_teacher_nodes(mocker):
|
||||
mock_nodes = tuple(u.rest_url() for u in MOCK_KNOWN_URSULAS_CACHE.values())[0:2]
|
||||
|
@ -1036,3 +947,8 @@ def random_context():
|
|||
}
|
||||
|
||||
return context
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def mock_rest_middleware():
|
||||
return MockRestMiddleware()
|
||||
|
|
Loading…
Reference in New Issue