2018-11-22 18:29:57 +00:00
|
|
|
"""
|
|
|
|
This file is part of nucypher.
|
|
|
|
|
|
|
|
nucypher is free software: you can redistribute it and/or modify
|
2019-03-05 02:50:11 +00:00
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
2018-11-22 18:29:57 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
nucypher is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-03-05 02:50:11 +00:00
|
|
|
GNU Affero General Public License for more details.
|
2018-11-22 18:29:57 +00:00
|
|
|
|
2019-03-05 02:50:11 +00:00
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2018-11-22 18:29:57 +00:00
|
|
|
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
2018-12-02 23:40:46 +00:00
|
|
|
|
|
|
|
|
2018-11-25 20:45:59 +00:00
|
|
|
import contextlib
|
2019-12-05 02:53:05 +00:00
|
|
|
import glob
|
2019-01-31 02:58:50 +00:00
|
|
|
import json
|
2019-01-20 23:45:06 +00:00
|
|
|
import os
|
2019-04-30 18:04:37 +00:00
|
|
|
import shutil
|
2018-11-22 18:29:57 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
from click.testing import CliRunner
|
|
|
|
|
2019-09-19 11:57:28 +00:00
|
|
|
from nucypher.blockchain.eth.actors import ContractAdministrator
|
2019-09-20 05:24:51 +00:00
|
|
|
from nucypher.blockchain.eth.registry import AllocationRegistry, InMemoryContractRegistry
|
2019-09-19 20:04:22 +00:00
|
|
|
from nucypher.config.characters import UrsulaConfiguration, StakeHolderConfiguration
|
2019-03-20 03:38:29 +00:00
|
|
|
from nucypher.utilities.sandbox.constants import (
|
2019-09-19 11:57:28 +00:00
|
|
|
MOCK_ALLOCATION_REGISTRY_FILEPATH,
|
2019-03-20 03:38:29 +00:00
|
|
|
MOCK_CUSTOM_INSTALLATION_PATH,
|
2019-10-16 17:28:35 +00:00
|
|
|
MOCK_CUSTOM_INSTALLATION_PATH_2,
|
|
|
|
INSECURE_DEVELOPMENT_PASSWORD,
|
2019-03-20 03:38:29 +00:00
|
|
|
MOCK_ALLOCATION_INFILE,
|
|
|
|
MOCK_REGISTRY_FILEPATH,
|
2019-06-04 11:44:52 +00:00
|
|
|
ONE_YEAR_IN_SECONDS)
|
2018-11-25 20:45:59 +00:00
|
|
|
|
2018-11-22 18:29:57 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
|
|
def click_runner():
|
|
|
|
runner = CliRunner()
|
|
|
|
yield runner
|
2018-11-25 20:45:59 +00:00
|
|
|
|
|
|
|
|
2019-04-30 18:04:37 +00:00
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
def deploy_user_input():
|
|
|
|
account_index = '0\n'
|
|
|
|
yes = 'Y\n'
|
|
|
|
deployment_secret = f'{INSECURE_DEVELOPMENT_PASSWORD}\n'
|
2019-05-31 19:06:04 +00:00
|
|
|
user_input = account_index + yes + (deployment_secret * 8) + 'DEPLOY'
|
2019-04-30 18:04:37 +00:00
|
|
|
return user_input
|
|
|
|
|
|
|
|
|
2019-06-11 21:36:36 +00:00
|
|
|
@pytest.fixture(scope='session')
|
2018-12-08 21:06:40 +00:00
|
|
|
def nominal_federated_configuration_fields():
|
|
|
|
config = UrsulaConfiguration(dev_mode=True, federated_only=True)
|
2019-06-08 18:57:10 +00:00
|
|
|
config_fields = config.static_payload()
|
2018-11-25 20:45:59 +00:00
|
|
|
yield tuple(config_fields.keys())
|
|
|
|
del config
|
|
|
|
|
|
|
|
|
2019-01-31 02:58:50 +00:00
|
|
|
@pytest.fixture(scope='module')
|
2019-03-20 03:38:29 +00:00
|
|
|
def mock_allocation_infile(testerchain, token_economics):
|
2019-04-22 20:15:40 +00:00
|
|
|
accounts = testerchain.unassigned_accounts
|
2019-08-21 12:11:39 +00:00
|
|
|
allocation_data = [{'beneficiary_address': addr,
|
2019-09-19 11:57:28 +00:00
|
|
|
'amount': 2 * token_economics.minimum_allowed_locked,
|
2019-08-21 12:11:39 +00:00
|
|
|
'duration_seconds': ONE_YEAR_IN_SECONDS}
|
2019-04-22 20:15:40 +00:00
|
|
|
for addr in accounts]
|
|
|
|
|
2019-01-31 02:58:50 +00:00
|
|
|
with open(MOCK_ALLOCATION_INFILE, 'w') as file:
|
|
|
|
file.write(json.dumps(allocation_data))
|
2019-04-22 20:15:40 +00:00
|
|
|
|
2019-09-19 11:57:28 +00:00
|
|
|
yield MOCK_ALLOCATION_INFILE
|
|
|
|
if os.path.isfile(MOCK_ALLOCATION_INFILE):
|
|
|
|
os.remove(MOCK_ALLOCATION_INFILE)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
|
|
def mock_allocation_registry(testerchain, test_registry, mock_allocation_infile):
|
|
|
|
admin = ContractAdministrator(registry=test_registry,
|
|
|
|
client_password=INSECURE_DEVELOPMENT_PASSWORD,
|
|
|
|
deployer_address=testerchain.etherbase_account)
|
|
|
|
|
2019-12-05 02:53:05 +00:00
|
|
|
if os.path.isfile(MOCK_ALLOCATION_REGISTRY_FILEPATH):
|
|
|
|
os.remove(MOCK_ALLOCATION_REGISTRY_FILEPATH)
|
|
|
|
|
2019-09-19 11:57:28 +00:00
|
|
|
admin.deploy_beneficiaries_from_file(allocation_data_filepath=mock_allocation_infile,
|
|
|
|
allocation_outfile=MOCK_ALLOCATION_REGISTRY_FILEPATH)
|
|
|
|
|
|
|
|
allocation_registry = AllocationRegistry(filepath=MOCK_ALLOCATION_REGISTRY_FILEPATH)
|
2019-12-05 02:53:05 +00:00
|
|
|
|
2019-09-19 11:57:28 +00:00
|
|
|
yield allocation_registry
|
2019-12-05 02:53:05 +00:00
|
|
|
|
|
|
|
# Cleanup Allocation Stuff
|
2019-09-19 11:57:28 +00:00
|
|
|
if os.path.isfile(MOCK_ALLOCATION_REGISTRY_FILEPATH):
|
|
|
|
os.remove(MOCK_ALLOCATION_REGISTRY_FILEPATH)
|
2019-01-31 02:58:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='module', autouse=True)
|
2019-09-20 05:24:51 +00:00
|
|
|
def temp_registry(testerchain, test_registry, agency):
|
|
|
|
registry_filepath = MOCK_REGISTRY_FILEPATH
|
|
|
|
# Disable registry fetching, use the mock one instead
|
|
|
|
InMemoryContractRegistry.download_latest_publication = lambda: registry_filepath
|
|
|
|
filepath = test_registry.commit(filepath=registry_filepath, overwrite=True)
|
2019-08-14 02:17:08 +00:00
|
|
|
assert filepath == MOCK_REGISTRY_FILEPATH
|
|
|
|
assert os.path.isfile(MOCK_REGISTRY_FILEPATH)
|
2019-09-20 05:24:51 +00:00
|
|
|
yield registry_filepath
|
|
|
|
if os.path.exists(registry_filepath):
|
|
|
|
os.remove(registry_filepath)
|
2019-01-31 02:58:50 +00:00
|
|
|
|
|
|
|
|
2018-11-25 20:45:59 +00:00
|
|
|
@pytest.fixture(scope='module')
|
|
|
|
def custom_filepath():
|
|
|
|
_custom_filepath = MOCK_CUSTOM_INSTALLATION_PATH
|
|
|
|
with contextlib.suppress(FileNotFoundError):
|
|
|
|
shutil.rmtree(_custom_filepath, ignore_errors=True)
|
2018-11-25 21:51:20 +00:00
|
|
|
try:
|
|
|
|
yield _custom_filepath
|
|
|
|
finally:
|
|
|
|
with contextlib.suppress(FileNotFoundError):
|
|
|
|
shutil.rmtree(_custom_filepath, ignore_errors=True)
|
2019-02-26 04:46:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
|
|
def custom_filepath_2():
|
|
|
|
_custom_filepath = MOCK_CUSTOM_INSTALLATION_PATH_2
|
|
|
|
with contextlib.suppress(FileNotFoundError):
|
|
|
|
shutil.rmtree(_custom_filepath, ignore_errors=True)
|
|
|
|
try:
|
|
|
|
yield _custom_filepath
|
|
|
|
finally:
|
|
|
|
with contextlib.suppress(FileNotFoundError):
|
|
|
|
shutil.rmtree(_custom_filepath, ignore_errors=True)
|
2019-09-19 20:04:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
|
|
def worker_configuration_file_location(custom_filepath):
|
|
|
|
_configuration_file_location = os.path.join(MOCK_CUSTOM_INSTALLATION_PATH,
|
|
|
|
UrsulaConfiguration.generate_filename())
|
|
|
|
return _configuration_file_location
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
|
|
def stakeholder_configuration_file_location(custom_filepath):
|
|
|
|
_configuration_file_location = os.path.join(MOCK_CUSTOM_INSTALLATION_PATH,
|
|
|
|
StakeHolderConfiguration.generate_filename())
|
|
|
|
return _configuration_file_location
|