def test_activate_network(testerchain, token_economics, test_registry): staking_escrow_deployer = StakingEscrowDeployer( registry=test_registry, deployer_address=testerchain.etherbase_account) # Let's check we're in the position of activating StakingEscrow assert staking_escrow_deployer.is_deployed() assert not staking_escrow_deployer.is_active assert staking_escrow_deployer.ready_to_activate # OK, let's do it! receipts = staking_escrow_deployer.activate() for tx in receipts: assert receipts[tx]['status'] == 1 # Yay! assert staking_escrow_deployer.is_active # Trying to activate now must fail assert not staking_escrow_deployer.ready_to_activate with pytest.raises(StakingEscrowDeployer.ContractDeploymentError): staking_escrow_deployer.activate()
def test_deploy_ethereum_contracts(testerchain, deployment_progress, test_registry): testerchain = testerchain origin, *everybody_else = testerchain.client.accounts # # Nucypher Token # token_deployer = NucypherTokenDeployer(registry=test_registry, deployer_address=origin) assert token_deployer.deployer_address == origin with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert token_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not token_deployer.is_deployed() token_deployer.deploy(progress=deployment_progress) assert token_deployer.is_deployed() assert len(token_deployer.contract_address) == 42 token_agent = NucypherTokenAgent(registry=test_registry) assert len(token_agent.contract_address) == 42 assert token_agent.contract_address == token_deployer.contract_address another_token_agent = token_deployer.make_agent() assert len(another_token_agent.contract_address) == 42 assert another_token_agent.contract_address == token_deployer.contract_address == token_agent.contract_address # # StakingEscrow # stakers_escrow_secret = os.urandom(DispatcherDeployer._secret_length) staking_escrow_deployer = StakingEscrowDeployer(registry=test_registry, deployer_address=origin) assert staking_escrow_deployer.deployer_address == origin with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert staking_escrow_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not staking_escrow_deployer.is_deployed() staking_escrow_deployer.deploy(secret_hash=keccak(stakers_escrow_secret), progress=deployment_progress) assert staking_escrow_deployer.is_deployed() assert len(staking_escrow_deployer.contract_address) == 42 staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=test_registry) assert len(staking_agent.contract_address) == 42 assert staking_agent.contract_address == staking_escrow_deployer.contract_address another_staking_agent = staking_escrow_deployer.make_agent() assert len(another_staking_agent.contract_address) == 42 assert another_staking_agent.contract_address == staking_escrow_deployer.contract_address == staking_agent.contract_address # # Policy Manager # policy_manager_secret = os.urandom(DispatcherDeployer._secret_length) policy_manager_deployer = PolicyManagerDeployer(registry=test_registry, deployer_address=origin) assert policy_manager_deployer.deployer_address == origin with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert policy_manager_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not policy_manager_deployer.is_deployed() policy_manager_deployer.deploy(secret_hash=keccak(policy_manager_secret), progress=deployment_progress) assert policy_manager_deployer.is_deployed() assert len(policy_manager_deployer.contract_address) == 42 policy_agent = policy_manager_deployer.make_agent() assert len(policy_agent.contract_address) == 42 assert policy_agent.contract_address == policy_manager_deployer.contract_address another_policy_agent = policy_manager_deployer.make_agent() assert len(another_policy_agent.contract_address) == 42 assert another_policy_agent.contract_address == policy_manager_deployer.contract_address == policy_agent.contract_address # # Adjudicator # adjudicator_secret = os.urandom(DispatcherDeployer._secret_length) adjudicator_deployer = AdjudicatorDeployer(registry=test_registry, deployer_address=origin) assert adjudicator_deployer.deployer_address == origin with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert adjudicator_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not adjudicator_deployer.is_deployed() adjudicator_deployer.deploy(secret_hash=keccak(adjudicator_secret), progress=deployment_progress) assert adjudicator_deployer.is_deployed() assert len(adjudicator_deployer.contract_address) == 42 adjudicator_agent = adjudicator_deployer.make_agent() assert len(adjudicator_agent.contract_address) == 42 assert adjudicator_agent.contract_address == adjudicator_deployer.contract_address another_adjudicator_agent = AdjudicatorAgent(registry=test_registry) assert len(another_adjudicator_agent.contract_address) == 42 assert another_adjudicator_agent.contract_address == adjudicator_deployer.contract_address == adjudicator_agent.contract_address # overall deployment steps must match aggregated individual expected number of steps all_deployment_transactions = token_deployer.deployment_steps + staking_escrow_deployer.deployment_steps + \ policy_manager_deployer.deployment_steps + adjudicator_deployer.deployment_steps assert deployment_progress.num_steps == len(all_deployment_transactions)
def test_deploy_idle_network(testerchain, deployment_progress, test_registry): origin, *everybody_else = testerchain.client.accounts # # Nucypher Token # token_deployer = NucypherTokenDeployer(registry=test_registry, deployer_address=origin) assert token_deployer.deployer_address == origin with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert token_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not token_deployer.is_deployed() token_deployer.deploy(progress=deployment_progress) assert token_deployer.is_deployed() token_agent = NucypherTokenAgent(registry=test_registry) assert token_agent.contract_address == token_deployer.contract_address another_token_agent = token_deployer.make_agent() assert another_token_agent.contract_address == token_deployer.contract_address == token_agent.contract_address # # StakingEscrow - in INIT mode, i.e. stub for StakingEscrow # staking_escrow_deployer = StakingEscrowDeployer(registry=test_registry, deployer_address=origin) assert staking_escrow_deployer.deployer_address == origin with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert staking_escrow_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not staking_escrow_deployer.is_deployed() staking_escrow_deployer.deploy(progress=deployment_progress, deployment_mode=constants.INIT) assert not staking_escrow_deployer.is_deployed() # # Policy Manager # policy_manager_deployer = PolicyManagerDeployer(registry=test_registry, deployer_address=origin) assert policy_manager_deployer.deployer_address == origin with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert policy_manager_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not policy_manager_deployer.is_deployed() policy_manager_deployer.deploy(progress=deployment_progress) assert policy_manager_deployer.is_deployed() policy_agent = policy_manager_deployer.make_agent() assert policy_agent.contract_address == policy_manager_deployer.contract_address # # Adjudicator # adjudicator_deployer = AdjudicatorDeployer(registry=test_registry, deployer_address=origin) assert adjudicator_deployer.deployer_address == origin with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert adjudicator_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not adjudicator_deployer.is_deployed() adjudicator_deployer.deploy(progress=deployment_progress) assert adjudicator_deployer.is_deployed() adjudicator_agent = adjudicator_deployer.make_agent() assert adjudicator_agent.contract_address == adjudicator_deployer.contract_address # # StakingEscrow - in IDLE mode, i.e. without activation steps (approve_funding and initialize) # staking_escrow_deployer = StakingEscrowDeployer(registry=test_registry, deployer_address=origin) assert staking_escrow_deployer.deployer_address == origin with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert staking_escrow_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not staking_escrow_deployer.is_deployed() staking_escrow_deployer.deploy(progress=deployment_progress, deployment_mode=constants.IDLE) assert staking_escrow_deployer.is_deployed() staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=test_registry) assert staking_agent.contract_address == staking_escrow_deployer.contract_address # The contract has no tokens yet assert token_agent.get_balance(staking_agent.contract_address) == 0
def test_deploy_ethereum_contracts(testerchain, deployment_progress, test_registry): origin, *everybody_else = testerchain.client.accounts tpower = TransactingPower(account=origin, signer=Web3Signer(testerchain.client)) # # Nucypher Token # token_deployer = NucypherTokenDeployer(registry=test_registry) with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert token_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not token_deployer.is_deployed() token_deployer.deploy(progress=deployment_progress, transacting_power=tpower) assert token_deployer.is_deployed() assert len(token_deployer.contract_address) == 42 token_agent = NucypherTokenAgent(registry=test_registry) assert len(token_agent.contract_address) == 42 assert token_agent.contract_address == token_deployer.contract_address another_token_agent = token_deployer.make_agent() assert len(another_token_agent.contract_address) == 42 assert another_token_agent.contract_address == token_deployer.contract_address == token_agent.contract_address # # StakingEscrowStub # staking_escrow_deployer = StakingEscrowDeployer(registry=test_registry) with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert staking_escrow_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not staking_escrow_deployer.is_deployed() staking_escrow_deployer.deploy(progress=deployment_progress, transacting_power=tpower) assert not staking_escrow_deployer.is_deployed() assert len(staking_escrow_deployer.contract_address) == 42 # # Policy Manager # policy_manager_deployer = PolicyManagerDeployer(registry=test_registry) with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert policy_manager_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not policy_manager_deployer.is_deployed() policy_manager_deployer.deploy(progress=deployment_progress, transacting_power=tpower) assert policy_manager_deployer.is_deployed() assert len(policy_manager_deployer.contract_address) == 42 policy_agent = policy_manager_deployer.make_agent() assert len(policy_agent.contract_address) == 42 assert policy_agent.contract_address == policy_manager_deployer.contract_address another_policy_agent = policy_manager_deployer.make_agent() assert len(another_policy_agent.contract_address) == 42 assert another_policy_agent.contract_address == policy_manager_deployer.contract_address == policy_agent.contract_address # # Adjudicator # adjudicator_deployer = AdjudicatorDeployer(registry=test_registry) with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert adjudicator_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not adjudicator_deployer.is_deployed() adjudicator_deployer.deploy(progress=deployment_progress, transacting_power=tpower) assert adjudicator_deployer.is_deployed() assert len(adjudicator_deployer.contract_address) == 42 adjudicator_agent = adjudicator_deployer.make_agent() assert len(adjudicator_agent.contract_address) == 42 assert adjudicator_agent.contract_address == adjudicator_deployer.contract_address another_adjudicator_agent = AdjudicatorAgent(registry=test_registry) assert len(another_adjudicator_agent.contract_address) == 42 assert another_adjudicator_agent.contract_address == adjudicator_deployer.contract_address == adjudicator_agent.contract_address # StakingEscrow staking_escrow_deployer = StakingEscrowDeployer(registry=test_registry) with pytest.raises(BaseContractDeployer.ContractDeploymentError): assert staking_escrow_deployer.contract_address is constants.CONTRACT_NOT_DEPLOYED assert not staking_escrow_deployer.is_deployed() staking_escrow_deployer.deploy(progress=deployment_progress, deployment_mode=constants.FULL, transacting_power=tpower) assert staking_escrow_deployer.is_deployed() assert len(staking_escrow_deployer.contract_address) == 42 staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=test_registry) assert len(staking_agent.contract_address) == 42 assert staking_agent.contract_address == staking_escrow_deployer.contract_address another_staking_agent = staking_escrow_deployer.make_agent() assert len(another_staking_agent.contract_address) == 42 assert another_staking_agent.contract_address == staking_escrow_deployer.contract_address == staking_agent.contract_address # overall deployment steps must match aggregated individual expected number of steps all_deployment_transactions = token_deployer.deployment_steps + staking_escrow_deployer.init_steps + \ staking_escrow_deployer.deployment_steps + \ policy_manager_deployer.deployment_steps + adjudicator_deployer.deployment_steps assert deployment_progress.num_steps == len(all_deployment_transactions)