Пример #1
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),
     )
Пример #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 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),
     )
Пример #3
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)
Пример #4
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)