Пример #1
0
    def __init__(self,
                 is_me: bool,
                 individual_allocation: IndividualAllocationRegistry = None,
                 *args, **kwargs) -> None:

        super().__init__(*args, **kwargs)
        self.log = Logger("staker")

        self.is_me = is_me
        self.__worker_address = None

        # Blockchain
        self.policy_agent = ContractAgency.get_agent(PolicyManagerAgent, registry=self.registry)  # type: PolicyManagerAgent
        self.staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=self.registry)  # type: StakingEscrowAgent
        self.economics = TokenEconomicsFactory.get_economics(registry=self.registry)

        # Staking via contract
        self.individual_allocation = individual_allocation
        if self.individual_allocation:
            self.beneficiary_address = individual_allocation.beneficiary_address
            self.checksum_address = individual_allocation.contract_address
            self.preallocation_escrow_agent = PreallocationEscrowAgent(registry=self.registry,
                                                                       allocation_registry=self.individual_allocation,
                                                                       beneficiary=self.beneficiary_address)
        else:
            self.beneficiary_address = None
            self.preallocation_escrow_agent = None

        # Check stakes
        self.stakes = StakeList(registry=self.registry, checksum_address=self.checksum_address)
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()
Пример #3
0
def preallocation_escrow_agent(beneficiary,
                               agency_local_registry,
                               mock_allocation_registry,
                               test_registry_source_manager,
                               individual_allocation):
    preallocation_escrow_agent = PreallocationEscrowAgent(beneficiary=beneficiary,
                                                          registry=agency_local_registry,
                                                          allocation_registry=individual_allocation)
    return preallocation_escrow_agent
def preallocation_escrow_agent(beneficiary, test_registry,
                               mock_allocation_registry):
    individual_allocation = IndividualAllocationRegistry.from_allocation_file(
        MOCK_INDIVIDUAL_ALLOCATION_FILEPATH)
    preallocation_escrow_agent = PreallocationEscrowAgent(
        beneficiary=beneficiary,
        registry=test_registry,
        allocation_registry=individual_allocation)
    return preallocation_escrow_agent
Пример #5
0
def test_nucypher_deploy_allocation_contracts(click_runner,
                                              testerchain,
                                              registry_filepath,
                                              mock_allocation_infile,
                                              token_economics):

    #
    # Main
    #

    deploy_command = ('allocations',
                      '--registry-infile', registry_filepath,
                      '--allocation-infile', mock_allocation_infile,
                      '--allocation-outfile', MOCK_ALLOCATION_REGISTRY_FILEPATH,
                      '--provider', TEST_PROVIDER_URI,
                      '--poa')

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

    result = click_runner.invoke(deploy,
                                 deploy_command,
                                 input=user_input,
                                 catch_exceptions=False)
    assert result.exit_code == 0
    for allocation_address in testerchain.unassigned_accounts:
        assert allocation_address in result.output

    # ensure that a pre-allocation recipient has the allocated token quantity.
    beneficiary = testerchain.client.accounts[-1]
    allocation_registry = AllocationRegistry(filepath=MOCK_ALLOCATION_REGISTRY_FILEPATH)
    registry = LocalContractRegistry(filepath=registry_filepath)
    preallocation_escrow_agent = PreallocationEscrowAgent(registry=registry,
                                                          beneficiary=beneficiary,
                                                          allocation_registry=allocation_registry)
    assert preallocation_escrow_agent.unvested_tokens == 2 * token_economics.minimum_allowed_locked