예제 #1
0
def test_poloniex_deposits_withdrawal_unknown_asset(function_scope_poloniex):
    """Test that if a poloniex asset movement query returns unknown asset no exception
    is raised and a warning is generated. Same for unsupported assets"""
    poloniex = function_scope_poloniex

    def mock_api_return(url, req):  # pylint: disable=unused-argument
        response = MockResponse(
            200,
            POLONIEX_MOCK_DEPOSIT_WITHDRAWALS_RESPONSE,
        )
        return response

    with patch.object(poloniex.session, 'post', side_effect=mock_api_return):
        # Test that after querying the api only ETH and BTC assets are there
        asset_movements = poloniex.query_online_deposits_withdrawals(
            start_ts=0,
            end_ts=1488994442,
        )
    assert_poloniex_asset_movements(to_check_list=asset_movements,
                                    deserialized=False)

    warnings = poloniex.msg_aggregator.consume_warnings()
    assert len(warnings) == 4
    assert 'Found withdrawal of unknown poloniex asset IDONTEXIST' in warnings[
        0]
    assert 'Found withdrawal of unsupported poloniex asset DIS' in warnings[1]
    assert 'Found deposit of unknown poloniex asset IDONTEXIST' in warnings[2]
    assert 'Found deposit of unsupported poloniex asset EBT' in warnings[3]
예제 #2
0
 def assert_okay(response):
     """Helper function for DRY checking below assertions"""
     if async_query:
         task_id = assert_ok_async_response(response)
         outcome = wait_for_async_task(
             rotkehlchen_api_server_with_exchanges, task_id)
         result = outcome['result']
     else:
         result = assert_proper_response_with_result(response)
     movements = result['entries']
     assert_poloniex_asset_movements(
         to_check_list=[
             x['entry'] for x in movements
             if x['entry']['location'] == 'poloniex'
         ],
         deserialized=True,
         movements_to_check=(1, 2),
     )
     msg = 'poloniex asset movements should have now been ignored for accounting'
     assert all(x['ignored_in_accounting'] is True for x in movements
                if x['entry']['location'] == 'poloniex'), msg  # noqa: E501
     assert_kraken_asset_movements(
         to_check_list=[
             x['entry'] for x in movements
             if x['entry']['location'] == 'kraken'
         ],
         deserialized=True,
         movements_to_check=(0, 1, 2),
     )
예제 #3
0
 def assert_okay(response):
     """Helper function for DRY checking below assertions"""
     if async_query:
         task_id = assert_ok_async_response(response)
         outcome = wait_for_async_task(rotkehlchen_api_server_with_exchanges, task_id)
         result = outcome['result']
     else:
         result = assert_proper_response_with_result(response)
     movements = result['entries']
     assert_poloniex_asset_movements(
         to_check_list=[x for x in movements if x['location'] == 'poloniex'],
         deserialized=True,
         movements_to_check=(1, 2),
     )
     assert_kraken_asset_movements(
         to_check_list=[x for x in movements if x['location'] == 'kraken'],
         deserialized=True,
         movements_to_check=(0, 1, 2),
     )
예제 #4
0
def test_query_asset_movements_over_limit(
    rotkehlchen_api_server_with_exchanges,
    start_with_valid_premium,
):
    """Test that using the asset movements query endpoint works fine"""
    start_ts = 0
    end_ts = 1598453214
    server = rotkehlchen_api_server_with_exchanges
    rotki = server.rest_api.rotkehlchen
    # Make sure online kraken is not queried by setting query ranges
    rotki.data.db.update_used_query_range(
        name='kraken_asset_movements',
        start_ts=start_ts,
        end_ts=end_ts,
    )
    polo_entries_num = 4
    # Set a ton of kraken asset movements in the DB
    kraken_entries_num = FREE_ASSET_MOVEMENTS_LIMIT + 50
    movements = [
        AssetMovement(location=Location.KRAKEN,
                      category=AssetMovementCategory.DEPOSIT,
                      address=None,
                      transaction_id=None,
                      timestamp=x,
                      asset=A_BTC,
                      amount=FVal(x * 100),
                      fee_asset=A_BTC,
                      fee=FVal(x),
                      link='') for x in range(kraken_entries_num)
    ]
    rotki.data.db.add_asset_movements(movements)
    all_movements_num = kraken_entries_num + polo_entries_num
    setup = prepare_rotki_for_history_processing_test(
        server.rest_api.rotkehlchen)

    # Check that querying movements with/without limits works even if we query two times
    for _ in range(2):
        # query asset movements of polo which has less movements than the limit
        with setup.polo_patch:
            response = requests.get(
                api_url_for(
                    server,
                    "assetmovementsresource",
                ),
                json={'location': 'poloniex'},
            )
        result = assert_proper_response_with_result(response)
        assert result['entries_found'] == all_movements_num
        assert result[
            'entries_limit'] == -1 if start_with_valid_premium else FREE_ASSET_MOVEMENTS_LIMIT  # noqa: E501
        assert_poloniex_asset_movements(
            [x['entry'] for x in result['entries']], deserialized=True)

        # now query kraken which has a ton of DB entries
        response = requests.get(
            api_url_for(server, "assetmovementsresource"),
            json={'location': 'kraken'},
        )
        result = assert_proper_response_with_result(response)

        if start_with_valid_premium:
            assert len(result['entries']) == kraken_entries_num
            assert result['entries_limit'] == -1
            assert result['entries_found'] == all_movements_num
        else:
            assert len(result['entries']
                       ) == FREE_ASSET_MOVEMENTS_LIMIT - polo_entries_num
            assert result['entries_limit'] == FREE_ASSET_MOVEMENTS_LIMIT
            assert result['entries_found'] == all_movements_num
예제 #5
0
def test_query_asset_movements(rotkehlchen_api_server_with_exchanges):
    """Test that using the asset movements query endpoint works fine"""
    async_query = random.choice([False, True])
    server = rotkehlchen_api_server_with_exchanges
    setup = prepare_rotki_for_history_processing_test(
        server.rest_api.rotkehlchen)
    # setup = mock_history_processing_and_exchanges(server.rest_api.rotkehlchen)
    # query asset movements of one specific exchange
    with setup.polo_patch:
        response = requests.get(
            api_url_for(
                server,
                "assetmovementsresource",
            ),
            json={
                'location': 'poloniex',
                'async_query': async_query
            },
        )
        if async_query:
            task_id = assert_ok_async_response(response)
            outcome = wait_for_async_task(
                rotkehlchen_api_server_with_exchanges, task_id)
            result = outcome['result']
        else:
            result = assert_proper_response_with_result(response)
    assert result['entries_found'] == 4
    assert result['entries_limit'] == FREE_ASSET_MOVEMENTS_LIMIT
    poloniex_ids = [x['entry']['identifier'] for x in result['entries']]
    assert_poloniex_asset_movements([x['entry'] for x in result['entries']],
                                    deserialized=True)
    assert all(
        x['ignored_in_accounting'] is False
        for x in result['entries']), 'ignored should be false'  # noqa: E501

    # now let's ignore all poloniex action ids
    response = requests.put(
        api_url_for(
            rotkehlchen_api_server_with_exchanges,
            "ignoredactionsresource",
        ),
        json={
            'action_type': 'asset movement',
            'action_ids': poloniex_ids
        },
    )
    result = assert_proper_response_with_result(response)
    assert set(result['asset movement']) == set(poloniex_ids)

    # query asset movements of all exchanges
    with setup.polo_patch:
        response = requests.get(
            api_url_for(server, "assetmovementsresource"),
            json={'async_query': async_query},
        )
        if async_query:
            task_id = assert_ok_async_response(response)
            outcome = wait_for_async_task(
                rotkehlchen_api_server_with_exchanges, task_id)
            result = outcome['result']
        else:
            result = assert_proper_response_with_result(response)

    movements = result['entries']
    assert_poloniex_asset_movements([
        x['entry'] for x in movements if x['entry']['location'] == 'poloniex'
    ], True)  # noqa: E501
    assert_kraken_asset_movements(
        [x['entry'] for x in movements if x['entry']['location'] == 'kraken'],
        True)  # noqa: E501

    def assert_okay(response):
        """Helper function for DRY checking below assertions"""
        if async_query:
            task_id = assert_ok_async_response(response)
            outcome = wait_for_async_task(
                rotkehlchen_api_server_with_exchanges, task_id)
            result = outcome['result']
        else:
            result = assert_proper_response_with_result(response)
        movements = result['entries']
        assert_poloniex_asset_movements(
            to_check_list=[
                x['entry'] for x in movements
                if x['entry']['location'] == 'poloniex'
            ],
            deserialized=True,
            movements_to_check=(1, 2),
        )
        msg = 'poloniex asset movements should have now been ignored for accounting'
        assert all(x['ignored_in_accounting'] is True for x in movements
                   if x['entry']['location'] == 'poloniex'), msg  # noqa: E501
        assert_kraken_asset_movements(
            to_check_list=[
                x['entry'] for x in movements
                if x['entry']['location'] == 'kraken'
            ],
            deserialized=True,
            movements_to_check=(0, 1, 2),
        )

    # and now query them in a specific time range excluding some asset movements
    data = {
        'from_timestamp': 1439994442,
        'to_timestamp': 1458994442,
        'async_query': async_query
    }
    with setup.polo_patch:
        response = requests.get(api_url_for(server, "assetmovementsresource"),
                                json=data)
        assert_okay(response)
    # do the same but with query args. This serves as test of from/to timestamp with query args
    with setup.polo_patch:
        response = requests.get(
            api_url_for(server, "assetmovementsresource") + '?' +
            urlencode(data))
        assert_okay(response)
예제 #6
0
def test_query_asset_movements(rotkehlchen_api_server_with_exchanges,
                               async_query):
    """Test that using the asset movements query endpoint works fine"""
    server = rotkehlchen_api_server_with_exchanges
    setup = prepare_rotki_for_history_processing_test(
        server.rest_api.rotkehlchen)
    # setup = mock_history_processing_and_exchanges(server.rest_api.rotkehlchen)
    # query asset movements of one specific exchange
    with setup.polo_patch:
        response = requests.get(
            api_url_for(
                server,
                "assetmovementsresource",
            ),
            json={
                'location': 'poloniex',
                'async_query': async_query
            },
        )
        if async_query:
            task_id = assert_ok_async_response(response)
            outcome = wait_for_async_task(
                rotkehlchen_api_server_with_exchanges, task_id)
            result = outcome['result']
        else:
            result = assert_proper_response_with_result(response)
    assert result['entries_found'] == 4
    assert result['entries_limit'] == FREE_ASSET_MOVEMENTS_LIMIT
    assert_poloniex_asset_movements(result['entries'], deserialized=True)

    # query asset movements of all exchanges
    with setup.polo_patch:
        response = requests.get(
            api_url_for(server, "assetmovementsresource"),
            json={'async_query': async_query},
        )
        if async_query:
            task_id = assert_ok_async_response(response)
            outcome = wait_for_async_task(
                rotkehlchen_api_server_with_exchanges, task_id)
            result = outcome['result']
        else:
            result = assert_proper_response_with_result(response)

    movements = result['entries']
    assert_poloniex_asset_movements(
        [x for x in movements if x['location'] == 'poloniex'], True)
    assert_kraken_asset_movements(
        [x for x in movements if x['location'] == 'kraken'], True)

    def assert_okay(response):
        """Helper function for DRY checking below assertions"""
        if async_query:
            task_id = assert_ok_async_response(response)
            outcome = wait_for_async_task(
                rotkehlchen_api_server_with_exchanges, task_id)
            result = outcome['result']
        else:
            result = assert_proper_response_with_result(response)
        movements = result['entries']
        assert_poloniex_asset_movements(
            to_check_list=[
                x for x in movements if x['location'] == 'poloniex'
            ],
            deserialized=True,
            movements_to_check=(1, 2),
        )
        assert_kraken_asset_movements(
            to_check_list=[x for x in movements if x['location'] == 'kraken'],
            deserialized=True,
            movements_to_check=(0, 1, 2),
        )

    # and now query them in a specific time range excluding some asset movements
    data = {
        'from_timestamp': 1439994442,
        'to_timestamp': 1458994442,
        'async_query': async_query
    }
    with setup.polo_patch:
        response = requests.get(api_url_for(server, "assetmovementsresource"),
                                json=data)
        assert_okay(response)
    # do the same but with query args. This serves as test of from/to timestamp with query args
    with setup.polo_patch:
        response = requests.get(
            api_url_for(server, "assetmovementsresource") + '?' +
            urlencode(data))
        assert_okay(response)