Exemple #1
0
    def deploy_escrow_proxy(self, secret):

        escrow_proxy_deployer = UserEscrowProxyDeployer(
            deployer_address=self.deployer_address, secret_hash=secret)

        escrow_proxy_deployer.deploy()
        return escrow_proxy_deployer
Exemple #2
0
def test_upgrade_user_escrow_proxy(session_testerchain, session_agency,
                                   user_escrow_proxy_deployer):
    testerchain = session_testerchain
    agency = session_agency
    old_secret = USER_ESCROW_PROXY_DEPLOYMENT_SECRET.encode()
    new_secret = 'new' + USER_ESCROW_PROXY_DEPLOYMENT_SECRET
    new_secret_hash = keccak_digest(new_secret.encode())

    linker_deployer = LibraryLinkerDeployer(
        blockchain=testerchain,
        deployer_address=user_escrow_proxy_deployer.deployer_address,
        target_contract=user_escrow_proxy_deployer.contract,
        bare=True)
    linker_address = linker_deployer.contract_address

    target = linker_deployer.contract.functions.target().call()
    assert target == UserEscrowProxyDeployer.get_latest_version(
        blockchain=testerchain).address

    receipts = user_escrow_proxy_deployer.upgrade(
        existing_secret_plaintext=old_secret, new_secret_hash=new_secret_hash)

    assert len(receipts) == 2

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

    for user_escrow_contract in user_escrow_contracts:
        linker = user_escrow_contract.functions.linker().call()
        assert linker == linker_address

    new_target = linker_deployer.contract.functions.target().call()
    assert new_target == UserEscrowProxyDeployer.get_latest_version(
        blockchain=testerchain).address
    assert new_target != target
Exemple #3
0
    def deploy_escrow_proxy(self, secret: bytes):

        escrow_proxy_deployer = UserEscrowProxyDeployer(blockchain=self.blockchain,
                                                        deployer_address=self.deployer_address,
                                                        secret_hash=secret)

        txhashes = escrow_proxy_deployer.deploy()
        return txhashes
    def deploy_escrow_proxy(self, secret: bytes) -> dict:
        secret = self.blockchain.interface.w3.keccak(secret)
        escrow_proxy_deployer = UserEscrowProxyDeployer(blockchain=self.blockchain,
                                                        deployer_address=self.deployer_address,
                                                        secret_hash=secret)

        txhashes = escrow_proxy_deployer.deploy()
        return txhashes
Exemple #5
0
def proxy_deployer(testerchain, agency) -> UserEscrowAgent:
    deployer_address, beneficiary_address, *everybody_else = testerchain.client.accounts

    # Proxy
    proxy_secret = os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH)
    proxy_deployer = UserEscrowProxyDeployer(deployer_address=deployer_address, blockchain=testerchain)

    proxy_deployer.deploy(secret_hash=proxy_secret)
    yield proxy_deployer
Exemple #6
0
def proxy_deployer(testerchain) -> UserEscrowAgent:
    deployer_address, beneficiary_address, *everybody_else = testerchain.interface.w3.eth.accounts

    # Proxy
    proxy_secret = os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH)
    proxy_deployer = UserEscrowProxyDeployer(deployer_address=deployer_address, secret_hash=proxy_secret)

    proxy_deployer.deploy()
    yield proxy_deployer
def user_escrow_proxy(three_agents):
    token_agent, miner_agent, policy_agent = three_agents
    testerchain = policy_agent.blockchain
    deployer = testerchain.etherbase_account

    escrow_proxy_deployer = UserEscrowProxyDeployer(deployer_address=deployer)

    _escrow_proxy_deployments_txhashes = escrow_proxy_deployer.deploy(secret_hash=os.urandom(32))
    testerchain.time_travel(seconds=120)
    yield escrow_proxy_deployer.contract_address
    testerchain.interface.registry.clear()
    testerchain.sever_connection()
def user_escrow_proxy(agency):
    token_agent, staking_agent, policy_agent = agency
    testerchain = policy_agent.blockchain
    deployer = testerchain.etherbase_account

    escrow_proxy_deployer = UserEscrowProxyDeployer(deployer_address=deployer)

    _escrow_proxy_deployments_txhashes = escrow_proxy_deployer.deploy(
        secret_hash=os.urandom(32))
    testerchain.time_travel(seconds=120)
    yield escrow_proxy_deployer.contract_address
    testerchain.registry.clear()
    testerchain.disconnect()
def test_user_escrow_deployer(three_agents, testerchain):
    deployer = testerchain.etherbase_account

    escrow_proxy_deployer = UserEscrowProxyDeployer(deployer_address=deployer, secret_hash=os.urandom(32))

    _escrow_proxy_deployments_txhashes = escrow_proxy_deployer.deploy()

    deployer = UserEscrowDeployer(deployer_address=deployer)

    deployment_txhashes = deployer.deploy()

    for title, txhash in deployment_txhashes.items():
        receipt = testerchain.wait_for_receipt(txhash=txhash)
        assert receipt['status'] == 1, "Transaction Rejected {}:{}".format(title, txhash)
Exemple #10
0
def _make_agency(testerchain, test_registry):
    """
    Launch the big three contracts on provided chain,
    make agents for each and return them.
    """
    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)

    user_escrow_proxy_deployer = UserEscrowProxyDeployer(
        deployer_address=origin, registry=test_registry)
    user_escrow_proxy_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
Exemple #11
0
def user_escrow_proxy_deployer(session_testerchain, session_agency):
    print("ENTER USER ESCROW")
    testerchain = session_testerchain
    deployer = testerchain.etherbase_account
    user_escrow_proxy_deployer = UserEscrowProxyDeployer(
        deployer_address=deployer, blockchain=testerchain)
    return user_escrow_proxy_deployer
def test_user_escrow_proxy_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
    #

    user_escrow_proxy_deployer = UserEscrowProxyDeployer(
        deployer_address=origin, registry=test_registry)
    user_escrow_proxy_receipts = user_escrow_proxy_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(
        user_escrow_proxy_deployer.deployment_steps) == 2
    assert len(user_escrow_proxy_receipts) == 2

    for step in user_escrow_proxy_deployer.deployment_steps:
        assert user_escrow_proxy_receipts[step]['status'] == 1
def test_upgrade_user_escrow_proxy(testerchain, test_registry):

    old_secret = INSECURE_DEPLOYMENT_SECRET_PLAINTEXT
    new_secret = 'new' + USER_ESCROW_PROXY_DEPLOYMENT_SECRET
    new_secret_hash = keccak_digest(new_secret.encode())
    linker = testerchain.get_contract_by_name(
        registry=test_registry, name=LibraryLinkerDeployer.contract_name)

    contract = testerchain.get_contract_by_name(
        registry=test_registry,
        name=UserEscrowProxyDeployer.contract_name,
        proxy_name=LibraryLinkerDeployer.contract_name,
        use_proxy_address=False)

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

    user_escrow_proxy_deployer = UserEscrowProxyDeployer(
        deployer_address=testerchain.etherbase_account, registry=test_registry)

    receipts = user_escrow_proxy_deployer.upgrade(
        existing_secret_plaintext=old_secret, new_secret_hash=new_secret_hash)

    assert len(receipts) == 2

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

    for user_escrow_contract in user_escrow_contracts:
        linker_address = user_escrow_contract.functions.linker().call()
        assert linker.address == linker_address

    new_target = linker.functions.target().call()
    contract = testerchain.get_contract_by_name(
        registry=test_registry,
        name=UserEscrowProxyDeployer.contract_name,
        proxy_name=LibraryLinkerDeployer.contract_name,
        use_proxy_address=False)
    assert new_target == contract.address
    assert new_target != target