2019-07-28 01:46:19 +00:00
|
|
|
import pytest
|
|
|
|
|
2019-08-31 23:16:01 +00:00
|
|
|
from nucypher.blockchain.eth.agents import PolicyManagerAgent, StakingEscrowAgent, AdjudicatorAgent, NucypherTokenAgent, \
|
|
|
|
ContractAgency
|
2019-07-26 16:38:01 +00:00
|
|
|
from nucypher.blockchain.eth.constants import STAKING_ESCROW_CONTRACT_NAME
|
2019-08-31 23:16:01 +00:00
|
|
|
from nucypher.blockchain.eth.registry import InMemoryContractRegistry
|
2019-07-26 16:38:01 +00:00
|
|
|
from nucypher.cli.deploy import deploy
|
2019-07-28 01:46:19 +00:00
|
|
|
from nucypher.utilities.sandbox.constants import TEST_PROVIDER_URI
|
2019-07-26 16:38:01 +00:00
|
|
|
|
2019-07-28 01:46:19 +00:00
|
|
|
registry_filepath = '/tmp/nucypher-test-registry.json'
|
2019-07-26 16:38:01 +00:00
|
|
|
|
2019-07-28 01:46:19 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope='module', autouse=True)
|
2019-09-01 01:57:51 +00:00
|
|
|
def mocked_blockchain_connection(testerchain, test_registry, agency):
|
2019-07-28 01:46:19 +00:00
|
|
|
# Disable registry fetching, use the mock one instead
|
2019-08-31 23:16:01 +00:00
|
|
|
InMemoryContractRegistry.download_latest_publication = lambda: registry_filepath
|
2019-09-01 01:57:51 +00:00
|
|
|
test_registry.commit(filepath=registry_filepath)
|
2019-07-28 01:46:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_nucypher_deploy_status_no_deployments(click_runner, testerchain):
|
|
|
|
|
|
|
|
status_command = ('status',
|
|
|
|
'--provider', TEST_PROVIDER_URI,
|
|
|
|
'--registry-infile', registry_filepath,
|
|
|
|
'--poa')
|
|
|
|
|
|
|
|
result = click_runner.invoke(deploy, status_command, catch_exceptions=False)
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
|
2019-08-31 23:16:01 +00:00
|
|
|
def test_nucypher_deploy_status_fully_deployed(click_runner, testerchain, test_registry, agency):
|
2019-07-28 01:46:19 +00:00
|
|
|
|
|
|
|
status_command = ('status',
|
|
|
|
'--provider', TEST_PROVIDER_URI,
|
|
|
|
'--registry-infile', registry_filepath,
|
|
|
|
'--poa')
|
|
|
|
|
|
|
|
result = click_runner.invoke(deploy, status_command, catch_exceptions=False)
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
2019-08-31 23:16:01 +00:00
|
|
|
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=test_registry)
|
|
|
|
policy_agent = ContractAgency.get_agent(PolicyManagerAgent, registry=test_registry)
|
|
|
|
adjudicator_agent = ContractAgency.get_agent(AdjudicatorAgent, registry=test_registry)
|
2019-07-28 01:46:19 +00:00
|
|
|
|
2019-09-01 01:57:51 +00:00
|
|
|
assert staking_agent.owner() in result.output
|
|
|
|
assert policy_agent.owner() in result.output
|
|
|
|
assert adjudicator_agent.owner() in result.output
|
2019-07-28 01:46:19 +00:00
|
|
|
|
|
|
|
|
2019-09-01 01:57:51 +00:00
|
|
|
def test_transfer_ownership(click_runner, testerchain, test_registry, agency):
|
2019-07-26 16:38:01 +00:00
|
|
|
|
|
|
|
maclane = testerchain.unassigned_accounts[0]
|
2019-07-28 01:46:19 +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
|
|
|
'--provider', TEST_PROVIDER_URI,
|
|
|
|
'--registry-infile', registry_filepath,
|
2019-07-26 16:38:01 +00:00
|
|
|
'--target-address', maclane,
|
|
|
|
'--poa')
|
|
|
|
|
|
|
|
account_index = '0\n'
|
|
|
|
yes = 'Y\n'
|
2019-07-28 01:46:19 +00:00
|
|
|
user_input = account_index + 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 01:57:51 +00:00
|
|
|
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=test_registry)
|
|
|
|
policy_agent = ContractAgency.get_agent(PolicyManagerAgent, registry=test_registry)
|
|
|
|
adjudicator_agent = ContractAgency.get_agent(AdjudicatorAgent, registry=test_registry)
|
2019-07-26 16:38:01 +00:00
|
|
|
|
2019-09-01 01:57:51 +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
|
|
|
|
|
|
|
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-07-28 01:46:19 +00:00
|
|
|
'--registry-infile', registry_filepath,
|
|
|
|
'--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 01:57:51 +00:00
|
|
|
assert staking_agent.owner() == michwill
|
2019-07-26 16:38:01 +00:00
|
|
|
|
|
|
|
|
2019-09-01 01:57:51 +00:00
|
|
|
def test_transfer_tokens(click_runner, testerchain, test_registry, agency):
|
2019-07-28 01:46:19 +00:00
|
|
|
|
2019-09-01 01:57:51 +00:00
|
|
|
token_agent = ContractAgency.get_agent(NucypherTokenAgent, registry=test_registry)
|
2019-07-26 16:38:01 +00:00
|
|
|
maclane = testerchain.unassigned_accounts[0]
|
2019-07-28 01:46:19 +00:00
|
|
|
pre_transfer_balance = token_agent.get_balance(address=maclane)
|
2019-07-26 16:38:01 +00:00
|
|
|
|
2019-07-28 01:46:19 +00:00
|
|
|
ownership_command = ('transfer-tokens',
|
2019-07-26 16:38:01 +00:00
|
|
|
'--deployer-address', testerchain.deployer_address,
|
2019-07-28 01:46:19 +00:00
|
|
|
'--registry-infile', registry_filepath,
|
|
|
|
'--provider', TEST_PROVIDER_URI,
|
2019-07-26 16:38:01 +00:00
|
|
|
'--target-address', maclane,
|
|
|
|
'--value', 100_000,
|
|
|
|
'--poa')
|
|
|
|
|
|
|
|
user_input = 'Y\n'
|
|
|
|
result = click_runner.invoke(deploy,
|
|
|
|
ownership_command,
|
|
|
|
input=user_input,
|
|
|
|
catch_exceptions=False)
|
|
|
|
assert result.exit_code == 0
|
2019-07-28 01:46:19 +00:00
|
|
|
|
|
|
|
# Check post-transfer balance
|
|
|
|
assert token_agent.get_balance(address=maclane) == pre_transfer_balance + 100_000
|