Esempio n. 1
0
def test_deploy_multiple(session_testerchain, session_agency,
                         user_escrow_proxy_deployer):
    testerchain = session_testerchain
    deployer_account = testerchain.etherbase_account

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

    for index in range(NUMBER_OF_PREALLOCATIONS):
        deployer = UserEscrowDeployer(deployer_address=deployer_account,
                                      blockchain=testerchain)

        deployment_receipt = deployer.deploy()
        assert deployment_receipt['status'] == 1

        user_escrow_contract = deployer.contract
        linker = user_escrow_contract.functions.linker().call()
        assert linker == linker_address

        user_escrow_contracts.append(user_escrow_contract)

        # simulates passage of time / blocks
        if index % 5 == 0:
            testerchain.w3.eth.web3.testing.mine(1)
            testerchain.time_travel(seconds=5)

    assert len(user_escrow_contracts) == NUMBER_OF_PREALLOCATIONS
def agent(testerchain, proxy_deployer) -> UserEscrowAgent:
    deployer_address, beneficiary_address, *everybody_else = testerchain.interface.w3.eth.accounts

    # Escrow
    escrow_deployer = UserEscrowDeployer(
        deployer_address=deployer_address,
        allocation_registry=TEST_ALLOCATION_REGISTRY)

    _txhash = escrow_deployer.deploy()

    escrow_deployer.initial_deposit(value=TEST_ALLOCATION,
                                    duration=TEST_DURATION)
    assert escrow_deployer.contract.functions.getLockedTokens().call(
    ) == TEST_ALLOCATION
    escrow_deployer.assign_beneficiary(beneficiary_address=beneficiary_address)
    escrow_deployer.enroll_principal_contract()
    assert escrow_deployer.contract.functions.getLockedTokens().call(
    ) == TEST_ALLOCATION
    _agent = escrow_deployer.make_agent()

    _direct_agent = UserEscrowAgent(
        blockchain=testerchain,
        allocation_registry=TEST_ALLOCATION_REGISTRY,
        beneficiary=beneficiary_address)

    assert _direct_agent == _agent
    assert _direct_agent.contract.abi == _agent.contract.abi
    assert _direct_agent.contract.address == _agent.contract.address
    assert _agent.principal_contract.address == escrow_deployer.contract.address
    assert _agent.principal_contract.abi == escrow_deployer.contract.abi
    assert _direct_agent.contract.abi == escrow_deployer.contract.abi
    assert _direct_agent.contract.address == escrow_deployer.contract.address

    yield _agent
    TEST_ALLOCATION_REGISTRY.clear()
def test_deploy_multiple_preallocations(testerchain, test_registry):
    testerchain = testerchain
    deployer_account = testerchain.etherbase_account

    linker = testerchain.get_contract_by_name(
        registry=test_registry, name=LibraryLinkerDeployer.contract_name)
    linker_address = linker.address
    for index in range(NUMBER_OF_PREALLOCATIONS):
        deployer = UserEscrowDeployer(deployer_address=deployer_account,
                                      registry=test_registry)

        deployment_receipt = deployer.deploy()
        assert deployment_receipt['status'] == 1

        user_escrow_contract = deployer.contract
        linker = user_escrow_contract.functions.linker().call()
        assert linker == linker_address

        user_escrow_contracts.append(user_escrow_contract)

        # simulates passage of time / blocks
        if index % 5 == 0:
            testerchain.w3.eth.web3.testing.mine(1)
            testerchain.time_travel(seconds=5)

    assert len(user_escrow_contracts) == NUMBER_OF_PREALLOCATIONS
Esempio n. 4
0
 def deploy_user_escrow(self, allocation_registry: AllocationRegistry) -> UserEscrowDeployer:
     user_escrow_deployer = UserEscrowDeployer(registry=self.registry,
                                               deployer_address=self.deployer_address,
                                               allocation_registry=allocation_registry)
     user_escrow_deployer.deploy()
     principal_address = user_escrow_deployer.contract.address
     self.user_escrow_deployers[principal_address] = user_escrow_deployer
     return user_escrow_deployer
Esempio n. 5
0
    def deploy_user_escrow(self):
        user_escrow_deployer = UserEscrowDeployer(blockchain=self.blockchain,
                                                  deployer_address=self.deployer_address,
                                                  allocation_registry=self.allocation_registy)

        user_escrow_deployer.deploy()
        principal_address = user_escrow_deployer.contract.address
        self.user_escrow_deployers[principal_address] = user_escrow_deployer
        return user_escrow_deployer
Esempio n. 6
0
def test_deploy_and_allocate(three_agents, user_escrow_proxy, token_economics):
    token_agent, miner_agent, policy_agent = three_agents
    testerchain = policy_agent.blockchain
    origin = testerchain.etherbase_account

    deployments = dict()
    allocation = token_economics.minimum_allowed_locked * 1
    number_of_deployments = 1

    _last_deployment_address = None
    for index in range(number_of_deployments):
        escrow_deployer = UserEscrowDeployer(deployer_address=origin)

        _deployment_txhashes = escrow_deployer.deploy()

        # Ensure we have the correct assembly of address and abi
        assert escrow_deployer.contract.address == escrow_deployer.contract.address
        # assert escrow_deployer.contract_address == user_escrow_proxy  # (address)

        # Ensure each deployment is unique
        if _last_deployment_address:
            assert escrow_deployer.contract.address != _last_deployment_address
        _last_deployment_address = escrow_deployer.contract.address

        deployments[escrow_deployer.contract.address] = escrow_deployer
    assert len(deployments) == number_of_deployments

    # Let some time pass
    testerchain.time_travel(hours=3)
    assert token_agent.get_balance(address=origin) > 1

    # Start allocating tokens
    deposit_txhashes, approve_hashes = dict(), dict()
    for address, deployer in deployments.items():
        assert deployer.deployer_address == origin

        deposit_txhash = deployer.initial_deposit(
            value=allocation, duration=token_economics.maximum_locked_periods)
        receipt = testerchain.wait_for_receipt(txhash=deposit_txhash)
        assert receipt['status'] == 1, "Transaction Rejected {}".format(
            deposit_txhash)
        deposit_txhashes[address] = deposit_txhash

        beneficiary = random.choice(testerchain.unassigned_accounts)
        assignment_txhash = deployer.assign_beneficiary(beneficiary)
        receipt = testerchain.wait_for_receipt(txhash=assignment_txhash)
        assert receipt['status'] == 1, "Transaction Rejected {}".format(
            assignment_txhash)

    assert len(deposit_txhashes) == number_of_deployments == len(deployments)
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)
def test_deploy_multiple(testerchain):
    deployer = testerchain.etherbase_account

    number_of_deployments = 100
    for index in range(number_of_deployments):
        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)

        # simulates passage of time / blocks
        if index % 15 == 0:
            testerchain.interface.w3.eth.web3.testing.mine(1)
            testerchain.time_travel(seconds=5)
Esempio n. 9
0
def test_deploy_and_allocate(agency, token_economics, test_registry):
    token_agent, staking_agent, policy_agent = agency
    testerchain = policy_agent.blockchain
    origin = testerchain.etherbase_account

    deployments = dict()
    allocation = token_economics.minimum_allowed_locked * 1
    number_of_deployments = 1

    _last_deployment_address = None
    for index in range(number_of_deployments):
        escrow_deployer = UserEscrowDeployer(deployer_address=origin, registry=test_registry)

        _deployment_txhashes = escrow_deployer.deploy()

        # Ensure we have the correct assembly of address and abi
        assert escrow_deployer.contract.address == escrow_deployer.contract.address
        # assert escrow_deployer.contract_address == user_escrow_proxy  # (address)

        # Ensure each deployment is unique
        if _last_deployment_address:
            assert escrow_deployer.contract.address != _last_deployment_address
        _last_deployment_address = escrow_deployer.contract.address

        deployments[escrow_deployer.contract.address] = escrow_deployer
    assert len(deployments) == number_of_deployments

    # Let some time pass
    testerchain.time_travel(hours=3)
    assert token_agent.get_balance(address=origin) > 1

    # Start allocating tokens
    deposit_receipts, approve_hashes = list(), dict()
    for address, deployer in deployments.items():
        assert deployer.deployer_address == origin

        deposit_receipt = deployer.initial_deposit(value=allocation, duration_seconds=token_economics.maximum_rewarded_periods)
        deposit_receipts.append(deposit_receipt)

        beneficiary = random.choice(testerchain.unassigned_accounts)
        _assign_receipt = deployer.assign_beneficiary(beneficiary)

    assert len(deposit_receipts) == number_of_deployments == len(deployments)
Esempio n. 10
0
def agent(testerchain, proxy_deployer, allocation_value) -> UserEscrowAgent:
    deployer_address, beneficiary_address, *everybody_else = testerchain.client.accounts

    # Mock Powerup consumption (Deployer)
    testerchain.transacting_power = TransactingPower(
        blockchain=testerchain,
        password=INSECURE_DEVELOPMENT_PASSWORD,
        account=deployer_address)
    testerchain.transacting_power.activate()

    # Escrow
    escrow_deployer = UserEscrowDeployer(
        deployer_address=deployer_address,
        blockchain=testerchain,
        allocation_registry=TEST_ALLOCATION_REGISTRY)

    _txhash = escrow_deployer.deploy()

    escrow_deployer.initial_deposit(value=allocation_value,
                                    duration=TEST_DURATION)
    assert escrow_deployer.contract.functions.getLockedTokens().call(
    ) == allocation_value
    escrow_deployer.assign_beneficiary(beneficiary_address=beneficiary_address)
    escrow_deployer.enroll_principal_contract()
    assert escrow_deployer.contract.functions.getLockedTokens().call(
    ) == allocation_value
    _agent = escrow_deployer.make_agent()

    _direct_agent = UserEscrowAgent(
        blockchain=testerchain,
        allocation_registry=TEST_ALLOCATION_REGISTRY,
        beneficiary=beneficiary_address)

    assert _direct_agent == _agent
    assert _direct_agent.contract.abi == _agent.contract.abi
    assert _direct_agent.contract.address == _agent.contract.address
    assert _agent.principal_contract.address == escrow_deployer.contract.address
    assert _agent.principal_contract.abi == escrow_deployer.contract.abi
    assert _direct_agent.contract.abi == escrow_deployer.contract.abi
    assert _direct_agent.contract.address == escrow_deployer.contract.address

    yield _agent
    TEST_ALLOCATION_REGISTRY.clear()
Esempio n. 11
0
def test_user_escrow_deployer(session_testerchain, session_agency, user_escrow_proxy_deployer, deployment_progress):
    testerchain = session_testerchain
    deployer_account = testerchain.etherbase_account
    secret_hash = keccak_digest(USER_ESCROW_PROXY_DEPLOYMENT_SECRET.encode())

    user_escrow_proxy_receipts = user_escrow_proxy_deployer.deploy(secret_hash=secret_hash,
                                                                   progress=deployment_progress)

    assert len(user_escrow_proxy_receipts) == 2
    # deployment steps must match expected number of steps
    assert deployment_progress.num_steps == user_escrow_proxy_deployer.number_of_deployment_transactions

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

    deployer = UserEscrowDeployer(deployer_address=deployer_account,
                                  blockchain=testerchain)

    receipt = deployer.deploy()
    assert receipt['status'] == 1