Exemplo n.º 1
0
def divisible_sub_stakes(current_period, token_economics) -> List[SubStakeInfo]:
    stakes = [SubStakeInfo(first_period=1,
                           last_period=current_period + 1,
                           locked_value=2 * token_economics.minimum_allowed_locked),
              SubStakeInfo(first_period=current_period - 3,
                           last_period=current_period + 2,
                           locked_value=2 * token_economics.minimum_allowed_locked + 1)]
    return stakes
Exemplo n.º 2
0
def test_stakeholder_configuration(test_emitter, test_registry,
                                   mock_testerchain, mock_staking_agent):

    stakeholder_config_options = StakeHolderConfigOptions(
        provider_uri=MOCK_PROVIDER_URI,
        poa=None,
        light=None,
        registry_filepath=None,
        network=TEMPORARY_DOMAIN,
        signer_uri=None)

    mock_staking_agent.get_all_stakes.return_value = [SubStakeInfo(1, 2, 3)]
    force = False
    selected_index = 0
    selected_account = mock_testerchain.client.accounts[selected_index]
    expected_stakeholder = StakeHolder(registry=test_registry,
                                       domains={TEMPORARY_DOMAIN},
                                       initial_address=selected_account)
    expected_stakeholder.refresh_stakes()

    staker_options = StakerOptions(config_options=stakeholder_config_options,
                                   staking_address=selected_account)
    transacting_staker_options = TransactingStakerOptions(
        staker_options=staker_options,
        hw_wallet=None,
        beneficiary_address=None,
        allocation_filepath=None)
    stakeholder_from_configuration = transacting_staker_options.create_character(
        emitter=test_emitter, config_file=None)
    client_account, staking_address = select_client_account_for_staking(
        emitter=test_emitter,
        stakeholder=stakeholder_from_configuration,
        staking_address=selected_account,
        individual_allocation=None,
        force=force)
    assert client_account == staking_address == selected_account
    assert stakeholder_from_configuration.stakes == expected_stakeholder.stakes
    assert stakeholder_from_configuration.checksum_address == client_account

    staker_options = StakerOptions(config_options=stakeholder_config_options,
                                   staking_address=None)
    transacting_staker_options = TransactingStakerOptions(
        staker_options=staker_options,
        hw_wallet=None,
        beneficiary_address=None,
        allocation_filepath=None)
    stakeholder_from_configuration = transacting_staker_options.create_character(
        emitter=None, config_file=None)
    client_account, staking_address = select_client_account_for_staking(
        emitter=test_emitter,
        stakeholder=stakeholder_from_configuration,
        staking_address=selected_account,
        individual_allocation=None,
        force=force)
    assert client_account == staking_address == selected_account
    assert stakeholder_from_configuration.stakes == expected_stakeholder.stakes
    assert stakeholder_from_configuration.checksum_address == client_account
Exemplo n.º 3
0
def surrogate_stakes(mock_staking_agent, token_economics, surrogate_staker):
    nu = 2 * token_economics.minimum_allowed_locked + 1
    current_period = 10
    duration = token_economics.minimum_locked_periods + 1
    final_period = current_period + duration
    # TODO: Add non divisible, non editable and inactive sub-stakes
    stakes = [
        SubStakeInfo(current_period - 1, final_period - 1, nu),
        SubStakeInfo(current_period + 1, final_period, nu)
    ]

    mock_staking_agent.get_current_period.return_value = current_period

    def get_all_stakes(staker_address):
        return stakes if staker_address == surrogate_staker.checksum_address else []

    mock_staking_agent.get_all_stakes.side_effect = get_all_stakes

    def get_substake_info(staker_address, stake_index):
        return stakes[stake_index] if staker_address == surrogate_staker.checksum_address else []

    mock_staking_agent.get_substake_info.side_effect = get_substake_info

    return stakes
Exemplo n.º 4
0
 def to_stake_info(self) -> SubStakeInfo:
     """Returns a tuple representing the blockchain record of a stake"""
     return SubStakeInfo(self.first_locked_period, self.final_locked_period,
                         self.value.to_nunits())
                        return_value=mock_testerchain)
    selected_account = select_client_account(emitter=test_emitter,
                                             provider_uri=MOCK_PROVIDER_URI)
    assert selected_account == expected_account
    assert mock_stdin.empty()
    captured = capsys.readouterr()
    assert GENERIC_SELECT_ACCOUNT in captured.out and f"Selected {selection}" in captured.out


@pytest.mark.parametrize(
    'selection,show_staking,show_eth,show_tokens,stake_info', (
        (0, True, True, True, []),
        (1, True, True, True, []),
        (5, True, True, True, []),
        (NUMBER_OF_ETH_TEST_ACCOUNTS - 1, True, True, True, []),
        (4, True, True, True, [SubStakeInfo(1, 2, 3)]),
        (7, True, True, True, [SubStakeInfo(1, 2, 3),
                               SubStakeInfo(1, 2, 3)]),
        (0, False, True, True, []),
        (0, False, False, True, []),
        (0, False, False, False, []),
    ))
def test_select_client_account_with_balance_display(
        mock_stdin, test_emitter, mock_testerchain, capsys,
        test_registry_source_manager, mock_staking_agent, mock_token_agent,
        selection, show_staking, show_eth, show_tokens, stake_info):

    # Setup
    mock_staking_agent.get_all_stakes.return_value = stake_info

    # Missing network kwarg with balance display active