Skip to content

[BUG] fetcher_sync_sucess fails for TheGraphFetcher #49

@EvolveArt

Description

@EvolveArt

What happened

Once #48 is done, we can fix this test.

I couldn't find a way to correctly mock post requests depending on the body which is only a problem for TheGraphFetcher as it works with POST requests and not GET requests as other fetchers do.

Note that weirdly enough, it works in the async case.

Stack trace

fetcher_config = {'expected_result': [SpotEntry(pair_id="BTC/USD", price=3459885191309, timestamp=12345, source="THEGRAPH", publisher="...file': PosixPath('/Users/matthall/Documents/pragma-sdk/pragma/tests/mock/responses/thegraph.json'), 'name': 'TheGraph'}
mock_data = {'BTC': {'data': {'pool': {'feeTier': '3000', 'liquidity': '12133869505104', 'sqrtPrice': '147370456125399510359475624...500', 'liquidity': '20753232973335935007', 'sqrtPrice': '1867199352400732300487913333649122', 'tick': '201362', ...}}}}

    @mock.patch("time.time", mock.MagicMock(return_value=12345))
    def test_fetcher_sync_success(fetcher_config, mock_data):
        with requests_mock.Mocker() as mocker:
            fetcher = fetcher_config["fetcher_class"](SAMPLE_ASSETS, PUBLISHER_NAME)
    
            # Mocking the expected call for assets
            for asset in SAMPLE_ASSETS:
                quote_asset = asset["pair"][0]
                base_asset = asset["pair"][1]
                url = fetcher.format_url(quote_asset, base_asset)
    
                # TODO (#000): Fix this test
                if fetcher_config["name"] == "TheGraph":
                    query = fetcher.query_body(quote_asset)
                    print(query)
                    mocker.post(
                        url,
                        json=mock_data[quote_asset],
                        additional_matcher=lambda request: request.text
                        == '{"query": "' + query + '"}}',
                    )
                else:
                    mocker.get(url, json=mock_data[quote_asset])
    
>           result = fetcher.fetch_sync()
...
requests_mock.exceptions.NoMockAddress: No mock address: POST https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3

Steps to reproduce

  1. poe test_ci_fetchers

SDK Version

1.0.4

Python version

3.9.13

What operating system are you using?

Mac

Is there an existing issue for this?

  • I have searched the existing issues and verified no issue exits for this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions