async def test_resolve_by_account_id_federation_not_found_async(self): with pytest.raises( FederationServerNotFoundError, match="Unable to find federation server at sdk-test.overcat.me.", ): await resolve_account_id( self.ACCOUNT_ID, domain="sdk-test.overcat.me", client=AiohttpClient() )
async def test_resolve_by_kuknos_address_federation_not_found_async(self): with pytest.raises( FederationServerNotFoundError, match="Unable to find federation server at sdk-test.overcat.me.", ): await resolve_kuknos_address( "hello*sdk-test.overcat.me", client=AiohttpClient() )
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://horizon.kuknos.org" client = AiohttpClient() async with Server(horizon_url, client) as server: resp = await server.submit_transaction(te, True) assert resp["envelope_xdr"] == xdr
async def test_load_acount_async(self): account_id = "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D" horizon_url = "https://horizon.kuknos.org" 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://httpbin.org/get" params = {"hello": "world", "kuknos": "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
async def test_stream(self): async with AiohttpClient() as client: resp = [] async for msg in client.stream( "https://horizon.kuknos.org/ledgers", {"cursor": "now"}): assert isinstance(msg, dict) resp.append(msg) if len(resp) == 2: break
async def test_get_stream_data_async(self): url = "https://horizon.kuknos.org/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_resolve_by_kuknos_address_with_federation_url_async(self): record = await resolve_kuknos_address( "hello*example.com", federation_url=self.FEDERATION_SERVER, client=AiohttpClient(), ) assert ( record.account_id == "GAWCQ74PIJO2NH6F3KZ4AMX27UAKBXWC7KG3FLYJOFIMRQF3REXAMPLE" )
async def test_get(self): user_agent = "Hello/Kuknos/overcat" client = AiohttpClient(pool_size=10, user_agent=user_agent) url = "https://httpbin.org/get" params = {"hello": "world", "kuknos": "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()
async def test_status_400_raise_async(self): url = "https://horizon.kuknos.org/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://kuknos.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": "Account ID must start with `G` and contain 56 alphanum characters", }
async def test_status_404_raise_async(self): url = "https://horizon.kuknos.org/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://kuknos.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://httpbin.org/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()
async def test_get_data_async(self): url = "https://httpbin.org/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-kuknos-sdk/{}/AiohttpClient".format(__version__) assert resp["headers"]["X-Client-Name"] == "py-kuknos-sdk" assert resp["headers"]["X-Client-Version"] == __version__ assert resp["url"] == "https://httpbin.org/get?cursor=89777&order=asc&limit=25"
async def test_resolve_by_account_id_with_domain_async(self): record = await resolve_account_id( self.ACCOUNT_ID, domain=self.DOMAIN, client=AiohttpClient() ) assert record == self.FEDERATION_RECORD
async def test_get_success_async(self): client = AiohttpClient() toml = await fetch_kuknos_toml("overcat.me", client) assert toml.get( "FEDERATION_SERVER") == "https://federation.overcat.workers.dev"
async def test_resolve_by_kuknos_address_async(self): record = await resolve_kuknos_address( self.STELLAR_ADDRESS, client=AiohttpClient() ) assert record == self.FEDERATION_RECORD
async def test_fetch_base_fee_async(self): horizon_url = "https://horizon.kuknos.org" client = AiohttpClient() async with Server(horizon_url, client) as server: base_fee = await server.fetch_base_fee() assert isinstance(base_fee, int)