Esempio n. 1
0
 def deploy_preallocation_escrow(self, allocation_registry: AllocationRegistry, progress=None) -> PreallocationEscrowDeployer:
     preallocation_escrow_deployer = PreallocationEscrowDeployer(registry=self.registry,
                                                                 deployer_address=self.deployer_address,
                                                                 allocation_registry=allocation_registry)
     preallocation_escrow_deployer.deploy(progress=progress)
     principal_address = preallocation_escrow_deployer.contract.address
     self.preallocation_escrow_deployers[principal_address] = preallocation_escrow_deployer
     return preallocation_escrow_deployer
Esempio n. 2
0
def mock_allocation_registry(testerchain, agency_local_registry, token_economics):
    # Deploy the PreallocationEscrow contract
    allocation_registry = InMemoryAllocationRegistry()
    deployer = PreallocationEscrowDeployer(deployer_address=testerchain.etherbase_account,
                                           registry=agency_local_registry,
                                           allocation_registry=allocation_registry)

    deployer.deploy()
    deployer.assign_beneficiary(checksum_address=testerchain.unassigned_accounts[0])
    deployer.initial_deposit(value=2 * token_economics.minimum_allowed_locked,
                             duration_seconds=ONE_YEAR_IN_SECONDS)
    deployer.enroll_principal_contract()
    return allocation_registry
Esempio n. 3
0
def test_deploy_multiple_preallocations(testerchain, test_registry):

    deployer_account = testerchain.etherbase_account

    router = testerchain.get_contract_by_name(
        registry=test_registry,
        contract_name=StakingInterfaceRouterDeployer.contract_name)
    router_address = router.address
    for index in range(NUMBER_OF_PREALLOCATIONS):
        deployer = PreallocationEscrowDeployer(
            deployer_address=deployer_account, registry=test_registry)

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

        preallocation_escrow_contract = deployer.contract
        router = preallocation_escrow_contract.functions.router().call()
        assert router == router_address

        preallocation_escrow_contracts.append(preallocation_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(preallocation_escrow_contracts) == NUMBER_OF_PREALLOCATIONS
def agent(testerchain, test_registry, allocation_value, agency,
          mock_transacting_power_activation) -> PreallocationEscrowAgent:
    deployer_address, beneficiary_address, *everybody_else = testerchain.client.accounts

    escrow_deployer = PreallocationEscrowDeployer(deployer_address=deployer_address,
                                                  registry=test_registry,
                                                  allocation_registry=TEST_ALLOCATION_REGISTRY)

    mock_transacting_power_activation(account=deployer_address, password=INSECURE_DEVELOPMENT_PASSWORD)
    _receipt = escrow_deployer.deploy()

    escrow_deployer.initial_deposit(value=allocation_value, duration_seconds=TEST_LOCK_DURATION_IN_SECONDS)
    assert escrow_deployer.contract.functions.getLockedTokens().call() == allocation_value
    escrow_deployer.assign_beneficiary(checksum_address=beneficiary_address)
    escrow_deployer.enroll_principal_contract()
    assert escrow_deployer.contract.functions.getLockedTokens().call() == allocation_value
    agent = escrow_deployer.make_agent()

    direct_agent = PreallocationEscrowAgent(registry=test_registry,
                                            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. 5
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 = PreallocationEscrowDeployer(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

        # 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)