2019-09-20 01:11:19 +00:00
|
|
|
import os
|
|
|
|
|
2019-09-01 04:01:37 +00:00
|
|
|
from nucypher.blockchain.eth.agents import (
|
|
|
|
PolicyManagerAgent,
|
|
|
|
StakingEscrowAgent,
|
|
|
|
AdjudicatorAgent,
|
2019-08-31 23:16:01 +00:00
|
|
|
ContractAgency
|
2019-09-01 04:01:37 +00:00
|
|
|
)
|
2019-07-26 16:38:01 +00:00
|
|
|
from nucypher.blockchain.eth.constants import STAKING_ESCROW_CONTRACT_NAME
|
2019-09-20 00:23:48 +00:00
|
|
|
from nucypher.blockchain.eth.deployers import StakingEscrowDeployer
|
2019-10-03 15:06:55 +00:00
|
|
|
from nucypher.blockchain.eth.registry import LocalContractRegistry
|
2020-01-14 22:52:50 +00:00
|
|
|
from nucypher.cli.commands.deploy import deploy
|
2019-09-20 01:11:19 +00:00
|
|
|
from nucypher.utilities.sandbox.constants import (
|
|
|
|
TEST_PROVIDER_URI,
|
|
|
|
MOCK_REGISTRY_FILEPATH,
|
|
|
|
INSECURE_DEVELOPMENT_PASSWORD,
|
|
|
|
INSECURE_DEPLOYMENT_SECRET_PLAINTEXT
|
|
|
|
)
|
2019-07-26 16:38:01 +00:00
|
|
|
|
2019-09-20 05:24:51 +00:00
|
|
|
ALTERNATE_REGISTRY_FILEPATH = '/tmp/nucypher-test-registry-alternate.json'
|
2019-07-28 01:46:19 +00:00
|
|
|
|
|
|
|
|
2019-09-01 04:01:37 +00:00
|
|
|
def test_nucypher_deploy_inspect_no_deployments(click_runner, testerchain):
|
2019-07-28 01:46:19 +00:00
|
|
|
|
2019-09-01 04:01:37 +00:00
|
|
|
status_command = ('inspect',
|
2019-07-28 01:46:19 +00:00
|
|
|
'--provider', TEST_PROVIDER_URI,
|
2019-09-20 05:24:51 +00:00
|
|
|
'--registry-infile', MOCK_REGISTRY_FILEPATH,
|
2019-07-28 01:46:19 +00:00
|
|
|
'--poa')
|
|
|
|
|
|
|
|
result = click_runner.invoke(deploy, status_command, catch_exceptions=False)
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
|
2019-09-17 19:16:42 +00:00
|
|
|
def test_nucypher_deploy_inspect_fully_deployed(click_runner, testerchain, agency):
|
2019-07-28 01:46:19 +00:00
|
|
|
|
2019-09-20 05:24:51 +00:00
|
|
|
local_registry = LocalContractRegistry(filepath=MOCK_REGISTRY_FILEPATH)
|
2019-09-17 19:16:42 +00:00
|
|
|
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=local_registry)
|
|
|
|
policy_agent = ContractAgency.get_agent(PolicyManagerAgent, registry=local_registry)
|
|
|
|
adjudicator_agent = ContractAgency.get_agent(AdjudicatorAgent, registry=local_registry)
|
2019-09-01 04:01:37 +00:00
|
|
|
|
|
|
|
status_command = ('inspect',
|
|
|
|
'--registry-infile', MOCK_REGISTRY_FILEPATH,
|
2019-07-28 01:46:19 +00:00
|
|
|
'--provider', TEST_PROVIDER_URI,
|
|
|
|
'--poa')
|
|
|
|
|
2019-09-01 04:01:37 +00:00
|
|
|
result = click_runner.invoke(deploy,
|
|
|
|
status_command,
|
|
|
|
catch_exceptions=False)
|
2019-07-28 01:46:19 +00:00
|
|
|
assert result.exit_code == 0
|
2019-09-01 04:01:37 +00:00
|
|
|
assert staking_agent.owner in result.output
|
|
|
|
assert policy_agent.owner in result.output
|
|
|
|
assert adjudicator_agent.owner in result.output
|
|
|
|
|
|
|
|
|
2019-09-20 01:11:19 +00:00
|
|
|
def test_transfer_ownership(click_runner, testerchain, agency, test_registry):
|
2019-07-28 01:46:19 +00:00
|
|
|
|
2019-09-20 05:24:51 +00:00
|
|
|
local_registry = LocalContractRegistry(filepath=MOCK_REGISTRY_FILEPATH)
|
2019-09-17 19:16:42 +00:00
|
|
|
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=local_registry)
|
|
|
|
policy_agent = ContractAgency.get_agent(PolicyManagerAgent, registry=local_registry)
|
|
|
|
adjudicator_agent = ContractAgency.get_agent(AdjudicatorAgent, registry=local_registry)
|
2019-07-28 01:46:19 +00:00
|
|
|
|
2019-09-01 04:01:37 +00:00
|
|
|
assert staking_agent.owner == testerchain.etherbase_account
|
|
|
|
assert policy_agent.owner == testerchain.etherbase_account
|
|
|
|
assert adjudicator_agent.owner == testerchain.etherbase_account
|
2019-07-26 16:38:01 +00:00
|
|
|
|
|
|
|
maclane = testerchain.unassigned_accounts[0]
|
2019-07-28 01:46:19 +00:00
|
|
|
|
2019-07-26 16:38:01 +00:00
|
|
|
ownership_command = ('transfer-ownership',
|
2019-09-20 01:11:19 +00:00
|
|
|
'--registry-infile', MOCK_REGISTRY_FILEPATH,
|
2019-07-28 01:46:19 +00:00
|
|
|
'--provider', TEST_PROVIDER_URI,
|
2019-07-26 16:38:01 +00:00
|
|
|
'--target-address', maclane,
|
|
|
|
'--poa')
|
|
|
|
|
|
|
|
account_index = '0\n'
|
|
|
|
yes = 'Y\n'
|
2019-09-01 04:01:37 +00:00
|
|
|
user_input = account_index + yes + yes
|
|
|
|
|
2019-07-26 16:38:01 +00:00
|
|
|
result = click_runner.invoke(deploy,
|
|
|
|
ownership_command,
|
|
|
|
input=user_input,
|
|
|
|
catch_exceptions=False)
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
2019-09-01 04:01:37 +00:00
|
|
|
assert staking_agent.owner == maclane
|
|
|
|
assert policy_agent.owner == maclane
|
|
|
|
assert adjudicator_agent.owner == maclane
|
2019-07-26 16:38:01 +00:00
|
|
|
|
2019-09-01 04:01:37 +00:00
|
|
|
michwill = testerchain.unassigned_accounts[1]
|
2019-07-26 16:38:01 +00:00
|
|
|
|
|
|
|
ownership_command = ('transfer-ownership',
|
2019-07-28 01:46:19 +00:00
|
|
|
'--deployer-address', maclane,
|
2019-07-26 16:38:01 +00:00
|
|
|
'--contract-name', STAKING_ESCROW_CONTRACT_NAME,
|
2019-09-01 04:01:37 +00:00
|
|
|
'--registry-infile', MOCK_REGISTRY_FILEPATH,
|
2019-07-28 01:46:19 +00:00
|
|
|
'--provider', TEST_PROVIDER_URI,
|
|
|
|
'--target-address', michwill,
|
2019-07-26 16:38:01 +00:00
|
|
|
'--poa')
|
|
|
|
|
|
|
|
user_input = yes
|
|
|
|
result = click_runner.invoke(deploy,
|
|
|
|
ownership_command,
|
|
|
|
input=user_input,
|
|
|
|
catch_exceptions=False)
|
|
|
|
assert result.exit_code == 0
|
2019-09-01 04:01:37 +00:00
|
|
|
assert staking_agent.owner != maclane
|
|
|
|
assert staking_agent.owner == michwill
|
2019-09-20 00:23:48 +00:00
|
|
|
|
|
|
|
|
2019-09-20 01:11:19 +00:00
|
|
|
def test_bare_contract_deployment_to_alternate_registry(click_runner, test_registry):
|
|
|
|
|
2019-09-20 05:24:51 +00:00
|
|
|
if os.path.exists(ALTERNATE_REGISTRY_FILEPATH):
|
|
|
|
os.remove(ALTERNATE_REGISTRY_FILEPATH)
|
|
|
|
assert not os.path.exists(ALTERNATE_REGISTRY_FILEPATH)
|
2019-09-20 00:23:48 +00:00
|
|
|
|
|
|
|
command = ('contracts',
|
|
|
|
'--contract-name', StakingEscrowDeployer.contract_name,
|
|
|
|
'--bare',
|
|
|
|
'--provider', TEST_PROVIDER_URI,
|
2019-09-20 01:11:19 +00:00
|
|
|
'--registry-infile', MOCK_REGISTRY_FILEPATH,
|
2019-09-20 05:24:51 +00:00
|
|
|
'--registry-outfile', ALTERNATE_REGISTRY_FILEPATH,
|
2019-11-30 16:38:23 +00:00
|
|
|
'--poa',
|
|
|
|
'--ignore-deployed')
|
2019-09-20 00:23:48 +00:00
|
|
|
|
|
|
|
user_input = '0\n' + 'Y\n' + 'DEPLOY'
|
|
|
|
result = click_runner.invoke(deploy, command, input=user_input, catch_exceptions=False)
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
2019-09-20 01:11:19 +00:00
|
|
|
# Verify alternate registry output
|
|
|
|
assert os.path.exists(MOCK_REGISTRY_FILEPATH)
|
2019-09-20 05:24:51 +00:00
|
|
|
assert os.path.exists(ALTERNATE_REGISTRY_FILEPATH)
|
2019-09-20 01:11:19 +00:00
|
|
|
old_registry = LocalContractRegistry(filepath=MOCK_REGISTRY_FILEPATH)
|
2019-09-20 05:24:51 +00:00
|
|
|
new_registry = LocalContractRegistry(filepath=ALTERNATE_REGISTRY_FILEPATH)
|
2019-09-20 01:11:19 +00:00
|
|
|
assert old_registry != new_registry
|
|
|
|
|
|
|
|
old_enrolled_names = list(old_registry.enrolled_names).count(StakingEscrowDeployer.contract_name)
|
|
|
|
new_enrolled_names = list(new_registry.enrolled_names).count(StakingEscrowDeployer.contract_name)
|
|
|
|
assert new_enrolled_names == old_enrolled_names + 1
|
|
|
|
|
2019-09-20 00:23:48 +00:00
|
|
|
|
|
|
|
def test_manual_proxy_retargeting(testerchain, click_runner, test_registry, token_economics):
|
2019-09-20 01:11:19 +00:00
|
|
|
|
|
|
|
# A local, alternate filepath registry exists
|
2019-09-20 05:24:51 +00:00
|
|
|
assert os.path.exists(ALTERNATE_REGISTRY_FILEPATH)
|
|
|
|
local_registry = LocalContractRegistry(filepath=ALTERNATE_REGISTRY_FILEPATH)
|
2019-09-20 00:23:48 +00:00
|
|
|
deployer = StakingEscrowDeployer(deployer_address=testerchain.etherbase_account,
|
|
|
|
registry=local_registry,
|
|
|
|
economics=token_economics)
|
2019-09-20 01:11:19 +00:00
|
|
|
proxy_deployer = deployer.get_proxy_deployer(registry=local_registry)
|
2019-09-20 00:23:48 +00:00
|
|
|
|
2020-01-14 03:02:17 +00:00
|
|
|
# Un-targeted enrollment is indeed un targeted by the proxy
|
2019-09-20 00:23:48 +00:00
|
|
|
untargeted_deployment = deployer.get_latest_enrollment(registry=local_registry)
|
2019-09-20 01:11:19 +00:00
|
|
|
assert proxy_deployer.target_contract.address != untargeted_deployment.address
|
|
|
|
|
|
|
|
# MichWill still owns this proxy.
|
|
|
|
michwill = testerchain.unassigned_accounts[1]
|
|
|
|
assert proxy_deployer.target_contract.functions.owner().call() == michwill
|
|
|
|
|
2019-09-20 00:23:48 +00:00
|
|
|
command = ('upgrade',
|
|
|
|
'--retarget',
|
2019-09-20 01:11:19 +00:00
|
|
|
'--deployer-address', michwill,
|
2019-09-20 00:23:48 +00:00
|
|
|
'--contract-name', StakingEscrowDeployer.contract_name,
|
|
|
|
'--target-address', untargeted_deployment.address,
|
|
|
|
'--provider', TEST_PROVIDER_URI,
|
2019-09-20 05:24:51 +00:00
|
|
|
'--registry-infile', ALTERNATE_REGISTRY_FILEPATH,
|
2019-09-20 00:23:48 +00:00
|
|
|
'--poa')
|
|
|
|
|
2019-09-20 01:11:19 +00:00
|
|
|
# Reveal the secret and upgrade
|
2019-09-20 00:23:48 +00:00
|
|
|
old_secret = INSECURE_DEPLOYMENT_SECRET_PLAINTEXT.decode()
|
|
|
|
user_input = '0\n' + 'Y\n' + f'{old_secret}\n' + (f'{INSECURE_DEVELOPMENT_PASSWORD}\n' * 2) + 'Y\n'
|
|
|
|
result = click_runner.invoke(deploy, command, input=user_input, catch_exceptions=False)
|
|
|
|
assert result.exit_code == 0
|
2019-09-20 01:11:19 +00:00
|
|
|
|
|
|
|
# The proxy target has been updated.
|
|
|
|
proxy_deployer = deployer.get_proxy_deployer(registry=local_registry)
|
|
|
|
assert proxy_deployer.target_contract.address == untargeted_deployment.address
|