Skip to content

Commit

Permalink
extend asset request builder, add query assets test
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Jun 28, 2020
1 parent e995c24 commit 792ee3f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/src/requests/assets_request_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import '../responses/response.dart';
import '../responses/asset_response.dart';
import 'request_builder.dart';

/// Lists all assets. It will give you all the assets in the system along with various statistics about each.
/// See: https://developers.stellar.org/api/resources/assets/object/
class AssetsRequestBuilder extends RequestBuilder {
AssetsRequestBuilder(http.Client httpClient, Uri serverURI)
: super(httpClient, serverURI, ["assets"]);
Expand Down Expand Up @@ -39,4 +41,22 @@ class AssetsRequestBuilder extends RequestBuilder {
return AssetsRequestBuilder.requestExecute(
this.httpClient, this.buildUri());
}

@override
AssetsRequestBuilder cursor(String token) {
super.cursor(token);
return this;
}

@override
AssetsRequestBuilder limit(int number) {
super.limit(number);
return this;
}

@override
AssetsRequestBuilder order(RequestBuilderOrder direction) {
super.order(direction);
return this;
}
}
27 changes: 27 additions & 0 deletions test/query_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,31 @@ void main() {
.execute();
assert(accountsForAsset.records.length == 2);
});

test('test query assets', () async {
Page<AssetResponse> assetsPage = await sdk.assets
.assetCode("USD")
.limit(5)
.order(RequestBuilderOrder.DESC)
.execute();
List<AssetResponse> assets = assetsPage.records;
assert(assets.length > 0 && assets.length < 6);
for (AssetResponse asset in assets) {
print("asset issuer: " + asset.assetIssuer);
}
String assetIssuer = assets.last.assetIssuer;
assetsPage = await sdk.assets
.assetIssuer(assetIssuer)
.limit(5)
.order(RequestBuilderOrder.DESC)
.execute();
assets = assetsPage.records;
assert(assets.length > 0 && assets.length < 6);
for (AssetResponse asset in assets) {
print("asset code: " +
asset.assetCode +
" amount:${asset.amount} " +
"num accounts:${asset.numAccounts}");
}
});
}

0 comments on commit 792ee3f

Please sign in to comment.