예제 #1
0
def test_upgrade_staking_interface(testerchain, test_registry):

    router = testerchain.get_contract_by_name(registry=test_registry,
                                              contract_name=StakingInterfaceRouterDeployer.contract_name)

    contract = testerchain.get_contract_by_name(registry=test_registry,
                                                contract_name=StakingInterfaceDeployer.contract_name,
                                                proxy_name=StakingInterfaceRouterDeployer.contract_name,
                                                use_proxy_address=False)

    target = router.functions.target().call()
    assert target == contract.address

    staking_interface_deployer = StakingInterfaceDeployer(deployer_address=testerchain.etherbase_account,
                                                          registry=test_registry)

    receipts = staking_interface_deployer.upgrade(ignore_deployed=True, confirmations=0)

    assert len(receipts) == 2

    for title, receipt in receipts.items():
        assert receipt['status'] == 1

    for preallocation_escrow_contract in preallocation_escrow_contracts:
        router_address = preallocation_escrow_contract.functions.router().call()
        assert router.address == router_address

    new_target = router.functions.target().call()
    contract = testerchain.get_contract_by_name(registry=test_registry,
                                                contract_name=StakingInterfaceDeployer.contract_name,
                                                proxy_name=StakingInterfaceRouterDeployer.contract_name,
                                                use_proxy_address=False)
    assert new_target == contract.address
    assert new_target != target
예제 #2
0
파일: fixtures.py 프로젝트: gs455/nucypher
def _make_agency(testerchain, test_registry):
    """
    Launch the big three contracts on provided chain,
    make agents for each and return them.
    """

    # Mock TransactingPower Consumption (Deployer)
    testerchain.transacting_power = TransactingPower(
        password=INSECURE_DEVELOPMENT_PASSWORD,
        account=testerchain.etherbase_account)
    testerchain.transacting_power.activate()

    origin = testerchain.etherbase_account

    token_deployer = NucypherTokenDeployer(deployer_address=origin,
                                           registry=test_registry)
    token_deployer.deploy()

    staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin,
                                                    registry=test_registry,
                                                    test_mode=True)
    staking_escrow_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    policy_manager_deployer = PolicyManagerDeployer(deployer_address=origin,
                                                    registry=test_registry)
    policy_manager_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    adjudicator_deployer = AdjudicatorDeployer(deployer_address=origin,
                                               registry=test_registry)
    adjudicator_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    staking_interface_deployer = StakingInterfaceDeployer(
        deployer_address=origin, registry=test_registry)
    staking_interface_deployer.deploy(
        secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    token_agent = token_deployer.make_agent()  # 1 Token
    staking_agent = staking_escrow_deployer.make_agent()  # 2 Staking Escrow
    policy_agent = policy_manager_deployer.make_agent()  # 3 Policy Agent
    _adjudicator_agent = adjudicator_deployer.make_agent()  # 4 Adjudicator

    # TODO: Get rid of returning these agents here.
    # What's important is deploying and creating the first agent for each contract,
    # and since agents are singletons, in tests it's only necessary to call the agent
    # constructor again to receive the existing agent.
    #
    # For example:
    #     staking_agent = StakingEscrowAgent()
    #
    # This is more clear than how we currently obtain an agent instance in tests:
    #     _, staking_agent, _ = agency
    #
    # Other advantages is that it's closer to how agents should be use (i.e., there
    # are no fixtures IRL) and it's more extensible (e.g., AdjudicatorAgent)

    return token_agent, staking_agent, policy_agent
예제 #3
0
def test_transfer_ownership_staking_interface_router(click_runner, testerchain, agency_local_registry):

    maclane = testerchain.unassigned_accounts[0]

    ownership_command = ('transfer-ownership',
                         '--registry-infile', agency_local_registry.filepath,
                         '--contract-name', StakingInterfaceDeployer.contract_name,
                         '--provider', TEST_PROVIDER_URI,
                         '--network', TEMPORARY_DOMAIN,
                         '--target-address', maclane,
                         '--debug')

    account_index = '0\n'
    yes = 'Y\n'
    user_input = account_index + yes + yes

    result = click_runner.invoke(deploy,
                                 ownership_command,
                                 input=user_input,
                                 catch_exceptions=False)
    assert result.exit_code == 0, result.output

    # This owner is updated
    interface_deployer = StakingInterfaceDeployer(registry=agency_local_registry)
    assert interface_deployer.owner == maclane
예제 #4
0
def test_upgrade_staking_interface(testerchain, test_registry):

    old_secret = INSECURE_DEPLOYMENT_SECRET_PLAINTEXT
    new_secret = 'new' + STAKING_INTERFACE_DEPLOYMENT_SECRET
    new_secret_hash = keccak_digest(new_secret.encode())
    router = testerchain.get_contract_by_name(
        registry=test_registry,
        contract_name=StakingInterfaceRouterDeployer.contract_name)

    contract = testerchain.get_contract_by_name(
        registry=test_registry,
        contract_name=StakingInterfaceDeployer.contract_name,
        proxy_name=StakingInterfaceRouterDeployer.contract_name,
        use_proxy_address=False)

    target = router.functions.target().call()
    assert target == contract.address

    staking_interface_deployer = StakingInterfaceDeployer(
        deployer_address=testerchain.etherbase_account, registry=test_registry)

    receipts = staking_interface_deployer.upgrade(
        existing_secret_plaintext=old_secret,
        new_secret_hash=new_secret_hash,
        ignore_deployed=True)

    assert len(receipts) == 2

    for title, receipt in receipts.items():
        assert receipt['status'] == 1

    for preallocation_escrow_contract in preallocation_escrow_contracts:
        router_address = preallocation_escrow_contract.functions.router().call(
        )
        assert router.address == router_address

    new_target = router.functions.target().call()
    contract = testerchain.get_contract_by_name(
        registry=test_registry,
        contract_name=StakingInterfaceDeployer.contract_name,
        proxy_name=StakingInterfaceRouterDeployer.contract_name,
        use_proxy_address=False)
    assert new_target == contract.address
    assert new_target != target
예제 #5
0
def test_staking_interface_deployer(testerchain, deployment_progress,
                                    test_registry):

    #
    # Setup
    #

    origin = testerchain.etherbase_account

    token_deployer = NucypherTokenDeployer(deployer_address=origin,
                                           registry=test_registry)
    token_deployer.deploy()

    staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin,
                                                    registry=test_registry)
    staking_escrow_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    policy_manager_deployer = PolicyManagerDeployer(deployer_address=origin,
                                                    registry=test_registry)
    policy_manager_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    adjudicator_deployer = AdjudicatorDeployer(deployer_address=origin,
                                               registry=test_registry)
    adjudicator_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    #
    # Test
    #

    staking_interface_deployer = StakingInterfaceDeployer(
        deployer_address=origin, registry=test_registry)
    staking_interface_receipts = staking_interface_deployer.deploy(
        secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH,
        progress=deployment_progress)

    # deployment steps must match expected number of steps
    assert deployment_progress.num_steps == len(
        staking_interface_deployer.deployment_steps) == 2
    assert len(staking_interface_receipts) == 2

    for step in staking_interface_deployer.deployment_steps:
        assert staking_interface_receipts[step]['status'] == 1
예제 #6
0
def _make_agency(testerchain, test_registry, token_economics,
                 deployer_transacting_power):

    transacting_power = deployer_transacting_power

    token_deployer = NucypherTokenDeployer(economics=token_economics,
                                           registry=test_registry)
    token_deployer.deploy(transacting_power=transacting_power)

    staking_escrow_deployer = StakingEscrowDeployer(economics=token_economics,
                                                    registry=test_registry)
    staking_escrow_deployer.deploy(deployment_mode=INIT,
                                   transacting_power=transacting_power)

    policy_manager_deployer = PolicyManagerDeployer(economics=token_economics,
                                                    registry=test_registry)
    policy_manager_deployer.deploy(transacting_power=transacting_power)

    adjudicator_deployer = AdjudicatorDeployer(economics=token_economics,
                                               registry=test_registry)
    adjudicator_deployer.deploy(transacting_power=transacting_power)

    staking_interface_deployer = StakingInterfaceDeployer(
        economics=token_economics, registry=test_registry)
    staking_interface_deployer.deploy(transacting_power=transacting_power)

    worklock_deployer = WorklockDeployer(economics=token_economics,
                                         registry=test_registry)
    worklock_deployer.deploy(transacting_power=transacting_power)

    staking_escrow_deployer = StakingEscrowDeployer(economics=token_economics,
                                                    registry=test_registry)
    staking_escrow_deployer.deploy(deployment_mode=FULL,
                                   transacting_power=transacting_power)

    # Set additional parameters
    minimum, default, maximum = FEE_RATE_RANGE
    policy_agent = policy_manager_deployer.make_agent()
    txhash = policy_agent.contract.functions.setFeeRateRange(
        minimum, default, maximum).transact()
    testerchain.wait_for_receipt(txhash)
예제 #7
0
def staking_interface_deployer(staking_escrow_deployer, testerchain,
                               test_registry):
    staking_interface_deployer = StakingInterfaceDeployer(
        registry=test_registry, deployer_address=testerchain.etherbase_account)
    return staking_interface_deployer
예제 #8
0
def _make_agency(
    testerchain, test_registry, token_economics
) -> Tuple[NucypherTokenAgent, StakingEscrowAgent, PolicyManagerAgent]:
    """
    Launch the big three contracts on provided chain,
    make agents for each and return them.
    """

    # Mock TransactingPower Consumption (Deployer)
    testerchain.transacting_power = TransactingPower(
        password=INSECURE_DEVELOPMENT_PASSWORD,
        signer=Web3Signer(client=testerchain.client),
        account=testerchain.etherbase_account)
    testerchain.transacting_power.activate()

    origin = testerchain.etherbase_account

    token_deployer = NucypherTokenDeployer(deployer_address=origin,
                                           economics=token_economics,
                                           registry=test_registry)
    token_deployer.deploy()

    staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin,
                                                    economics=token_economics,
                                                    registry=test_registry,
                                                    test_mode=True)
    staking_escrow_deployer.deploy()

    policy_manager_deployer = PolicyManagerDeployer(deployer_address=origin,
                                                    economics=token_economics,
                                                    registry=test_registry)
    policy_manager_deployer.deploy()

    adjudicator_deployer = AdjudicatorDeployer(deployer_address=origin,
                                               economics=token_economics,
                                               registry=test_registry)
    adjudicator_deployer.deploy()

    staking_interface_deployer = StakingInterfaceDeployer(
        deployer_address=origin,
        economics=token_economics,
        registry=test_registry)
    staking_interface_deployer.deploy()

    worklock_deployer = WorklockDeployer(deployer_address=origin,
                                         economics=token_economics,
                                         registry=test_registry)
    worklock_deployer.deploy()

    token_agent = token_deployer.make_agent()  # 1 Token
    staking_agent = staking_escrow_deployer.make_agent()  # 2 Staking Escrow
    policy_agent = policy_manager_deployer.make_agent()  # 3 Policy Agent
    _adjudicator_agent = adjudicator_deployer.make_agent()  # 4 Adjudicator
    _worklock_agent = worklock_deployer.make_agent()  # 5 Worklock

    # Set additional parameters
    minimum, default, maximum = FEE_RATE_RANGE
    txhash = policy_agent.contract.functions.setFeeRateRange(
        minimum, default, maximum).transact()
    _receipt = testerchain.wait_for_receipt(txhash)

    # TODO: Get rid of returning these agents here.
    # What's important is deploying and creating the first agent for each contract,
    # and since agents are singletons, in tests it's only necessary to call the agent
    # constructor again to receive the existing agent.
    #
    # For example:
    #     staking_agent = StakingEscrowAgent()
    #
    # This is more clear than how we currently obtain an agent instance in tests:
    #     _, staking_agent, _ = agency
    #
    # Other advantages is that it's closer to how agents should be use (i.e., there
    # are no fixtures IRL) and it's more extensible (e.g., AdjudicatorAgent)

    return token_agent, staking_agent, policy_agent
예제 #9
0
def staking_interface_deployer(staking_escrow_deployer, testerchain,
                               test_registry):
    staking_interface_deployer = StakingInterfaceDeployer(
        registry=test_registry)
    return staking_interface_deployer