Esempio n. 1
0
def test_manual_proxy_retargeting(testerchain, click_runner, token_economics):

    # A local, alternate filepath registry exists
    assert os.path.exists(ALTERNATE_REGISTRY_FILEPATH)
    local_registry = LocalContractRegistry(filepath=ALTERNATE_REGISTRY_FILEPATH)
    deployer = StakingEscrowDeployer(deployer_address=testerchain.etherbase_account,
                                     registry=local_registry,
                                     economics=token_economics)
    proxy_deployer = deployer.get_proxy_deployer()

    # Un-targeted enrollment is indeed un targeted by the proxy
    untargeted_deployment = deployer.get_latest_enrollment()
    assert proxy_deployer.target_contract.address != untargeted_deployment.address

    # MichWill still owns this proxy.
    michwill = testerchain.unassigned_accounts[1]
    assert proxy_deployer.contract.functions.owner().call() == michwill

    command = ('upgrade',
               '--retarget',
               '--deployer-address', michwill,
               '--contract-name', StakingEscrowDeployer.contract_name,
               '--target-address', untargeted_deployment.address,
               '--provider', TEST_PROVIDER_URI,
               '--registry-infile', ALTERNATE_REGISTRY_FILEPATH)

    # Upgrade
    user_input = '0\n' + 'Y\n' + 'Y\n'
    result = click_runner.invoke(deploy, command, input=user_input, catch_exceptions=False)
    assert result.exit_code == 0

    # The proxy target has been updated.
    proxy_deployer = deployer.get_proxy_deployer()
    assert proxy_deployer.target_contract.address == untargeted_deployment.address
def test_manual_proxy_retargeting(testerchain, test_registry, token_economics):

    deployer = StakingEscrowDeployer(
        registry=test_registry,
        deployer_address=testerchain.etherbase_account,
        economics=token_economics)

    # Get Proxy-Direct
    proxy_deployer = deployer.get_proxy_deployer(
        registry=test_registry, provider_uri=TEST_PROVIDER_URI)

    # Re-Deploy Staking Escrow
    old_target = proxy_deployer.target_contract.address

    old_secret = bytes("...maybe not.", encoding='utf-8')
    new_secret = keccak_digest(bytes('thistimeforsure', encoding='utf-8'))

    # Get the latest un-targeted contract from the registry
    latest_deployment = deployer.get_latest_enrollment(registry=test_registry)
    receipt = deployer.retarget(target_address=latest_deployment.address,
                                existing_secret_plaintext=old_secret,
                                new_secret_hash=new_secret)

    assert receipt['status'] == 1

    # Check proxy targets
    new_target = proxy_deployer.contract.functions.target().call()
    assert old_target != new_target
    assert new_target == latest_deployment.address

    # Check address consistency
    new_bare_contract = deployer.get_principal_contract(
        registry=test_registry, provider_uri=TEST_PROVIDER_URI)
    assert new_bare_contract.address == latest_deployment.address == new_target
def test_deployer_version_management(testerchain, test_registry, token_economics):
    deployer = StakingEscrowDeployer(registry=test_registry, economics=token_economics)

    untargeted_deployment = deployer.get_latest_enrollment()
    latest_targeted_deployment = deployer.get_principal_contract()

    proxy_deployer = deployer.get_proxy_deployer()
    proxy_target = proxy_deployer.target_contract.address
    assert latest_targeted_deployment.address == proxy_target
    assert untargeted_deployment.address != latest_targeted_deployment.address
Esempio n. 4
0
def test_manual_proxy_retargeting(testerchain, test_registry, token_economics):

    deployer = StakingEscrowDeployer(
        registry=test_registry,
        deployer_address=testerchain.etherbase_account,
        economics=token_economics)

    # Get Proxy-Direct
    proxy_deployer = deployer.get_proxy_deployer(
        registry=test_registry, provider_uri=TEST_PROVIDER_URI)

    # Re-Deploy Staking Escrow
    old_target = proxy_deployer.target_contract.address

    old_secret = bytes("...maybe not.", encoding='utf-8')
    new_secret = keccak_digest(bytes('thistimeforsure', encoding='utf-8'))

    # Get the latest un-targeted contract from the registry
    latest_deployment = deployer.get_latest_enrollment(registry=test_registry)

    # Build retarget transaction (just for informational purposes)
    transaction = deployer.retarget(target_address=latest_deployment.address,
                                    existing_secret_plaintext=old_secret,
                                    new_secret_hash=new_secret,
                                    just_build_transaction=True)

    assert transaction['to'] == proxy_deployer.contract.address
    upgrade_function, _params = proxy_deployer.contract.decode_function_input(
        transaction['data'])
    assert upgrade_function.fn_name == proxy_deployer.contract.functions.upgrade.fn_name

    # Retarget, for real
    receipt = deployer.retarget(target_address=latest_deployment.address,
                                existing_secret_plaintext=old_secret,
                                new_secret_hash=new_secret)

    assert receipt['status'] == 1

    # Check proxy targets
    new_target = proxy_deployer.contract.functions.target().call()
    assert old_target != new_target
    assert new_target == latest_deployment.address

    # Check address consistency
    new_bare_contract = deployer.get_principal_contract(
        registry=test_registry, provider_uri=TEST_PROVIDER_URI)
    assert new_bare_contract.address == latest_deployment.address == new_target
def test_deployer_version_management(testerchain, test_registry,
                                     token_economics):
    deployer = StakingEscrowDeployer(
        deployer_address=testerchain.etherbase_account,
        registry=test_registry,
        economics=token_economics)

    untargeted_deployment = deployer.get_latest_enrollment(
        registry=test_registry)
    latest_targeted_deployment = deployer.get_principal_contract(
        registry=test_registry)

    proxy_deployer = deployer.get_proxy_deployer(
        registry=test_registry, provider_uri=TEST_PROVIDER_URI)
    proxy_target = proxy_deployer.target_contract.address
    assert latest_targeted_deployment.address == proxy_target
    assert untargeted_deployment.address != latest_targeted_deployment.address
Esempio n. 6
0
def test_manual_proxy_retargeting(testerchain, test_registry, token_economics,
                                  transacting_power):

    deployer = StakingEscrowDeployer(registry=test_registry,
                                     economics=token_economics)

    # Get Proxy-Direct
    proxy_deployer = deployer.get_proxy_deployer()

    # Re-Deploy Staking Escrow
    old_target = proxy_deployer.target_contract.address

    # Get the latest un-targeted contract from the registry
    latest_deployment = deployer.get_latest_enrollment()

    # Build retarget transaction (just for informational purposes)
    transaction = deployer.retarget(transacting_power=transacting_power,
                                    target_address=latest_deployment.address,
                                    just_build_transaction=True,
                                    confirmations=0)

    assert transaction['to'] == proxy_deployer.contract.address
    upgrade_function, _params = proxy_deployer.contract.decode_function_input(
        transaction['data'])  # TODO: this only tests for ethtester
    assert upgrade_function.fn_name == proxy_deployer.contract.functions.upgrade.fn_name

    # Retarget, for real
    receipt = deployer.retarget(transacting_power=transacting_power,
                                target_address=latest_deployment.address,
                                confirmations=0)

    assert receipt['status'] == 1

    # Check proxy targets
    new_target = proxy_deployer.contract.functions.target().call()
    assert old_target != new_target
    assert new_target == latest_deployment.address

    # Check address consistency
    new_bare_contract = deployer.get_principal_contract()
    assert new_bare_contract.address == latest_deployment.address == new_target