def select_client_account_for_staking( emitter: StdoutEmitter, stakeholder: StakeHolder, staking_address: Optional[str], ) -> Tuple[str, str]: """ Manages client account selection for stake-related operations. It always returns a tuple of addresses: the first is the local client account and the second is the staking address. When this is not a preallocation staker (which is the normal use case), both addresses are the same. Otherwise, when the staker is a contract managed by a beneficiary account, then the local client account is the beneficiary, and the staking address is the address of the staking contract. """ if staking_address: client_account = staking_address else: client_account = select_client_account( prompt=SELECT_STAKING_ACCOUNT_INDEX, emitter=emitter, registry=stakeholder.registry, network=stakeholder.domain, signer=stakeholder.signer) staking_address = client_account stakeholder.assimilate(client_account) return client_account, staking_address
def test_handle_selection_with_no_divisible_stakes( test_emitter, token_economics, mock_staking_agent, test_registry, mock_testerchain, mock_stdin, # used to assert the user hasn't been prompted capsys, non_divisible_stakes): # Setup mock_staking_agent.get_all_stakes.return_value = non_divisible_stakes stakeholder = StakeHolder(registry=test_registry) stakeholder.assimilate(checksum_address=mock_testerchain.etherbase_account, password=INSECURE_DEVELOPMENT_PASSWORD) # FAILURE: Divisible only with no divisible stakes on chain with pytest.raises(click.Abort): select_stake(emitter=test_emitter, divisible=True, stakeholder=stakeholder) # Divisible warning was displayed, but having # no divisible stakes cases an expected failure captured = capsys.readouterr() assert NO_STAKES_FOUND not in captured.out assert ONLY_DISPLAYING_DIVISIBLE_STAKES_NOTE in captured.out assert_stake_table_not_painted(output=captured.out)
def stakeholder_with_no_divisible_stakes(mock_testerchain, token_economics, mock_staking_agent, test_registry, non_divisible_stakes): mock_staking_agent.get_all_stakes.return_value = non_divisible_stakes stakeholder = StakeHolder(registry=test_registry) account = mock_testerchain.etherbase_account stakeholder.assimilate(checksum_address=account, password=INSECURE_DEVELOPMENT_PASSWORD) return stakeholder