def test_nucypher_rebond_operator(click_runner, mock_testerchain,
                                  operator_address, staking_provider_address,
                                  mock_application_agent):
    mock_application_agent.get_staking_provider_info.return_value = StakingProviderInfo(
        operator=mock_testerchain.unassigned_accounts[-1],
        operator_confirmed=False,
        operator_start_timestamp=1)
    mock_application_agent.get_beneficiary.return_value = NULL_ADDRESS
    mock_application_agent.get_staking_provider_from_operator.return_value = NULL_ADDRESS

    result = exec_bond(click_runner=click_runner,
                       operator_address=operator_address,
                       staking_provider_address=staking_provider_address)
    assert result.exit_code == 0
def test_nucypher_unbond_operator(click_runner, mock_testerchain,
                                  staking_provider_address,
                                  mock_application_agent, operator_address):

    mock_application_agent.get_staking_provider_info.return_value = StakingProviderInfo(
        operator=operator_address,
        operator_confirmed=False,
        operator_start_timestamp=1)

    mock_application_agent.get_staking_provider_from_operator.return_value = staking_provider_address

    result = exec_unbond(click_runner=click_runner,
                         staking_provider_address=staking_provider_address)
    assert result.exit_code == 0
def test_nucypher_bond_unauthorized(click_runner, mock_testerchain,
                                    operator_address, staking_provider_address,
                                    mock_application_agent):

    mock_application_agent.is_authorized.return_value = False
    mock_application_agent.get_staking_provider_info.return_value = StakingProviderInfo(
        operator=NULL_ADDRESS,
        operator_confirmed=False,
        operator_start_timestamp=1)

    result = exec_bond(click_runner=click_runner,
                       operator_address=operator_address,
                       staking_provider_address=staking_provider_address)
    assert result.exit_code == 1
    error_message = f'{staking_provider_address} is not authorized'
    assert error_message in result.output
def test_nucypher_unexpected_beneficiary(click_runner, mock_testerchain,
                                         operator_address,
                                         staking_provider_address,
                                         mock_application_agent):

    mock_application_agent.get_staking_provider_info.return_value = StakingProviderInfo(
        operator=NULL_ADDRESS,
        operator_confirmed=False,
        operator_start_timestamp=1)
    mock_application_agent.get_beneficiary.return_value = mock_testerchain.unassigned_accounts[
        -1]
    mock_application_agent.get_staking_provider_from_operator.return_value = NULL_ADDRESS

    result = exec_bond(click_runner=click_runner,
                       operator_address=operator_address,
                       staking_provider_address=staking_provider_address)

    assert result.exit_code == 1
    assert UNEXPECTED_HUMAN_OPERATOR in result.output
def test_nucypher_rebond_too_soon(click_runner, mock_testerchain,
                                  operator_address, staking_provider_address,
                                  mock_application_agent):

    min_authorized_seconds = 5
    now = mock_testerchain.get_blocktime()
    operator_start_timestamp = now
    termination = operator_start_timestamp + min_authorized_seconds

    mock_application_agent.get_staking_provider_info.return_value = StakingProviderInfo(
        operator=operator_address,
        operator_confirmed=False,
        operator_start_timestamp=operator_start_timestamp)
    mock_application_agent.get_min_operator_seconds.return_value = min_authorized_seconds

    result = exec_bond(click_runner=click_runner,
                       operator_address=operator_address,
                       staking_provider_address=staking_provider_address)
    assert result.exit_code == 1
    error_message = BONDING_TIME.format(date=maya.MayaDT(termination))
    assert error_message in result.output
Example #6
0
 def get_staking_provider_info(
         self, staking_provider: ChecksumAddress) -> StakingProviderInfo:
     # remove reserved fields
     info: list = self.contract.functions.stakingProviderInfo(
         staking_provider).call()
     return StakingProviderInfo(*info[0:3])