Example #1
0
 async def test_load_acount_async(self):
     account_id = "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D"
     horizon_url = "https://testhorizon.paydex.io/"
     client = AiohttpClient()
     async with Server(horizon_url, client) as server:
         account = await server.load_account(account_id)
         assert account.account_id == account_id
         assert isinstance(account.sequence, int)
         assert account.thresholds == Thresholds(1, 2, 3)
 async def test_with(self):
     async with AiohttpClient() as client:
         url = "https://testhorizon.paydex.io//get"
         params = {"hello": "world", "Paydex": "sdk"}
         resp = await client.get(url, params=params)
         assert resp.status_code == 200
         json = resp.json()
         assert json["args"] == params
         assert json["headers"]["User-Agent"] == USER_AGENT
Example #3
0
 async def test_submit_transaction_with_te(self):
     xdr = "AAAAAHI7fpgo+b7tgpiFyYWimjV7L7IOYLwmQS7k7F8SronXAAAAZAE+QT4AAAAJAAAAAQAAAAAAAAAAAAAAAF1MG8cAAAAAAAAAAQAAAAAAAAAAAAAAAOvi1O/HEn+QgZJw+EMZBtwvTVNmpgvE9p8IRfwp0GY4AAAAAAExLQAAAAAAAAAAARKuidcAAABAJVc1ASGp35hUquGNbzzSqWPoTG0zgc89zc4p+19QkgbPqsdyEfHs7+ng9VJA49YneEXRa6Fv7pfKpEigb3VTCg=="
     te = TransactionEnvelope.from_xdr(xdr,
                                       Network.PUBLIC_NETWORK_PASSPHRASE)
     horizon_url = "https://testhorizon.paydex.io/"
     client = AiohttpClient()
     async with Server(horizon_url, client) as server:
         resp = await server.submit_transaction(te)
         assert resp["envelope_xdr"] == xdr
 async def test_stream(self):
     async with AiohttpClient() as client:
         resp = []
         async for msg in client.stream(
                 "https://horizon.Paydex.org/ledgers", {"cursor": "now"}):
             assert isinstance(msg, dict)
             resp.append(msg)
             if len(resp) == 2:
                 break
Example #5
0
 async def test_get_stream_data_async(self):
     url = "https://testhorizon.paydex.io/ledgers"
     client = AiohttpClient()
     resp = BaseCallBuilder(url, client).cursor("now").stream()
     messages = []
     async for msg in resp:
         assert isinstance(msg, dict)
         messages.append(msg)
         if len(messages) == 2:
             break
 async def test_get(self):
     user_agent = "Hello/Paydex/overcat"
     client = AiohttpClient(pool_size=10, user_agent=user_agent)
     url = "https://testhorizon.paydex.io//get"
     params = {"hello": "world", "Paydex": "sdk"}
     resp = await client.get(url, params=params)
     assert resp.status_code == 200
     json = resp.json()
     assert json["args"] == params
     assert json["headers"]["User-Agent"] == user_agent
     await client.close()
Example #7
0
    async def test_status_400_raise_async(self):
        url = "https://testhorizon.paydex.io/accounts/BADACCOUNTID"
        client = AiohttpClient()
        with pytest.raises(BadRequestError) as err:
            await BaseCallBuilder(url, client).call()

        exception = err.value
        assert exception.status == 400
        assert exception.type == "https://paydex.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",
        }
Example #8
0
    async def test_status_404_raise_async(self):
        url = "https://testhorizon.paydex.io/not_found"
        client = AiohttpClient()
        with pytest.raises(NotFoundError) as err:
            await BaseCallBuilder(url, client).call()

        exception = err.value
        assert exception.status == 404
        assert exception.type == "https://paydex.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
 async def test_post(self):
     client = AiohttpClient()
     url = "https://testhorizon.paydex.io//post"
     data = {
         "tx":
         "AAAAABa3N0+hJk17vP/AnYK5xV4o/PhOnEfgi36HlYo4g+3nAAAAZQFDfjoAAaTSAAAAAA"
         "AAAAEAAAAJX3VwZGF0ZWRfAAAAAAAAAQAAAAEAAAAAFrc3T6EmTXu8/8CdgrnFXij8+E6cR+"
         "CLfoeVijiD7ecAAAADAAAAAAAAAAFFVFgAAAAAAIhWSba8wLvB8YFRdzLJPkoyQSFmvRMQeaD"
         "Kym9JD6yTAAAAAAfjgC8NOvYPAA7nFwAAAAAGU5P1AAAAAAAAAAE4g+3nAAAAQOlPDNg4a76N/4"
         "VQh5oKc+RaUZVlK3Pr1HJphQn/yMthQh9gVGUbg/MHKl1RnKPuvmpzyqpBgb1zBVgyAYfIaQI="
     }
     resp = await 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
     await client.close()
Example #10
0
    async def test_get_data_async(self):
        url = "https://testhorizon.paydex.io/get"
        client = AiohttpClient()
        resp = (await
                BaseCallBuilder(url,
                                client).cursor(89777).order(desc=False
                                                            ).limit(25).call())

        assert resp["args"] == {
            "cursor": "89777",
            "limit": "25",
            "order": "asc"
        }
        assert resp["headers"][
            "User-Agent"] == "py-paydex-sdk/{}/AiohttpClient".format(
                __version__)
        assert resp["headers"]["X-Client-Name"] == "py-paydex-sdk"
        assert resp["headers"]["X-Client-Version"] == __version__
        assert resp[
            "url"] == "https://testhorizon.paydex.io/get?cursor=89777&order=asc&limit=25"
Example #11
0
async def main():
    # Configure paydexSdk to talk to the horizon instance hosted by paydex.org
    # When we use the `with` syntax, it automatically releases the resources it occupies.
    async with Server(horizon_url="https://testhorizon.paydex.io//",
                      client=AiohttpClient()) as server:
        # Transactions require a valid sequence number that is specific to this account.
        # We can fetch the current sequence number for the source account from Horizon.
        source_account = await server.load_account(source_public_key)

        base_fee = await server.fetch_base_fee()
        # we are going to submit the transaction to the test network,
        # so network_passphrase is `Network.TESTNET_NETWORK_PASSPHRASE`,
        # if you want to submit to the public network, please use `Network.PUBLIC_NETWORK_PASSPHRASE`.
        transaction = (
            TransactionBuilder(
                source_account=source_account,
                network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
                base_fee=base_fee,
            ).add_text_memo("Hello, paydex!")  # Add a memo
            # Add a payment operation to the transaction
            # Send 350.1234567 PAYDEX to receiver
            # Specify 350.1234567 lumens. Lumens are divisible to seven digits past the decimal.
            .append_payment_op(receiver_public_key, "350.1234567", "PAYDEX").
            set_timeout(
                30)  # Make this transaction valid for the next 30 seconds only
            .build())

        # Sign this transaction with the secret key
        # NOTE: signing is transaction is network specific. Test network transactions
        # won't work in the public network. To switch networks, use the Network object
        # as explained above (look for paydex_base_sdk.network.Network).
        transaction.sign(source_keypair)

        # Let's see the XDR (encoded in base64) of the transaction we just built
        print(transaction.to_xdr())

        # Submit the transaction to the Horizon server.
        # The Horizon server will then submit the transaction into the network for us.
        response = await server.submit_transaction(transaction)
        print(response)
Example #12
0
 async def test_fetch_base_fee_async(self):
     horizon_url = "https://testhorizon.paydex.io/"
     client = AiohttpClient()
     async with Server(horizon_url, client) as server:
         base_fee = await server.fetch_base_fee()
         assert isinstance(base_fee, int)
 async def test_get_success_async(self):
     client = AiohttpClient()
     toml = await fetch_paydex_toml("overcat.me", client)
     assert toml.get(
         "FEDERATION_SERVER") == "https://federation.overcat.workers.dev"