Skip to content

Commit

Permalink
fix ledger response parsing, add query effects test
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Jun 28, 2020
1 parent 792ee3f commit 00e6c77
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/src/responses/ledger_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class LedgerResponse extends Response {
json['total_coins'] as String,
json['fee_pool'] as String,
convertInt(json['base_fee']),
json['base_fee_in_stroops'] as String,
json['base_fee_in_stroops'].toString(),
json['base_reserve'] as String,
json['base_reserve_in_stroops'] as String,
json['base_reserve_in_stroops'].toString(),
convertInt(json['max_tx_set_size']),
convertInt(json['protocol_version']),
json['header_xdr'] as String,
Expand Down
61 changes: 61 additions & 0 deletions test/query_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,65 @@ void main() {
"num accounts:${asset.numAccounts}");
}
});

test('test query effects', () 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);

String assetIssuer = assets.last.assetIssuer;

Page<EffectResponse> effectsPage = await sdk.effects
.forAccount(assetIssuer)
.limit(3)
.order(RequestBuilderOrder.ASC)
.execute();
List<EffectResponse> effects = effectsPage.records;
assert(effects.length > 0 && effects.length < 4);
assert(effects.first is AccountCreatedEffectResponse);

Page<LedgerResponse> ledgersPage =
await sdk.ledgers.limit(1).order(RequestBuilderOrder.DESC).execute();
assert(ledgersPage.records.length == 1);
LedgerResponse ledger = ledgersPage.records.first;
effectsPage = await sdk.effects
.forLedger(ledger.sequence)
.limit(3)
.order(RequestBuilderOrder.ASC)
.execute();
effects = effectsPage.records;
assert(effects.length > 0);

Page<TransactionResponse> transactionsPage = await sdk.transactions
.forLedger(ledger.sequence)
.limit(1)
.order(RequestBuilderOrder.DESC)
.execute();
assert(transactionsPage.records.length == 1);
TransactionResponse transaction = transactionsPage.records.first;
effectsPage = await sdk.effects
.forTransaction(transaction.hash)
.limit(3)
.order(RequestBuilderOrder.ASC)
.execute();
assert(effects.length > 0);

Page<OperationResponse> operationsPage = await sdk.operations
.forTransaction(transaction.hash)
.limit(1)
.order(RequestBuilderOrder.DESC)
.execute();
assert(operationsPage.records.length == 1);
OperationResponse operation = operationsPage.records.first;
effectsPage = await sdk.effects
.forOperation(operation.id)
.limit(3)
.order(RequestBuilderOrder.ASC)
.execute();
assert(effects.length > 0);
});
}

0 comments on commit 00e6c77

Please sign in to comment.