def test_stream(self):
     client = RequestsClient()
     resp = []
     for msg in client.stream("https://horizon.stellar.org/ledgers",
                              {"cursor": "now"}):
         assert isinstance(msg, dict)
         resp.append(msg)
         if len(resp) == 2:
             break
 def test_get(self):
     client = RequestsClient()
     url = "https://httpbin.org/get"
     params = {"hello": "world", "stellar": "sdk"}
     resp = client.get(url, params=params)
     assert resp.status_code == 200
     json = resp.json()
     assert json["args"] == params
     assert json["headers"]["User-Agent"] == USER_AGENT
Beispiel #3
0
 def test_submit_transaction_with_xdr(self):
     xdr = "AAAAAHI7fpgo+b7tgpiFyYWimjV7L7IOYLwmQS7k7F8SronXAAAAZAE+QT4AAAAJAAAAAQAAAAAAAAAAAAAAAF1MG8cAAAAAAAAAAQAAAAAAAAAAAAAAAOvi1O/HEn+QgZJw+EMZBtwvTVNmpgvE9p8IRfwp0GY4AAAAAAExLQAAAAAAAAAAARKuidcAAABAJVc1ASGp35hUquGNbzzSqWPoTG0zgc89zc4p+19QkgbPqsdyEfHs7+ng9VJA49YneEXRa6Fv7pfKpEigb3VTCg=="
     horizon_url = "https://horizon.stellar.org"
     client = RequestsClient()
     with Server(horizon_url, client) as server:
         resp = server.submit_transaction(xdr, True)
         assert resp["envelope_xdr"] == xdr
 def test_post(self):
     client = RequestsClient()
     url = "https://httpbin.org/post"
     data = {
         "tx":
         "AAAAABa3N0+hJk17vP/AnYK5xV4o/PhOnEfgi36HlYo4g+3nAAAAZQFDfjoAAaTSAAAAAA"
         "AAAAEAAAAJX3VwZGF0ZWRfAAAAAAAAAQAAAAEAAAAAFrc3T6EmTXu8/8CdgrnFXij8+E6cR+"
         "CLfoeVijiD7ecAAAADAAAAAAAAAAFFVFgAAAAAAIhWSba8wLvB8YFRdzLJPkoyQSFmvRMQeaD"
         "Kym9JD6yTAAAAAAfjgC8NOvYPAA7nFwAAAAAGU5P1AAAAAAAAAAE4g+3nAAAAQOlPDNg4a76N/4"
         "VQh5oKc+RaUZVlK3Pr1HJphQn/yMthQh9gVGUbg/MHKl1RnKPuvmpzyqpBgb1zBVgyAYfIaQI="
     }
     resp = client.post(url, data=data)
     assert resp.status_code == 200
     json = resp.json()
     assert json["headers"][
         "Content-Type"] == "application/x-www-form-urlencoded"
     assert json["form"] == data
Beispiel #5
0
 def test_get_data_no_link(self):
     url = "https://httpbin.org/get"
     client = RequestsClient()
     call_builder = (BaseCallBuilder(
         url, client).limit(10).cursor(10086).order(desc=True))
     call_builder.call()
     assert call_builder.next_href is None
     assert call_builder.prev_href is None
Beispiel #6
0
 def test_stream_data_sync(self):
     url = "https://horizon.stellar.org/ledgers"
     client = RequestsClient()
     resp = BaseCallBuilder(url, client).cursor("now").stream()
     messages = []
     for msg in resp:
         assert isinstance(msg, dict)
         messages.append(msg)
         if len(messages) == 2:
             break
Beispiel #7
0
    def test_get_data_not_pageable_raise(self):
        url = "https://httpbin.org/get"
        client = RequestsClient()
        call_builder = (BaseCallBuilder(
            url, client).limit(10).cursor(10086).order(desc=True))
        call_builder.call()
        with pytest.raises(NotPageableError,
                           match="The next page does not exist."):
            call_builder.next()

        with pytest.raises(NotPageableError,
                           match="The prev page does not exist."):
            call_builder.prev()
Beispiel #8
0
 def test_get_data_page(self):
     url = "https://horizon.stellar.org/transactions"
     client = RequestsClient()
     call_builder = (BaseCallBuilder(
         url, client).cursor(81058917781504).limit(10).order(desc=True))
     first_resp = call_builder.call()
     assert first_resp["_links"] == {
         "self": {
             "href":
             "https://horizon.stellar.org/transactions?cursor=81058917781504&limit=10&order=desc"
         },
         "next": {
             "href":
             "https://horizon.stellar.org/transactions?cursor=12884905984&limit=10&order=desc"
         },
         "prev": {
             "href":
             "https://horizon.stellar.org/transactions?cursor=80607946215424&limit=10&order=asc"
         },
     }
     next_resp = call_builder.next()
     assert next_resp["_links"] == {
         "self": {
             "href":
             "https://horizon.stellar.org/transactions?cursor=12884905984&limit=10&order=desc"
         },
         "next": {
             "href":
             "https://horizon.stellar.org/transactions?cursor=12884905984&limit=10&order=desc"
         },
         "prev": {
             "href":
             "https://horizon.stellar.org/transactions?cursor=12884905984&limit=10&order=asc"
         },
     }
     prev_page = call_builder.prev()
     assert prev_page["_links"] == {
         "self": {
             "href":
             "https://horizon.stellar.org/transactions?cursor=12884905984&limit=10&order=asc"
         },
         "next": {
             "href":
             "https://horizon.stellar.org/transactions?cursor=81827716927488&limit=10&order=asc"
         },
         "prev": {
             "href":
             "https://horizon.stellar.org/transactions?cursor=33676838572032&limit=10&order=desc"
         },
     }
Beispiel #9
0
    def test_status_400_raise_sync(self):
        url = "https://horizon.stellar.org/accounts/BADACCOUNTID"
        client = RequestsClient()
        with pytest.raises(BadRequestError) as err:
            BaseCallBuilder(url, client).call()

        exception = err.value
        assert exception.status == 400
        assert exception.type == "https://stellar.org/horizon-errors/bad_request"
        assert exception.title == "Bad Request"
        assert exception.detail == "The request you sent was invalid in some way."
        assert exception.extras == {
            "invalid_field": "account_id",
            "reason": "invalid address",
        }
Beispiel #10
0
 def _get_client_signing_key(client_domain):
     client_toml_contents = fetch_stellar_toml(
         client_domain,
         client=RequestsClient(request_timeout=settings.
                               SEP10_CLIENT_ATTRIBUTION_REQUEST_TIMEOUT),
     )
     client_signing_key = client_toml_contents.get("SIGNING_KEY")
     if not client_signing_key:
         raise ValueError(
             gettext("SIGNING_KEY not present on 'client_domain' TOML"))
     try:
         Keypair.from_public_key(client_signing_key)
     except Ed25519PublicKeyInvalidError:
         raise ValueError(
             gettext("invalid SIGNING_KEY value on 'client_domain' TOML"))
     return client_signing_key
Beispiel #11
0
    def test_status_404_raise_sync(self):
        url = "https://horizon.stellar.org/not_found"
        client = RequestsClient()
        with pytest.raises(NotFoundError) as err:
            BaseCallBuilder(url, client).call()

        exception = err.value
        assert exception.status == 404
        assert exception.type == "https://stellar.org/horizon-errors/not_found"
        assert exception.title == "Resource Missing"
        assert (
            exception.detail ==
            "The resource at the url requested was not found.  This "
            "usually occurs for one of two reasons:  The url requested is not valid, "
            "or no data in our database could be found with the parameters provided."
        )
        assert exception.extras is None
Beispiel #12
0
 def test_get_data_sync(self):
     url = "https://httpbin.org/get"
     client = RequestsClient()
     resp = (BaseCallBuilder(
         url, client).limit(10).cursor(10086).order(desc=True).call())
     assert resp["args"] == {
         "cursor": "10086",
         "limit": "10",
         "order": "desc"
     }
     assert resp["headers"][
         "User-Agent"] == "py-stellar-sdk/{}/RequestsClient".format(
             __version__)
     assert resp["headers"]["X-Client-Name"] == "py-stellar-sdk"
     assert resp["headers"]["X-Client-Version"] == __version__
     assert resp[
         "url"] == "https://httpbin.org/get?limit=10&cursor=10086&order=desc"
Beispiel #13
0
 def test_get_data_sync(self):
     url = "https://httpbin.org/get"
     client = RequestsClient()
     resp = (BaseCallBuilder(
         url, client).limit(10).cursor(10086).order(desc=True).call())
     assert resp["args"] == {
         "cursor": "10086",
         "limit": "10",
         "order": "desc"
     }
     assert resp["headers"] == {
         "Accept": "*/*",
         "Accept-Encoding": "gzip, deflate",
         "Host": "httpbin.org",
         "User-Agent":
         "py-stellar-sdk/{}/RequestsClient".format(__version__),
         "X-Client-Name": "py-stellar-sdk",
         "X-Client-Version": __version__,
     }
     assert resp[
         "url"] == "https://httpbin.org/get?limit=10&cursor=10086&order=desc"
Beispiel #14
0
 def test_horizon_url_params(self):
     url = "https://httpbin.org/get?version=1.2&auth=myPassw0wd"
     client = RequestsClient()
     resp = (BaseCallBuilder(
         url, client).limit(10).cursor(10086).order(desc=True).call())
     assert resp["args"] == {
         "auth": "myPassw0wd",
         "cursor": "10086",
         "limit": "10",
         "order": "desc",
         "version": "1.2",
     }
     assert resp["headers"][
         "User-Agent"] == "py-stellar-sdk/{}/RequestsClient".format(
             __version__)
     assert resp["headers"]["X-Client-Name"] == "py-stellar-sdk"
     assert resp["headers"]["X-Client-Version"] == __version__
     assert (
         resp["url"] ==
         "https://httpbin.org/get?version=1.2&auth=myPassw0wd&limit=10&cursor=10086&order=desc"
     )
Beispiel #15
0
 def test_endpoint(self):
     horizon_url = "https://horizon.stellar.org"
     client = RequestsClient()
     with Server(horizon_url, client) as server:
         assert server.accounts() == AccountsCallBuilder(
             horizon_url, client)
         assert server.assets() == AssetsCallBuilder(horizon_url, client)
         assert server.effects() == EffectsCallBuilder(horizon_url, client)
         assert server.fee_stats() == FeeStatsCallBuilder(
             horizon_url, client)
         assert server.ledgers() == LedgersCallBuilder(horizon_url, client)
         assert server.offers(
             "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D"
         ) == OffersCallBuilder(
             horizon_url,
             client,
             "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D",
         )
         assert server.operations() == OperationsCallBuilder(
             horizon_url, client)
         buying = Asset.native()
         selling = Asset(
             "MOE",
             "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D")
         assert server.orderbook(buying, selling) == OrderbookCallBuilder(
             horizon_url, client, buying, selling)
         source_account = "GABUVMDURJFF477AEDAXOG5TL7JBHGDAKJQLH5K6FB5QONMLEV52C6IO"
         destination_account = (
             "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D")
         destination_asset = Asset.native()
         destination_amount = "100.0"
         assert server.paths(
             source_account,
             destination_account,
             destination_asset,
             destination_amount,
         ) == PathsCallBuilder(
             horizon_url,
             client,
             source_account,
             destination_account,
             destination_asset,
             destination_amount,
         )
         assert server.payments() == PaymentsCallBuilder(
             horizon_url, client)
         assert server.root() == RootCallBuilder(horizon_url, client)
         base = Asset.native()
         counter = Asset(
             "MOE",
             "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D")
         resolution = 3600000
         start_time = 1565272000000
         end_time = 1565278000000
         offset = 3600000
         assert server.trade_aggregations(
             base, counter, resolution, start_time, end_time,
             offset) == TradeAggregationsCallBuilder(
                 horizon_url,
                 client,
                 base,
                 counter,
                 resolution,
                 start_time,
                 end_time,
                 offset,
             )
         assert server.trades() == TradesCallBuilder(horizon_url, client)
         assert server.transactions() == TransactionsCallBuilder(
             horizon_url, client)
Beispiel #16
0
    def test_endpoint(self):
        horizon_url = "https://horizon.stellar.org"
        client = RequestsClient()
        with Server(horizon_url, client) as server:
            assert server.accounts() == AccountsCallBuilder(
                horizon_url, client)
            assert server.assets() == AssetsCallBuilder(horizon_url, client)
            assert server.claimable_balances() == ClaimableBalancesCallBuilder(
                horizon_url, client)
            assert server.data(
                "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D",
                "hello") == DataCallBuilder(
                    horizon_url,
                    client,
                    "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D",
                    "hello",
                )
            assert server.effects() == EffectsCallBuilder(horizon_url, client)
            assert server.fee_stats() == FeeStatsCallBuilder(
                horizon_url, client)
            assert server.ledgers() == LedgersCallBuilder(horizon_url, client)
            assert server.offers() == OffersCallBuilder(horizon_url, client)
            assert server.operations() == OperationsCallBuilder(
                horizon_url, client)
            buying = Asset.native()
            selling = Asset(
                "MOE",
                "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D")
            assert server.orderbook(buying, selling) == OrderbookCallBuilder(
                horizon_url, client, buying, selling)
            source = "GAYSHLG75RPSMXWJ5KX7O7STE6RSZTD6NE4CTWAXFZYYVYIFRUVJIBJH"
            destination_asset = Asset(
                "EUR",
                "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN")
            destination_amount = "20.0"
            assert server.strict_receive_paths(
                source, destination_asset,
                destination_amount) == StrictReceivePathsCallBuilder(
                    horizon_url, client, source, destination_asset,
                    destination_amount)

            source_asset = Asset(
                "EUR",
                "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN")
            source_amount = "10.25"
            destination = "GARSFJNXJIHO6ULUBK3DBYKVSIZE7SC72S5DYBCHU7DKL22UXKVD7MXP"
            assert server.strict_send_paths(
                source_asset, source_amount,
                destination) == StrictSendPathsCallBuilder(
                    horizon_url, client, source_asset, source_amount,
                    destination)
            assert server.payments() == PaymentsCallBuilder(
                horizon_url, client)
            assert server.root() == RootCallBuilder(horizon_url, client)
            base = Asset.native()
            counter = Asset(
                "MOE",
                "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D")
            resolution = 3600000
            start_time = 1565272000000
            end_time = 1565278000000
            offset = 3600000
            assert server.trade_aggregations(
                base, counter, resolution, start_time, end_time,
                offset) == TradeAggregationsCallBuilder(
                    horizon_url,
                    client,
                    base,
                    counter,
                    resolution,
                    start_time,
                    end_time,
                    offset,
                )
            assert server.trades() == TradesCallBuilder(horizon_url, client)
            assert server.transactions() == TransactionsCallBuilder(
                horizon_url, client)
Beispiel #17
0
from stellar_sdk.client.requests_client import RequestsClient

horizon_url = "https://horizon-testnet.stellar.org"
client = RequestsClient()